]> git.donarmstrong.com Git - qmk_firmware.git/blob - usb_mouse.c
added description of ADB socket pintouts.
[qmk_firmware.git] / usb_mouse.c
1 #include <avr/interrupt.h>
2 #include <util/delay.h>
3 #include "usb_mouse.h"
4 #include "print.h"
5 #include "debug.h"
6
7
8 uint8_t usb_mouse_protocol=1;
9
10
11 int8_t usb_mouse_send(int8_t x, int8_t y, int8_t wheel_v, int8_t wheel_h, uint8_t buttons)
12 {
13         uint8_t intr_state, timeout;
14
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;
20         intr_state = SREG;
21         cli();
22         UENUM = MOUSE_ENDPOINT;
23         timeout = UDFNUML + 50;
24         while (1) {
25                 // are we ready to transmit?
26                 if (UEINTX & (1<<RWAL)) break;
27                 SREG = intr_state;
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
33                 intr_state = SREG;
34                 cli();
35                 UENUM = MOUSE_ENDPOINT;
36         }
37         UEDATX = buttons;
38         UEDATX = x;
39         UEDATX = y;
40         if (usb_mouse_protocol) {
41             UEDATX = wheel_v;
42             UEDATX = wheel_h;
43         }
44         
45         UEINTX = 0x3A;
46         SREG = intr_state;
47         return 0;
48 }
49
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("|");
54     phex(x); print(" ");
55     phex(y); print(" ");
56     phex(wheel_v); print(" ");
57     phex(wheel_h); print("\n");
58 }