Reputation: 37307
Consider this code:
import chisel3.experimental.ChiselEnum
object MyEnum extends ChiselEnum {
val A, B = Value
}
class UseEnumIO extends Module {
val io = IO(new Bundle {
val in = Input(UInt(1.W))
val out = Output(Bool())
})
io.out := MuxLookup(io.in, false.B, Array(
MyEnum.A -> true.B,
MyEnum.B -> true.B
))
}
I need to use an IO port which is supposed to be a ChiselEnum
object in a MuxLookup
.
This is the error message I got from SBT:
[error] found : scala.collection.mutable.WrappedArray[(MyEnum.Type, chisel3.core.Bool)]
while Scala inferred that [S <: chisel3.UInt,T <: chisel3.Data]
I also tried val in = Input(MyEnum.Type)
which gave me a more serious error.
val defaultVersions = Map(
"chisel3" -> "3.2-SNAPSHOT
)
Upvotes: 3
Views: 698
Reputation: 6064
MuxLookup
requires UInts (or Bools) for the selector. From the API docs:
def apply[S <: UInt, T <: Data](key: S, default: T, mapping: Seq[(S, T)]): T
This is probably an oversight, MuxLookup
predates ChiselEnum
by a lot of time so it wasn't made with it in mind, I have filed an issue to support this use case. You can use Chick's workaround in the meantime.
Upvotes: 2
Reputation: 4051
I'm not quite sure why this doesn't work, but the following work-around might help. Try
io.out := MuxLookup(io.in, false.B, Seq(
MyEnum.A.asUInt -> true.B,
MyEnum.B.asUInt -> true.B
))
it seems to work to me. I'll keep looking for a reason that the more obvious simple syntax does not work.
Upvotes: 2