usb-hid: echo typed characters to the log — a simple keyboard check

There was no way to confirm a keyboard actually registers keys on real
hardware (enumeration binding the driver only proves the device came
up). The keyboard driver now echoes each decoded printable character
(and newline) to its log: type a known phrase and read it back from
usb-hid-keyboard.log, or watch it appear live on screen in a -Ddiagnose
boot (where the kernel console is a log sink). It exercises the whole
path — HID report -> diff -> layout -> character — not just enumeration,
and works identically for a keyboard behind a hub.

A usb-key-echo QEMU case injects a phrase via QMP send-key and asserts
it echoes (stable across repeated runs). Full suite 92/92.
This commit is contained in:
Daniel Samson
2026-07-21 22:27:47 +01:00
parent e52ae242fc
commit 7ee6033fa4
2 changed files with 24 additions and 0 deletions
+9
View File
@@ -148,6 +148,15 @@ pub fn main(init: runtime.process.Init) void {
.character = character,
.modifiers = modifier_word,
});
// Echo the character to the log — a simple end-to-end
// keyboard check on real hardware: type a known phrase,
// then read it back from usb-hid-keyboard.log (or watch
// it appear live on screen in a -Ddiagnose boot, where
// the kernel console is a log sink). Printable ASCII and
// newline only; other keys are left to the input service.
if (character == '\n' or (character >= 0x20 and character < 0x7F)) {
_ = runtime.system.write(&[1]u8{@intCast(character)});
}
}
},
.released => {