Project

General

Profile

Statistics
| Revision:

root / proj / src / keyboard.c @ 198

History | View | Annotate | Download (1.5 KB)

1 145 up20180655
#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 167 up20180655
#include "proj_func.h"
10 145 up20180655
11
int (subscribe_kbc_interrupt)(uint8_t interrupt_bit, int *interrupt_id) {
12
    if (interrupt_id == NULL) return NULL_PTR;
13
    *interrupt_id = interrupt_bit;
14
    if(sys_irqsetpolicy(KBC_IRQ, IRQ_REENABLE | IRQ_EXCLUSIVE, interrupt_id)) return SBCR_ERROR;
15
    return SUCCESS;
16
}
17
18
int done = 1;
19
int sz = 1;
20
int got_error_keyboard = SUCCESS;
21
22
void (kbc_ih)(void) {
23 171 up20180655
    if(done) { sz = 1; }
24 145 up20180655
    else     sz++;
25
    uint8_t status = 0;
26
    got_error_keyboard = SUCCESS;
27
    if ((got_error_keyboard = util_sys_inb(STATUS_REG, &status))) return;
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 = READ_ERROR;
34
        return;
35
    }
36
    uint8_t byte = 0;
37
    if ((got_error_keyboard = util_sys_inb(OUTPUT_BUF, &byte))) return;
38
39
    scancode[sz-1] = byte;
40
    done = !(TWO_BYTE_CODE == byte);
41 167 up20180655
42 184 up20180655
    if (done) update_key_presses();
43 167 up20180655
44 145 up20180655
}
45
46
int (keyboard_poll)(uint8_t bytes[], uint8_t *size){
47
    int ret = 0;
48
    if(bytes == NULL || size == NULL) return NULL_PTR;
49
    uint8_t c;
50
    if((ret = kbc_read_byte(&c))) return ret;
51
    if(c == TWO_BYTE_CODE){
52
        if((ret = kbc_read_byte(&bytes[1]))) return ret;
53
        bytes[0] = c;
54
        *size = 2;
55
    }else{
56
        bytes[1] = 0;
57
        bytes[0] = c;
58
        *size = 1;
59
    }
60
    return SUCCESS;
61
}