]>
git.gir.st - tmk_keyboard.git/blob - pjrc/usb_mouse.c
1 #include <avr/interrupt.h>
2 #include <util/delay.h>
8 uint8_t usb_mouse_protocol
=1;
11 int8_t usb_mouse_send(int8_t x
, int8_t y
, int8_t wheel_v
, int8_t wheel_h
, uint8_t buttons
)
13 uint8_t intr_state
, timeout
;
15 if (!usb_configured()) return -1;
16 if (x
== -128) x
= -127;
17 if (y
== -128) y
= -127;
18 if (wheel_v
== -128) wheel_v
= -127;
19 if (wheel_h
== -128) wheel_h
= -127;
22 UENUM
= MOUSE_ENDPOINT
;
23 timeout
= UDFNUML
+ 50;
25 // are we ready to transmit?
26 if (UEINTX
& (1<<RWAL
)) break;
28 // has the USB gone offline?
29 if (!usb_configured()) return -1;
30 // have we waited too long?
31 if (UDFNUML
== timeout
) return -1;
32 // get ready to try checking again
35 UENUM
= MOUSE_ENDPOINT
;
40 if (usb_mouse_protocol
) {
50 void usb_mouse_print(int8_t x
, int8_t y
, int8_t wheel_v
, int8_t wheel_h
, uint8_t buttons
) {
51 if (!debug_mouse
) return;
52 print("usb_mouse[btn|x y v h]: ");
53 phex(buttons
); print("|");
56 phex(wheel_v
); print(" ");
57 phex(wheel_h
); print("\n");