Project

General

Profile

Statistics
| Revision:

root / lab4 / mouse_func.c @ 56

History | View | Annotate | Download (1.46 KB)

1
#include "mouse_func.h"
2
#include "errors.h"
3
#include "kbc.h"
4
#include "mouse.h"
5

    
6
#include <lcom/lcf.h>
7

    
8
int (subscribe_mouse_interrupt)(uint8_t interrupt_bit, int *interrupt_id) {
9
    if (interrupt_id == NULL) return NULL_PTR;
10
    *interrupt_id = interrupt_bit;
11
    if (sys_irqsetpolicy(MOUSE_IRQ, IRQ_REENABLE | IRQ_EXCLUSIVE, interrupt_id)) return SBCR_ERROR;
12
    return SUCCESS;
13
}
14

    
15
int (unsubscribe_interrupt)(int *interrupt_id) {
16
    if (interrupt_id == NULL) return NULL_PTR;
17
    if (sys_irqrmpolicy(interrupt_id)) return UNSBCR_ERROR;
18
    return SUCCESS;
19
}
20

    
21
int got_error = 0;
22
uint8_t packet[3];
23
int counter = 0;
24

    
25
void (mouse_ih)(void) {
26
    uint8_t status = 0;
27
    got_error = 0;
28

    
29
    if (util_sys_inb(STATUS_REG, &status)) {
30
        got_error = 1;
31
        return;
32
    }
33

    
34
    if (status & (TIME_OUT_REC | PARITY_ERROR)) {
35
        got_error = 1;
36
        return;
37
    }
38

    
39
    uint8_t byte = 0;
40

    
41
    if (util_sys_inb(OUTPUT_BUF, &byte)) {
42
        got_error = 1;
43
        return;
44
    }
45

    
46
    if(counter >= 3) counter = 0;
47
    packet[counter] = byte;
48
    counter++;
49

    
50
}
51

    
52
struct packet (mouse_parse_packet)(const uint8_t *packet_bytes){
53
    struct packet pp;
54
    pp.bytes[0] = packet_bytes[0];
55
    pp.bytes[1] = packet_bytes[1];
56
    pp.bytes[2] = packet_bytes[2];
57
    pp.rb       = pp.bytes[0] & RIGHT_BUTTON;
58
    pp.mb       = pp.bytes[0] & MIDDLE_BUTTON;
59
    pp.lb       = pp.bytes[0] & LEFT_BUTTON;
60
    //pp.delta_x  = 
61
    return pp;
62
}