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