Revision 67
not working
kbc.c | ||
---|---|---|
4 | 4 |
|
5 | 5 |
#include "kbc_macros.h" |
6 | 6 |
#include "utils.h" |
7 |
#include "errors.h" |
|
7 | 8 |
|
8 | 9 |
int (unsubscribe_interrupt)(int *interrupt_id) { |
9 |
if (interrupt_id == NULL) return 1; |
|
10 |
return sys_irqrmpolicy(interrupt_id); |
|
10 |
if (interrupt_id == NULL) return NULL_PTR; |
|
11 |
if(sys_irqrmpolicy(interrupt_id)) return UNSBCR_ERROR; |
|
12 |
return SUCCESS; |
|
11 | 13 |
} |
12 | 14 |
|
13 | 15 |
int (kbc_read_cmd)(uint8_t *cmd){ |
14 |
if(kbc_issue_cmd(READ_KBC_CMD)) return 1; |
|
15 |
if(kbc_read_byte(cmd)) return 1; |
|
16 |
return 0; |
|
16 |
int ret = 0; |
|
17 |
if((ret = kbc_issue_cmd(READ_KBC_CMD))) return ret; |
|
18 |
if((ret = kbc_read_byte(cmd))) return ret; |
|
19 |
return SUCCESS; |
|
17 | 20 |
} |
18 | 21 |
|
19 | 22 |
int (kbc_change_cmd)(uint8_t cmd){ |
20 |
if(kbc_issue_cmd(WRITE_KBC_CMD)) return 1; |
|
21 |
if(sys_outb(KBC_CMD_ARG, cmd)) return 1; |
|
22 |
return 0; |
|
23 |
int ret = 0; |
|
24 |
if((ret = kbc_issue_cmd(WRITE_KBC_CMD))) return ret; |
|
25 |
if((ret = kbc_issue_arg(cmd))) return ret; |
|
26 |
return SUCCESS; |
|
23 | 27 |
} |
24 | 28 |
|
25 | 29 |
int (kbc_restore_keyboard)(){ |
30 |
int ret = 0; |
|
26 | 31 |
uint8_t cmd = 0; |
27 |
if(kbc_read_cmd(&cmd)) return 1;
|
|
32 |
if((ret = kbc_read_cmd(&cmd))) return ret;
|
|
28 | 33 |
cmd = (cmd | INT_KBD) & (~DIS_KBD) ; |
29 |
if(kbc_change_cmd(cmd)) return 1;
|
|
30 |
return 0;
|
|
34 |
if((ret = kbc_change_cmd(cmd))) return ret;
|
|
35 |
return SUCCESS;
|
|
31 | 36 |
} |
32 | 37 |
|
33 | 38 |
int (kbc_issue_cmd)(uint8_t cmd){ |
39 |
int ret = 0; |
|
34 | 40 |
uint8_t stat; |
35 | 41 |
for(int i = 0; i < KBC_NUM_TRIES; ++i){ |
36 |
if(util_sys_inb(STATUS_REG, &stat)) return 1;
|
|
42 |
if((ret = util_sys_inb(STATUS_REG, &stat))) return ret;
|
|
37 | 43 |
if((stat&IN_BUF_FULL) == 0){ |
38 |
if(sys_outb(KBC_CMD, cmd)) return 1;
|
|
39 |
return 0;
|
|
44 |
if(sys_outb(KBC_CMD, cmd)) return WRITE_ERROR;
|
|
45 |
return SUCCESS;
|
|
40 | 46 |
} |
41 | 47 |
tickdelay(micros_to_ticks(DELAY)); |
42 | 48 |
} |
43 |
return 1;
|
|
49 |
return TIMEOUT_ERROR;
|
|
44 | 50 |
} |
45 | 51 |
|
46 | 52 |
int (kbc_issue_arg)(uint8_t arg){ |
53 |
int ret = 0; |
|
47 | 54 |
uint8_t stat; |
48 | 55 |
for(int i = 0; i < KBC_NUM_TRIES; ++i){ |
49 |
if(util_sys_inb(STATUS_REG, &stat)) return 1;
|
|
56 |
if((ret = util_sys_inb(STATUS_REG, &stat))) return ret;
|
|
50 | 57 |
if((stat&IN_BUF_FULL) == 0){ |
51 |
if(sys_outb(KBC_CMD_ARG, arg)) return 1;
|
|
52 |
return 0;
|
|
58 |
if(sys_outb(KBC_CMD_ARG, arg)) return WRITE_ERROR;
|
|
59 |
return SUCCESS;
|
|
53 | 60 |
} |
54 | 61 |
tickdelay(micros_to_ticks(DELAY)); |
55 | 62 |
} |
56 |
return 1;
|
|
63 |
return TIMEOUT_ERROR;
|
|
57 | 64 |
} |
58 | 65 |
|
59 | 66 |
int (kbc_read_byte)(uint8_t *byte){ |
67 |
int ret = 0; |
|
60 | 68 |
uint8_t stat; |
61 | 69 |
while(true){ |
62 |
if(util_sys_inb(STATUS_REG, &stat)) return 1;
|
|
70 |
if((ret = util_sys_inb(STATUS_REG, &stat))) return ret;
|
|
63 | 71 |
if((stat&OUT_BUF_FUL) && (stat&AUX_MOUSE)==0){ |
64 | 72 |
if(stat & (PARITY_ERROR | TIME_OUT_REC)) return 1; |
65 |
if(util_sys_inb(OUTPUT_BUF, byte)) return 1;
|
|
66 |
else return 0;
|
|
73 |
if((ret = util_sys_inb(OUTPUT_BUF, byte))) return ret;
|
|
74 |
else return SUCCESS;
|
|
67 | 75 |
} |
68 | 76 |
tickdelay(micros_to_ticks(DELAY)); |
69 | 77 |
} |
78 |
return TIMEOUT_ERROR; |
|
70 | 79 |
} |
Also available in: Unified diff