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