Project

General

Profile

Statistics
| Revision:

root / lab4 / kbd.c @ 62

History | View | Annotate | Download (1.21 KB)

1 59 up20180642
#include <lcom/lcf.h>
2
3
#include "kbd.h"
4
5
#include "kbc_macros.h"
6
#include "kbc.h"
7
8
int (subscribe_kbc_interrupt)(uint8_t interrupt_bit, int *interrupt_id) {
9
    if (interrupt_id == NULL) return 1;
10
    *interrupt_id = interrupt_bit;
11
    return (sys_irqsetpolicy(KBC_IRQ, IRQ_REENABLE | IRQ_EXCLUSIVE, interrupt_id));
12
}
13
14
void (kbc_ih)(void) {
15
    uint8_t status = 0;
16
    got_error = 0;
17
18
    if (util_sys_inb(STATUS_REG, &status)) {
19
        got_error = 1;
20
        return;
21
    }
22
23
    if (status & (TIME_OUT_REC | PARITY_ERROR)) {
24
        got_error = 1;
25
        return;
26
    }
27
28
    uint8_t byte = 0;
29
30
    if (util_sys_inb(OUTPUT_BUF, &byte)) {
31
        got_error = 1;
32
        return;
33
    }
34
35
    if (two_byte_scancode) {
36
        scancode[1] = byte;
37
        two_byte_scancode = 0;
38
    } else {
39
        scancode[0] = byte;
40
        two_byte_scancode = (byte == TWO_BYTE_CODE);
41
    }
42
43
}
44
45
int (kbd_poll)(uint8_t bytes[], uint8_t *size){
46
    if(bytes == NULL || size == NULL) return 1;
47
    uint8_t c;
48
    if(kbc_read_byte(&c)) return 1;
49
    if(c == TWO_BYTE_CODE){
50
        if(kbc_read_byte(&bytes[1])) return 1;
51
        bytes[0] = c;
52
        *size = 2;
53
    }else{
54
        bytes[1] = 0;
55
        bytes[0] = c;
56
        *size = 1;
57
    }
58
    return 0;
59
}