Skip to content

Commit a30f7d8

Browse files
New features have been added to the Keyboard driver.
1 parent 5716197 commit a30f7d8

2 files changed

Lines changed: 32 additions & 16 deletions

File tree

Drivers/Keyboard/keyboard.c

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#define KBD_DATA 0x60
55
#define KBD_STAT 0x64
66

7+
static bool_t caps_lock = false;
8+
79
static char kmap[128] = {
810
0, 27, '1','2','3','4','5','6','7','8','9','0','-','=', '\b',
911
'\t','q','w','e','r','t','y','u','i','o','p','[',']','\n',
@@ -16,9 +18,17 @@ static char kbf[KEY_BF_SIZE];
1618
static uint8_t buf_head = 0;
1719
static uint8_t buf_tail = 0;
1820

21+
static char to_upper(char c) {
22+
if (caps_lock && c >= 'a' && c <= 'z') {
23+
return c - 32;
24+
}
25+
return c;
26+
}
27+
1928
void kbd_init() {
2029
buf_head = 0;
2130
buf_tail = 0;
31+
caps_lock = false;
2232
}
2333

2434
uint8_t kb_check() {
@@ -27,28 +37,34 @@ uint8_t kb_check() {
2737

2838
char get_char() {
2939
uint8_t scancode;
30-
40+
3141
while (1) {
3242
while (!(inb(KBD_STAT) & 1));
43+
3344
scancode = inb(KBD_DATA);
3445

35-
if (scancode & 0x80)
46+
if (scancode & 0x80) {
3647
continue;
48+
}
49+
50+
kbd_hndlr(scancode);
51+
52+
if (scancode < 128) {
53+
char c = kmap[scancode];
3754

38-
if (scancode < 128)
39-
return kmap[scancode];
55+
if (c == 0) {
56+
continue;
57+
}
58+
59+
c = to_upper(c);
60+
61+
return c;
62+
}
4063
}
4164
}
4265

43-
void kbd_hndlr() {
44-
uint8_t status = inb(KBD_STAT);
45-
if (status & 0x01) {
46-
uint8_t scancode = inb(KBD_DATA);
47-
char c = 0;
48-
if (scancode < 128) c = kmap[scancode];
49-
if (c) {
50-
kbf[buf_head] = c;
51-
buf_head = (buf_head + 1) % KEY_BF_SIZE;
52-
}
66+
void kbd_hndlr(uint8_t scancode) {
67+
if (scancode == 0x3A) {
68+
caps_lock = !caps_lock;
5369
}
5470
}

Drivers/Keyboard/keyboard.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
void kbd_init();
99
char get_char();
1010
uint8_t kb_check();
11-
void kbd_hndlr();
11+
void kbd_hndlr(uint8_t scancode);
1212

1313
#define KBD_DRIVER_NAME "OpenKernel Keyboard Driver"
14-
#define KBD_DRIVER_VER "0.1"
14+
#define KBD_DRIVER_VER "0.2"
1515
#define KBD_DRIVER_DESC "A simple Keyboard driver for OpenKernel"
1616
#define KBD_DRIVER_KRNL_VER "1.0"
1717

0 commit comments

Comments
 (0)