Project

General

Profile

Revision 80

reorganized remote

View differences:

mouse.c
15 15
}
16 16

  
17 17
int got_error_mouse_ih = 0;
18
uint8_t packet[3];
19
int counter = 0;
18
int counter_mouse_ih = 0;
20 19

  
21 20
void (mouse_ih)(void) {
22 21
    uint8_t status = 0;
23 22
    got_error_mouse_ih = 0;
24
    if(counter >= 3) counter = 0;
23
    if(counter_mouse_ih >= 3) counter_mouse_ih = 0;
25 24

  
26 25
    if ((got_error_mouse_ih = util_sys_inb(STATUS_REG, &status))) return;
27 26

  
......
39 38
    if ((got_error_mouse_ih = util_sys_inb(OUTPUT_BUF, &byte))) return;
40 39

  
41 40
    /// This does not run if: I was expecting the first one but what I get is definitely not the first byte
42
    if((byte & FIRST_BYTE_ID)  || counter){
43
        packet[counter] = byte;
44
        counter++;
41
    if((byte & FIRST_BYTE_ID)  || counter_mouse_ih){
42
        packet_mouse_ih[counter_mouse_ih] = byte;
43
        counter_mouse_ih++;
45 44
    }
46 45
}
47 46

  
......
60 59
    return pp;
61 60
}
62 61

  
63
int (mouse_set_data_report)(int on){
62
int mouse_poll(struct packet *pp, uint16_t period){
64 63
    int ret = 0;
65
    if(on){
66
        if((ret = mouse_issue_cmd(ENABLE_DATA_REP))) return ret;
64

  
65
    int counter = 0;
66
    uint8_t packet[3];
67
    uint8_t byte;
68
    while(counter < 3){
69
        if((ret = mouse_read_data(&byte, period))) return ret;
70
        if((byte & FIRST_BYTE_ID) || counter){
71
            packet[counter] = byte;
72
            counter++;
73
        }
67 74
    }
68
    else{
69
        if((ret = mouse_issue_cmd(   DIS_DATA_REP))) return ret;
70
    }
71
    return ret;
75
    *pp = mouse_parse_packet(packet);
76
    return SUCCESS;
72 77
}
73 78

  
74
int (mouse_read_data)(uint8_t *data) {
79
int (mouse_set_data_report)(int on){
80
    if(on) return mouse_issue_cmd(ENABLE_DATA_REP);
81
    else   return mouse_issue_cmd(   DIS_DATA_REP);
82
}
83

  
84
int (mouse_read_data)(uint8_t *data, uint16_t period) {
75 85
    int ret;
76 86
    if ((ret = mouse_issue_cmd(READ_DATA))) return ret;
77
    if ((ret = mouse_read_byte(data))) return ret;
87
    if ((ret = mouse_poll_byte(data, period))) return ret;
78 88
    return SUCCESS;
79 89
}
80 90

  
......
123 133
    //return TIMEOUT_ERROR;
124 134
}
125 135

  
136
int (mouse_poll_byte)(uint8_t *byte, uint16_t period) {
137
    int ret = 0;
138
    uint8_t stat;
139
    while(true){
140
        if((ret = util_sys_inb(STATUS_REG, &stat))) return ret;
141
        if((stat&OUT_BUF_FUL) && (stat&AUX_MOUSE)) {
142
            if(stat & (PARITY_ERROR | TIME_OUT_REC)) return OTHER_ERROR;
143
            if((ret = util_sys_inb(OUTPUT_BUF, byte))) return ret;
144
            else return SUCCESS;
145
        }
146
        tickdelay(micros_to_ticks(period*1000));
147
    }
148
}
149

  
126 150
int16_t (sign_extend_byte)(uint8_t sign_bit, uint8_t byte) {
127 151
    return (int16_t)(((0xFF * sign_bit)<<8) | byte);
128 152
}

Also available in: Unified diff