xref: /XiangShan/src/main/scala/device/AXI4Keyboard.scala (revision ac67b1cb2bab6d8503f1b0d9cb1ea98ddf2a7c42)
1*ac67b1cbSZihao Yupackage device
2*ac67b1cbSZihao Yu
3*ac67b1cbSZihao Yuimport chisel3._
4*ac67b1cbSZihao Yuimport chisel3.util._
5*ac67b1cbSZihao Yu
6*ac67b1cbSZihao Yuimport bus.axi4._
7*ac67b1cbSZihao Yuimport utils._
8*ac67b1cbSZihao Yu
9*ac67b1cbSZihao Yuclass KeyboardIO extends Bundle {
10*ac67b1cbSZihao Yu  val ps2Clk = Input(Bool())
11*ac67b1cbSZihao Yu  val ps2Data = Input(Bool())
12*ac67b1cbSZihao Yu}
13*ac67b1cbSZihao Yu
14*ac67b1cbSZihao Yu// this Module is not tested
15*ac67b1cbSZihao Yuclass AXI4Keyboard extends AXI4SlaveModule(new AXI4Lite, new KeyboardIO) {
16*ac67b1cbSZihao Yu  val buf = Reg(UInt(10.W))
17*ac67b1cbSZihao Yu  val ps2ClkLatch = RegNext(io.extra.get.ps2Clk)
18*ac67b1cbSZihao Yu  val negedge = RegNext(ps2ClkLatch) && ~ps2ClkLatch
19*ac67b1cbSZihao Yu  when (negedge) { buf := Cat(io.extra.get.ps2Data, buf(9,1)) }
20*ac67b1cbSZihao Yu
21*ac67b1cbSZihao Yu  val cnt = Counter(negedge, 10)
22*ac67b1cbSZihao Yu  val queue = Module(new Queue(UInt(8.W), 8))
23*ac67b1cbSZihao Yu  queue.io.enq.valid := cnt._2 && !buf(0) && io.extra.get.ps2Data && buf(9,1).xorR
24*ac67b1cbSZihao Yu  queue.io.enq.bits := buf(8,1)
25*ac67b1cbSZihao Yu  queue.io.deq.ready := in.r.ready
26*ac67b1cbSZihao Yu
27*ac67b1cbSZihao Yu  in.r.bits.data := Mux(queue.io.deq.valid, queue.io.deq.bits, 0.U)
28*ac67b1cbSZihao Yu}
29