]>
git.gir.st - tmk_keyboard.git/blob - usb_mouse.c
1 #include <avr/interrupt.h>
2 #include <util/delay.h>
7 static bool is_sent
= false;
9 // which buttons are currently pressed
10 uint8_t mouse_buttons
=0;
12 // protocol setting from the host. We use exactly the same report
13 // either way, so this variable only stores the setting since we
14 // are required to be able to report which setting is in use.
15 uint8_t mouse_protocol
=1;
18 // Set the mouse buttons. To create a "click", 2 calls are needed,
19 // one to push the button down and the second to release it
20 int8_t usb_mouse_buttons(uint8_t left
, uint8_t middle
, uint8_t right
)
25 if (middle
) mask
|= 4;
28 return usb_mouse_move(0, 0, 0, 0);
31 // Move the mouse. x, y and wheel are -127 to 127. Use 0 for no movement.
32 int8_t usb_mouse_move(int8_t x
, int8_t y
, int8_t wheel
, int8_t hwheel
)
34 uint8_t intr_state
, timeout
;
36 if (!usb_configured()) return -1;
37 if (x
== -128) x
= -127;
38 if (y
== -128) y
= -127;
39 if (wheel
== -128) wheel
= -127;
40 if (hwheel
== -128) hwheel
= -127;
43 UENUM
= MOUSE_ENDPOINT
;
44 timeout
= UDFNUML
+ 50;
46 // are we ready to transmit?
47 if (UEINTX
& (1<<RWAL
)) break;
49 // has the USB gone offline?
50 if (!usb_configured()) return -1;
51 // have we waited too long?
52 if (UDFNUML
== timeout
) return -1;
53 // get ready to try checking again
56 UENUM
= MOUSE_ENDPOINT
;
58 UEDATX
= mouse_buttons
;
70 void usb_mouse_clear(void) {
74 bool usb_mouse_is_sent(void) {
78 void usb_mouse_print(int8_t mouse_x
, int8_t mouse_y
, int8_t wheel_v
, int8_t wheel_h
) {
79 print("mouse btn|x y v h: ");
80 phex(mouse_buttons
); print("|");
81 phex(mouse_x
); print(" ");
82 phex(mouse_y
); print(" ");
83 phex(wheel_v
); print(" ");
84 phex(wheel_h
); print("\n");