Revision 14
Added mouse.c, mouse.h and i8024.h; Haven't made mouse_enable_date_reporting() function
lab4/lab4.c | ||
---|---|---|
3 | 3 |
|
4 | 4 |
#include <stdint.h> |
5 | 5 |
#include <stdio.h> |
6 |
#include "mouse.h" |
|
6 | 7 |
|
7 | 8 |
// Any header files included below this line should have been created by you |
8 | 9 |
|
... | ... | |
30 | 31 |
return 0; |
31 | 32 |
} |
32 | 33 |
|
34 |
extern uint8_t byte; |
|
33 | 35 |
|
34 | 36 |
int (mouse_test_packet)(uint32_t cnt) { |
35 |
/* To be completed */ |
|
36 |
printf("%s(%u): under construction\n", __func__, cnt); |
|
37 |
int r, ipc_status; |
|
38 |
uint8_t mouse_irq, size=0; //size of mouse packet is 3 byte long |
|
39 |
message msg; |
|
40 |
uint32_t counter_copy=cnt; |
|
41 |
|
|
42 |
struct packet pp; |
|
43 |
|
|
44 |
if(mouse_enable_data_reporting()!=0){ //check if disabling stream mode worked |
|
45 |
printf("Error disabling stream mode\n"); |
|
37 | 46 |
return 1; |
47 |
} |
|
48 |
|
|
49 |
if(mouse_subscribe_int(&kmouse_irq)!=0){ //check if subscription worked |
|
50 |
printf("Error subscribing int\n"); |
|
51 |
return 1; |
|
52 |
} |
|
53 |
|
|
54 |
while(counter_copy>0){ //looping until counter>0 |
|
55 |
|
|
56 |
if ((r = driver_receive(ANY, &msg, &ipc_status))==1){ |
|
57 |
printf("driver_receive failed with: %d",r); |
|
58 |
continue; |
|
59 |
} |
|
60 |
if (is_ipc_notify(ipc_status)){ //received notification |
|
61 |
switch (_ENDPOINT_P(msg.m_source)){ |
|
62 |
case HARDWARE: //hardware interrupt notification |
|
63 |
if (msg.m_notify.interrupts &mouse_irq){ // subscribed interrupt |
|
64 |
|
|
65 |
mouse_ih(); |
|
66 |
if((size==0 && ((byte&0x08)==0x08)) || size==1 ||size==2){ //0x08 is the mask to check if the 3rd bit of the first byte is set |
|
67 |
pp.bytes[size]=byte; |
|
68 |
size++; |
|
69 |
} |
|
70 |
if(size==3){ |
|
71 |
size=0; |
|
72 |
parse_packet(&pp); |
|
73 |
mouse_print_packet(&pp); |
|
74 |
counter_copy--; |
|
75 |
} |
|
76 |
} |
|
77 |
break; |
|
78 |
default: |
|
79 |
break; //no other notifications expected: do nothing |
|
80 |
} |
|
81 |
} |
|
82 |
else { //received a standard message, not a notification |
|
83 |
//no standard messages expected: do nothing |
|
84 |
} |
|
85 |
} |
|
86 |
|
|
87 |
if (mouse_unsubscribe_int() != 0) { //check if unsubscription worked |
|
88 |
printf("Error unsubscribing int \n"); |
|
89 |
return 1; |
|
90 |
} |
|
91 |
scan_code=0; |
|
92 |
|
|
93 |
return 0; |
|
38 | 94 |
} |
39 | 95 |
|
40 | 96 |
int (mouse_test_remote)(uint16_t period, uint8_t cnt) { |
Also available in: Unified diff