root / lab3 / keyboard.c @ 64
History | View | Annotate | Download (1.36 KB)
1 |
#include <lcom/lcf.h> |
---|---|
2 |
|
3 |
#include "keyboard.h" |
4 |
|
5 |
#include "kbc.h" |
6 |
#include "kbc_macros.h" |
7 |
#include "utils.h" |
8 |
|
9 |
int (subscribe_keyboard_interrupt)(uint8_t interrupt_bit, int *interrupt_id) { |
10 |
if (interrupt_id == NULL) return 1; |
11 |
*interrupt_id = interrupt_bit; |
12 |
return (sys_irqsetpolicy(KBC_IRQ, IRQ_REENABLE | IRQ_EXCLUSIVE, interrupt_id));
|
13 |
} |
14 |
|
15 |
int done = 1; |
16 |
int sz = 1; |
17 |
int got_error_keyboard = 0; |
18 |
|
19 |
void (kbc_ih)(void) { |
20 |
if(done) sz = 1; |
21 |
else sz++;
|
22 |
uint8_t status = 0;
|
23 |
got_error_keyboard = 0;
|
24 |
if (util_sys_inb(STATUS_REG, &status)) {
|
25 |
got_error_keyboard = 1;
|
26 |
return;
|
27 |
} |
28 |
if (status & (TIME_OUT_REC | PARITY_ERROR)) {
|
29 |
got_error_keyboard = 1;
|
30 |
return;
|
31 |
} |
32 |
if ((status & OUT_BUF_FUL) == 0 || (status & AUX_MOUSE) != 0) { |
33 |
got_error_keyboard = 1;
|
34 |
return;
|
35 |
} |
36 |
uint8_t byte = 0;
|
37 |
if (util_sys_inb(OUTPUT_BUF, &byte)) {
|
38 |
got_error_keyboard = 1;
|
39 |
return;
|
40 |
} |
41 |
scancode[sz-1] = byte;
|
42 |
done = !(TWO_BYTE_CODE == byte); |
43 |
} |
44 |
|
45 |
int (keyboard_poll)(uint8_t bytes[], uint8_t *size){
|
46 |
if(bytes == NULL || size == NULL) return 1; |
47 |
uint8_t c; |
48 |
if(kbc_read_byte(&c)) return 1; |
49 |
if(c == TWO_BYTE_CODE){
|
50 |
if(kbc_read_byte(&bytes[1])) return 1; |
51 |
bytes[0] = c;
|
52 |
*size = 2;
|
53 |
}else{
|
54 |
bytes[1] = 0; |
55 |
bytes[0] = c;
|
56 |
*size = 1;
|
57 |
} |
58 |
return 0; |
59 |
} |