Project

General

Profile

Revision 56

implementing mouse_parse_packet

View differences:

mouse_func.c
17 17
    if (sys_irqrmpolicy(interrupt_id)) return UNSBCR_ERROR;
18 18
    return SUCCESS;
19 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
}

Also available in: Unified diff