From b3c0e1e2f9bef74b395c9d9f670c93a8d8f5c725 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Sun, 12 May 2024 23:05:58 -0400 Subject: kernel/amd64: i8042: Prevent blinking capslock LED Holding down the caps-lock key would result in the LED blinking rapidly which is obviously not normal. This commit corrects that behavior. Signed-off-by: Ian Moffett --- sys/arch/amd64/isa/i8042.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/sys/arch/amd64/isa/i8042.c b/sys/arch/amd64/isa/i8042.c index 9b9e254..dd1990f 100644 --- a/sys/arch/amd64/isa/i8042.c +++ b/sys/arch/amd64/isa/i8042.c @@ -48,6 +48,7 @@ __KERNEL_META("$Hyra$: i8042.c, Ian Marco Moffett, " static struct spinlock data_lock; static bool shift_key = false; static bool capslock = false; +static bool capslock_released = true; static int dev_send(bool aux, uint8_t data); @@ -96,8 +97,18 @@ scancode_to_chr(uint8_t sc, char *chr) bool release = __TEST(sc, __BIT(7)); switch (sc) { - /* Capslock */ + /* Capslock pressed */ case 0x3A: + /* + * If we are holding down caps-lock, we do not + * want a stream of presses that constantly cause + * it to toggle, only toggle if released then pushed + * again. + */ + if (!capslock_released) + return -EAGAIN; + + capslock_released = false; capslock = !capslock; if (!capslock) { @@ -106,6 +117,10 @@ scancode_to_chr(uint8_t sc, char *chr) kbd_set_leds(I8042_LED_CAPS); } return -EAGAIN; + /* Capslock released */ + case 0xBA: + capslock_released = true; + return -EAGAIN; /* Shift */ case 0x36: case 0xAA: -- cgit v1.2.3