root / lab4 / mouse.c @ 15
History | View | Annotate | Download (2.43 KB)
1 |
#include "mouse.c" |
---|---|
2 |
|
3 |
uint8_t byte; |
4 |
|
5 |
int (util_sys_inb)(int port, uint8_t *value) { //transform 8 bit into 32 bit |
6 |
|
7 |
uint32_t new_val; //initializing 32 bit variable
|
8 |
|
9 |
if(sys_inb(port,&new_val)!=0){ //verifies if there is an error |
10 |
printf("Error in util_sys_inb\n");
|
11 |
return 1; |
12 |
} |
13 |
*value=new_val & 0xFF; //dereferencing "value" |
14 |
#ifdef LAB3
|
15 |
cnt++; |
16 |
#endif
|
17 |
|
18 |
return 0; |
19 |
} |
20 |
|
21 |
void (mouse_ih)(void){ |
22 |
uint8_t status_reg; |
23 |
|
24 |
if(util_sys_inb(STATUS_REG,&status_reg)!=0){ //checks if there is an error |
25 |
printf("Error reading status register in the keyboard interruption\n");
|
26 |
return;
|
27 |
} |
28 |
if(((status_reg & STAT_REG_OBF)==0) ||((status_reg&(STAT_REG_PAR|STAT_REG_TIMEOUT))!=0)){ //checks if there is a parity or timeout error (mask -> 0xC0, bit 7 and 6 set), checks if output buffer is empty |
29 |
printf("Parity/Timeout error or output buffer is empty or data coming from the mouse\n");
|
30 |
return;
|
31 |
} |
32 |
if(util_sys_inb(OUTPUT_BUF,&byte)!=0){//checks if there is an error |
33 |
printf("Error reading output buffer in the keyboard interruption\n");
|
34 |
return;
|
35 |
} |
36 |
|
37 |
} |
38 |
|
39 |
int (mouse_subscribe_int)(uint8_t *bit_no) { //similar function to that of timer_subscribe_int |
40 |
*bit_no = BIT(keyboard_id); |
41 |
if(sys_irqsetpolicy(KEYBOARD_IRQ,(IRQ_REENABLE|IRQ_EXCLUSIVE),&keyboard_id)==1){ //operation to subscribe int |
42 |
printf("Error subscribing int\n");
|
43 |
return 1; |
44 |
} |
45 |
return 0; |
46 |
} |
47 |
|
48 |
int (mouse_unsubscribe_int)() { //similar function to that of timer_unsubscribe_int |
49 |
if(sys_irqrmpolicy(&keyboard_id)==1){ |
50 |
printf("Error unsubscribing int\n");
|
51 |
return 1; |
52 |
} |
53 |
return 0; |
54 |
} |
55 |
|
56 |
int parse_packet(struct packet *pp){ |
57 |
if((pp->bytes[0]&0x80) == 0x80){ |
58 |
pp->y_ov=true;
|
59 |
|
60 |
} |
61 |
else{
|
62 |
pp->y_ov=false;
|
63 |
} |
64 |
|
65 |
if((pp->bytes[0]&0x40)==0x40){ |
66 |
pp->x_ov=true;
|
67 |
|
68 |
} |
69 |
else{
|
70 |
pp->x_ov=false;
|
71 |
} |
72 |
|
73 |
if((pp->bytes[0]&0x02)==0x02){ |
74 |
pp->rb=true;
|
75 |
|
76 |
} |
77 |
else{
|
78 |
pp->rb=false;
|
79 |
} |
80 |
|
81 |
if((pp->bytes[0]&0x04)==0x04){ |
82 |
pp->mb=true;
|
83 |
} |
84 |
else{
|
85 |
pp->mb=false;
|
86 |
} |
87 |
|
88 |
if((pp->bytes[0]&0x01)==0x01){ |
89 |
pp->lb=true;
|
90 |
} |
91 |
else{
|
92 |
pp->lb=false;
|
93 |
} |
94 |
|
95 |
if((pp->bytes[0]&0x20)==0x20){ //it means y_delta is negative |
96 |
pp->delta_y=~pp->bytes[2];
|
97 |
pp->delta_y+=1;
|
98 |
|
99 |
} |
100 |
else{
|
101 |
pp->delta_y=pp->bytes[2];
|
102 |
} |
103 |
|
104 |
if((pp->bytes[0]&0x10)==0x10){ //it means x_delta is negative |
105 |
pp->delta_x=~pp->bytes[1];
|
106 |
pp->delta_x+=1;
|
107 |
|
108 |
} |
109 |
else{
|
110 |
pp->delta_y=pp->bytes[1];
|
111 |
} |
112 |
} |