]>
git.gir.st - tmk_keyboard.git/blob - usb_mouse.c
1 #include <avr/interrupt.h>
2 #include <util/delay.h>
6 // which buttons are currently pressed
7 uint8_t mouse_buttons
=0;
9 // protocol setting from the host. We use exactly the same report
10 // either way, so this variable only stores the setting since we
11 // are required to be able to report which setting is in use.
12 uint8_t mouse_protocol
=1;
15 // Set the mouse buttons. To create a "click", 2 calls are needed,
16 // one to push the button down and the second to release it
17 int8_t usb_mouse_buttons(uint8_t left
, uint8_t middle
, uint8_t right
)
22 if (middle
) mask
|= 4;
25 return usb_mouse_move(0, 0, 0, 0);
28 // Move the mouse. x, y and wheel are -127 to 127. Use 0 for no movement.
29 int8_t usb_mouse_move(int8_t x
, int8_t y
, int8_t wheel
, int8_t hwheel
)
31 uint8_t intr_state
, timeout
;
33 if (!usb_configured()) return -1;
34 if (x
== -128) x
= -127;
35 if (y
== -128) y
= -127;
36 if (wheel
== -128) wheel
= -127;
37 if (hwheel
== -128) hwheel
= -127;
40 UENUM
= MOUSE_ENDPOINT
;
41 timeout
= UDFNUML
+ 50;
43 // are we ready to transmit?
44 if (UEINTX
& (1<<RWAL
)) break;
46 // has the USB gone offline?
47 if (!usb_configured()) return -1;
48 // have we waited too long?
49 if (UDFNUML
== timeout
) return -1;
50 // get ready to try checking again
53 UENUM
= MOUSE_ENDPOINT
;
55 UEDATX
= mouse_buttons
;