root / lab4 / mouse_func.c @ 57
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 got_error_mouse_ih = 0; |
16 |
uint8_t packet[3];
|
17 |
int counter = 0; |
18 |
|
19 |
void (mouse_ih)(void) { |
20 |
uint8_t status = 0;
|
21 |
got_error_mouse_ih = 0;
|
22 |
|
23 |
if (util_sys_inb(STATUS_REG, &status)) {
|
24 |
got_error_mouse_ih = 1;
|
25 |
return;
|
26 |
} |
27 |
|
28 |
if (status & (TIME_OUT_REC | PARITY_ERROR)) {
|
29 |
got_error_mouse_ih = 1;
|
30 |
return;
|
31 |
} |
32 |
|
33 |
uint8_t byte = 0;
|
34 |
|
35 |
if (util_sys_inb(OUTPUT_BUF, &byte)) {
|
36 |
got_error_mouse_ih = 1;
|
37 |
return;
|
38 |
} |
39 |
|
40 |
if(counter >= 3) counter = 0; |
41 |
packet[counter] = byte; |
42 |
counter++; |
43 |
|
44 |
} |
45 |
|
46 |
struct packet (mouse_parse_packet)(const uint8_t *packet_bytes){ |
47 |
struct packet pp;
|
48 |
pp.bytes[0] = packet_bytes[0]; |
49 |
pp.bytes[1] = packet_bytes[1]; |
50 |
pp.bytes[2] = packet_bytes[2]; |
51 |
pp.rb = pp.bytes[0] & RIGHT_BUTTON;
|
52 |
pp.mb = pp.bytes[0] & MIDDLE_BUTTON;
|
53 |
pp.lb = pp.bytes[0] & LEFT_BUTTON;
|
54 |
pp.delta_x = pp.bytes[1];
|
55 |
pp.delta_y = pp.bytes[2];
|
56 |
pp.x_ov = pp.bytes[0] & X_OVERFLOW;
|
57 |
pp.y_ov = pp.bytes[0] & Y_OVERFLOW;
|
58 |
return pp;
|
59 |
} |