From f17cfd7946d5fc84310f87476fe90d378135bd8e Mon Sep 17 00:00:00 2001 From: tracer-ysyx Date: Wed, 10 Jan 2024 14:54:44 +0800 Subject: [PATCH] =?UTF-8?q?>=20configure(npc)=20=20ysyx=5F22040000=20?= =?UTF-8?q?=E6=9D=8E=E5=BF=83=E6=9D=A8=20=20Linux=20calcite=206.1.69=20#1-?= =?UTF-8?q?NixOS=20SMP=20PREEMPT=5FDYNAMIC=20Wed=20Dec=2020=2016:00:29=20U?= =?UTF-8?q?TC=202023=20x86=5F64=20GNU/Linux=20=20=2014:54:44=20=20up=202?= =?UTF-8?q?=20days=2013:55,=20=202=20users,=20=20load=20average:=201.87,?= =?UTF-8?q?=201.83,=201.54?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- npc/CMakeLists.txt | 2 +- npc/core/src/main/scala/Keyboard.scala | 21 ++------------------- npc/core/src/main/scala/Main.scala | 6 ++++-- npc/core/src/test/scala/Keyboard.scala | 2 +- 4 files changed, 8 insertions(+), 23 deletions(-) diff --git a/npc/CMakeLists.txt b/npc/CMakeLists.txt index d3c7372..edc36f2 100644 --- a/npc/CMakeLists.txt +++ b/npc/CMakeLists.txt @@ -17,7 +17,7 @@ find_package(verilator REQUIRED) find_library(NVBOARD_LIBRARY NAMES nvboard) find_path(NVBOARD_INCLUDE_DIR NAMES nvboard.h) -set(TOPMODULE "Keyboard") +set(TOPMODULE "keyboard.SegHandler") set(SCALA_CORE "${CMAKE_CURRENT_SOURCE_DIR}/core") set(CHISEL_MODULE_CLASS "${CMAKE_PROJECT_NAME}.${TOPMODULE}") file(GLOB_RECURSE SCALA_CORE_SOURCES "${SCALA_CORE}/src/main/scala/*.scala") diff --git a/npc/core/src/main/scala/Keyboard.scala b/npc/core/src/main/scala/Keyboard.scala index dd2acbb..53eff3e 100644 --- a/npc/core/src/main/scala/Keyboard.scala +++ b/npc/core/src/main/scala/Keyboard.scala @@ -57,7 +57,7 @@ class KeyboardController extends Module { } } -class SegHandler(seg_count: Int) extends Module { +class SegGenerator(seg_count: Int) extends Module { val io = IO(new Bundle { val keycode = Flipped(Decoupled(UInt(8.W))) val segs = Output(Vec(seg_count, UInt(8.W))) @@ -89,26 +89,9 @@ class SegHandler(seg_count: Int) extends Module { val keycode_digits = VecInit(io.keycode.bits(3,0)) ++ VecInit(io.keycode.bits(7,4)) val keycode_seg = keycode_digits.map(MuxLookup(_, 0.U)(digit_to_seg)) - seg_regs := keycode_seg ++ keycode_seg ++ keycode_seg + seg_regs := keycode_seg ++ keycode_seg ++ keycode_seg ++ keycode_seg io.segs := seg_regs - - // when(io.keycode.valid) { - // val data = io.keycode.bits - // val state_f0_received = RegNext(data === 0xF0.U, false.B) - // io.keycode.ready := true.B - // // Handle keycode based on current state - // // (keyboard press counter) :: (ASCII code) :: (Keycode) - // when(state_f0_received) { - // // Release code - // }.otherwise{ - // counter.inc() - // last_keycode := io.keycode.bits - // } - // }.otherwise { - // io.keycode.ready := false.B - // } - } diff --git a/npc/core/src/main/scala/Main.scala b/npc/core/src/main/scala/Main.scala index 38a7e60..3116d12 100644 --- a/npc/core/src/main/scala/Main.scala +++ b/npc/core/src/main/scala/Main.scala @@ -88,11 +88,13 @@ class Keyboard extends Module { val segs = Output(Vec(3, UInt(8.W))) }) - val seg_handler = Module(new SegHandler(6)) + val seg_handler = Module(new SegHandler) val keyboard_controller = Module(new KeyboardController) seg_handler.io.keycode <> keyboard_controller.io.out keyboard_controller.io.ps2 := io.ps2 io.segs := seg_handler.io.segs -} \ No newline at end of file +} + +class SegHandler extends SegGenerator(8) { } diff --git a/npc/core/src/test/scala/Keyboard.scala b/npc/core/src/test/scala/Keyboard.scala index afa5fa2..12644e4 100644 --- a/npc/core/src/test/scala/Keyboard.scala +++ b/npc/core/src/test/scala/Keyboard.scala @@ -66,7 +66,7 @@ class KeyboardControllerSpec extends AnyFreeSpec with ChiselScalatestTester { class SegSpec extends AnyFreeSpec with ChiselScalatestTester { "try out vec" in { - test(new SegHandler(6)) {c => + test(new SegHandler) {c => c.io.keycode.bits.poke(0xAC) c.clock.step(1) println(s"out: ${c.io.segs(0).peek().litValue}")