root / proj / libs / kbc / src / kbc.c @ 309
History | View | Annotate | Download (1.99 KB)
1 |
#include <lcom/lcf.h> |
---|---|
2 |
|
3 |
#include "kbc.h" |
4 |
|
5 |
#include "utils.h" |
6 |
#include "errors.h" |
7 |
|
8 |
int (kbc_read_cmd)(uint8_t *cmd){
|
9 |
int ret = 0; |
10 |
if((ret = kbc_issue_cmd(READ_KBC_CMD))) return ret; |
11 |
if((ret = kbc_read_byte(cmd))) return ret; |
12 |
return SUCCESS;
|
13 |
} |
14 |
|
15 |
int (kbc_change_cmd)(uint8_t cmd){
|
16 |
int ret = 0; |
17 |
if((ret = kbc_issue_cmd(WRITE_KBC_CMD))) return ret; |
18 |
if((ret = kbc_issue_arg(cmd))) return ret; |
19 |
return SUCCESS;
|
20 |
} |
21 |
|
22 |
int (kbc_restore_kbd)(){
|
23 |
int ret = 0; |
24 |
uint8_t cmd = 0;
|
25 |
if((ret = kbc_read_cmd(&cmd))) return ret; |
26 |
cmd = (cmd | INT_KBD) & (~DIS_KBD); |
27 |
if((ret = kbc_change_cmd(cmd))) return ret; |
28 |
return SUCCESS;
|
29 |
} |
30 |
|
31 |
int (kbc_issue_cmd)(uint8_t cmd){
|
32 |
int ret = 0; |
33 |
uint8_t stat; |
34 |
for(int i = 0; i < KBC_NUM_TRIES; ++i){ |
35 |
if((ret = util_sys_inb(STATUS_REG, &stat))) return ret; |
36 |
if((stat&IN_BUF_FULL) == 0){ |
37 |
if(sys_outb(KBC_CMD, cmd)) return WRITE_ERROR; |
38 |
return SUCCESS;
|
39 |
} |
40 |
tickdelay(micros_to_ticks(DELAY)); |
41 |
} |
42 |
return TIMEOUT_ERROR;
|
43 |
} |
44 |
|
45 |
int (kbc_issue_arg)(uint8_t arg){
|
46 |
int ret = 0; |
47 |
uint8_t stat; |
48 |
for(int i = 0; i < KBC_NUM_TRIES; ++i){ |
49 |
if((ret = util_sys_inb(STATUS_REG, &stat))) return ret; |
50 |
if((stat&IN_BUF_FULL) == 0){ |
51 |
if(sys_outb(KBC_CMD_ARG, arg)) return WRITE_ERROR; |
52 |
return SUCCESS;
|
53 |
} |
54 |
tickdelay(micros_to_ticks(DELAY)); |
55 |
} |
56 |
return TIMEOUT_ERROR;
|
57 |
} |
58 |
|
59 |
int (kbc_read_byte)(uint8_t *byte){
|
60 |
int ret = 0; |
61 |
uint8_t stat; |
62 |
for(int i = 0; i < KBC_NUM_TRIES; ++i){ |
63 |
if((ret = util_sys_inb(STATUS_REG, &stat))) return ret; |
64 |
if((stat&OUT_BUF_FUL) && (stat&AUX_MOUSE)==0){ |
65 |
if(stat & (PARITY_ERROR | TIME_OUT_REC)) return OTHER_ERROR; |
66 |
if((ret = util_sys_inb(OUTPUT_BUF, byte))) return ret; |
67 |
else return SUCCESS; |
68 |
} |
69 |
tickdelay(micros_to_ticks(DELAY)); |
70 |
} |
71 |
printf("Timing out\n");
|
72 |
return TIMEOUT_ERROR;
|
73 |
} |