root / proj / libs / kbc / src / keyboard.c @ 307
History | View | Annotate | Download (1.47 KB)
1 | 145 | up20180655 | #include <lcom/lcf.h> |
---|---|---|---|
2 | |||
3 | #include "keyboard.h" |
||
4 | |||
5 | #include "kbc.h" |
||
6 | #include "utils.h" |
||
7 | #include "errors.h" |
||
8 | 167 | up20180655 | #include "proj_func.h" |
9 | 145 | up20180655 | |
10 | int (subscribe_kbc_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 done = 1; |
||
18 | int sz = 1; |
||
19 | int got_error_keyboard = SUCCESS;
|
||
20 | |||
21 | void (kbc_ih)(void) { |
||
22 | 171 | up20180655 | if(done) { sz = 1; } |
23 | 145 | up20180655 | else sz++;
|
24 | uint8_t status = 0;
|
||
25 | got_error_keyboard = SUCCESS; |
||
26 | if ((got_error_keyboard = util_sys_inb(STATUS_REG, &status))) return; |
||
27 | if (status & (TIME_OUT_REC | PARITY_ERROR)) {
|
||
28 | got_error_keyboard = 1;
|
||
29 | return;
|
||
30 | } |
||
31 | if ((status & OUT_BUF_FUL) == 0 || (status & AUX_MOUSE) != 0) { |
||
32 | got_error_keyboard = READ_ERROR; |
||
33 | return;
|
||
34 | } |
||
35 | uint8_t byte = 0;
|
||
36 | if ((got_error_keyboard = util_sys_inb(OUTPUT_BUF, &byte))) return; |
||
37 | |||
38 | scancode[sz-1] = byte;
|
||
39 | done = !(TWO_BYTE_CODE == byte); |
||
40 | 167 | up20180655 | |
41 | 184 | up20180655 | if (done) update_key_presses();
|
42 | 167 | up20180655 | |
43 | 145 | up20180655 | } |
44 | |||
45 | int (keyboard_poll)(uint8_t bytes[], uint8_t *size){
|
||
46 | int ret = 0; |
||
47 | if(bytes == NULL || size == NULL) return NULL_PTR; |
||
48 | uint8_t c; |
||
49 | if((ret = kbc_read_byte(&c))) return ret; |
||
50 | if(c == TWO_BYTE_CODE){
|
||
51 | if((ret = kbc_read_byte(&bytes[1]))) return ret; |
||
52 | bytes[0] = c;
|
||
53 | *size = 2;
|
||
54 | }else{
|
||
55 | bytes[1] = 0; |
||
56 | bytes[0] = c;
|
||
57 | *size = 1;
|
||
58 | } |
||
59 | return SUCCESS;
|
||
60 | } |