Add caps lock handling (ps/2)
This commit is contained in:
parent
7d962ff208
commit
5d316c0691
@ -80,7 +80,8 @@ OBJS+=$(O)/sys/debug.o \
|
||||
$(O)/sys/vfs/vfs_ops.o \
|
||||
$(O)/sys/vfs/vfs_access.o \
|
||||
$(O)/sys/time.o \
|
||||
$(O)/sys/thread.o
|
||||
$(O)/sys/thread.o \
|
||||
$(O)/sys/ctype.o
|
||||
|
||||
# \
|
||||
$(O)/sys/vfs/pty.o \
|
||||
|
@ -1,13 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#define isprint(x) ((x) >= ' ')
|
||||
#define isdigit(x) ((x) >= '0' && (x) <= '9')
|
||||
#define isxdigit(x) (((x) >= 'A' && (x) <= 'F') || \
|
||||
((x) >= 'a' && (x) <= 'f') || \
|
||||
isdigit(x))
|
||||
#define isspace(x) ((x) == ' ' || \
|
||||
(x) == '\t' || \
|
||||
(x) == '\n' || \
|
||||
(x) == '\r')
|
||||
#define tolower(x) (((x) >= 'A' && (x) <= 'Z') ? ((x) - 'A' + 'a') : (x))
|
||||
#define toupper(x) (((x) >= 'a' && (x) <= 'z') ? ((x) - 'a' + 'A') : (x))
|
||||
int isprint(int x);
|
||||
int isdigit(int x);
|
||||
int isxdigit(int x);
|
||||
int isspace(int x);
|
||||
int isupper(int x);
|
||||
int islower(int x);
|
||||
int toupper(int x);
|
||||
int tolower(int x);
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "sys/amd64/hw/ps2.h"
|
||||
#include "sys/amd64/hw/irq.h"
|
||||
#include "sys/amd64/hw/io.h"
|
||||
#include "sys/ctype.h"
|
||||
#include "sys/signum.h"
|
||||
#include "sys/debug.h"
|
||||
#include "sys/tty.h"
|
||||
@ -13,8 +14,11 @@
|
||||
#define PS2_KEY_LCTRL_DOWN 0x1D
|
||||
#define PS2_KEY_LCTRL_UP 0x9D
|
||||
|
||||
#define PS2_KEY_CAPS_LOCK_DOWN 0x3A
|
||||
|
||||
#define PS2_MOD_SHIFT (1 << 0)
|
||||
#define PS2_MOD_CTRL (1 << 1)
|
||||
#define PS2_MOD_CAPS (1 << 2)
|
||||
|
||||
static uint32_t ps2_mods = 0;
|
||||
|
||||
@ -72,6 +76,10 @@ uint32_t ps2_irq_keyboard(void *ctx) {
|
||||
ps2_mods &= ~PS2_MOD_CTRL;
|
||||
}
|
||||
|
||||
if (key == PS2_KEY_CAPS_LOCK_DOWN) {
|
||||
ps2_mods ^= PS2_MOD_CAPS;
|
||||
}
|
||||
|
||||
if (!(key & 0x80) && !(ps2_mods & PS2_MOD_CTRL)) {
|
||||
// Special keys
|
||||
switch (key) {
|
||||
@ -116,6 +124,14 @@ uint32_t ps2_irq_keyboard(void *ctx) {
|
||||
|
||||
char key_char = ((ps2_mods & PS2_MOD_SHIFT) ? ps2_key_table_1 : ps2_key_table_0)[key];
|
||||
|
||||
if (ps2_mods & PS2_MOD_CAPS) {
|
||||
if (isupper(key_char)) {
|
||||
key_char = tolower(key_char);
|
||||
} else if (islower(key_char)) {
|
||||
key_char = toupper(key_char);
|
||||
}
|
||||
}
|
||||
|
||||
if (key_char != 0) {
|
||||
tty_buffer_write(0, key_char);
|
||||
}
|
||||
|
31
sys/ctype.c
Normal file
31
sys/ctype.c
Normal file
@ -0,0 +1,31 @@
|
||||
int isprint(int x) {
|
||||
return x >= ' ' && x < 255;
|
||||
}
|
||||
|
||||
int islower(int x) {
|
||||
return x >= 'a' && x <= 'z';
|
||||
}
|
||||
|
||||
int isupper(int x) {
|
||||
return x >= 'A' && x <= 'Z';
|
||||
}
|
||||
|
||||
int isspace(int x) {
|
||||
return x == ' ' || x == '\n' || x == '\t';
|
||||
}
|
||||
|
||||
int isdigit(int x) {
|
||||
return x >= '0' && x <= '9';
|
||||
}
|
||||
|
||||
int isxdigit(int x) {
|
||||
return (x >= '0' && x <= '9') || (x >= 'A' && x <= 'F') || (x >= 'a' && x <= 'f');
|
||||
}
|
||||
|
||||
int toupper(int x) {
|
||||
return islower(x) ? (x - 'a' + 'A') : x;
|
||||
}
|
||||
|
||||
int tolower(int x) {
|
||||
return isupper(x) ? (x - 'A' + 'a') : x;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user