Mercurial > louis > kiibohd-controller
annotate Output/pjrcUSB/arm/usb_mouse.c @ 430:d3cef419c849
Adding relative movement mouse key support
- Still very basic (lots of room for improvement)
- Capability format will likely change at some point
- 16 bit movement control, however repeat rate limits usability (will need KLL 0.4 to make better)
author | Jacob Alexander <haata@kiibohd.com> |
---|---|
date | Mon, 21 Mar 2016 22:23:57 -0700 |
parents | 970dab727f47 |
children | 68e19d7c953e |
rev | line source |
---|---|
369
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1 /* Teensyduino Core Library |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
2 * http://www.pjrc.com/teensy/ |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
3 * Copyright (c) 2013 PJRC.COM, LLC. |
429
970dab727f47
Adding basic mouse button support
Jacob Alexander <haata@kiibohd.com>
parents:
369
diff
changeset
|
4 * Modified by Jacob Alexander (2015-2016) |
369
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
5 * |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
6 * Permission is hereby granted, free of charge, to any person obtaining |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
7 * a copy of this software and associated documentation files (the |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
8 * "Software"), to deal in the Software without restriction, including |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
9 * without limitation the rights to use, copy, modify, merge, publish, |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
10 * distribute, sublicense, and/or sell copies of the Software, and to |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
11 * permit persons to whom the Software is furnished to do so, subject to |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
12 * the following conditions: |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
13 * |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
14 * 1. The above copyright notice and this permission notice shall be |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
15 * included in all copies or substantial portions of the Software. |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
16 * |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
17 * 2. If the Software is incorporated into a build system that allows |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
18 * selection among a list of target devices, then similar target |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
19 * devices manufactured by PJRC.COM must be included in the list of |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
20 * target devices and selectable in the same manner. |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
21 * |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
23 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
24 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
25 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
26 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
27 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
28 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
29 * SOFTWARE. |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
30 */ |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
31 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
32 // ----- Includes ----- |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
33 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
34 // Compiler Includes |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
35 #include <string.h> // for memcpy() |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
36 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
37 // Project Includes |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
38 #include <Lib/OutputLib.h> |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
39 #include <print.h> |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
40 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
41 // Local Includes |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
42 #include "usb_dev.h" |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
43 #include "usb_mouse.h" |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
44 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
45 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
46 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
47 // ----- Defines ----- |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
48 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
49 // Maximum number of transmit packets to queue so we don't starve other endpoints for memory |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
50 #define TX_PACKET_LIMIT 3 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
51 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
52 // When the PC isn't listening, how long do we wait before discarding data? |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
53 #define TX_TIMEOUT_MSEC 30 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
54 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
55 #if F_CPU == 168000000 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
56 #define TX_TIMEOUT (TX_TIMEOUT_MSEC * 1100) |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
57 #elif F_CPU == 144000000 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
58 #define TX_TIMEOUT (TX_TIMEOUT_MSEC * 932) |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
59 #elif F_CPU == 120000000 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
60 #define TX_TIMEOUT (TX_TIMEOUT_MSEC * 764) |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
61 #elif F_CPU == 96000000 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
62 #define TX_TIMEOUT (TX_TIMEOUT_MSEC * 596) |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
63 #elif F_CPU == 72000000 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
64 #define TX_TIMEOUT (TX_TIMEOUT_MSEC * 512) |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
65 #elif F_CPU == 48000000 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
66 #define TX_TIMEOUT (TX_TIMEOUT_MSEC * 428) |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
67 #elif F_CPU == 24000000 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
68 #define TX_TIMEOUT (TX_TIMEOUT_MSEC * 262) |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
69 #endif |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
70 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
71 //#define DEFAULT_XRES 640 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
72 //#define DEFAULT_YRES 480 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
73 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
74 //#define DEFAULT_XRES 800 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
75 //#define DEFAULT_YRES 600 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
76 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
77 //#define DEFAULT_XRES 1024 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
78 //#define DEFAULT_YRES 768 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
79 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
80 //#define DEFAULT_XRES 1280 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
81 //#define DEFAULT_YRES 720 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
82 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
83 //#define DEFAULT_XRES 1280 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
84 //#define DEFAULT_YRES 800 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
85 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
86 #define DEFAULT_XRES 1366 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
87 #define DEFAULT_YRES 768 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
88 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
89 //#define DEFAULT_XRES 1440 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
90 //#define DEFAULT_YRES 900 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
91 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
92 //#define DEFAULT_XRES 1920 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
93 //#define DEFAULT_YRES 1080 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
94 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
95 //#define DEFAULT_XRES 2560 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
96 //#define DEFAULT_YRES 1440 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
97 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
98 //#define DEFAULT_XRES 2560 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
99 //#define DEFAULT_YRES 1600 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
100 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
101 //#define DEFAULT_XRES 2880 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
102 //#define DEFAULT_YRES 1800 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
103 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
104 //#define DEFAULT_XRES 3840 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
105 //#define DEFAULT_YRES 2160 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
106 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
107 //#define DEFAULT_XRES 7680 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
108 //#define DEFAULT_YRES 4320 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
109 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
110 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
111 #define DEFAULT_XSCALE ((0x80000000ul+DEFAULT_XRES/2)/DEFAULT_XRES) |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
112 #define DEFAULT_YSCALE ((0x80000000ul+DEFAULT_YRES/2)/DEFAULT_YRES) |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
113 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
114 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
115 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
116 // ----- Variables ----- |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
117 |
429
970dab727f47
Adding basic mouse button support
Jacob Alexander <haata@kiibohd.com>
parents:
369
diff
changeset
|
118 static uint8_t transmit_previous_timeout = 0; |
970dab727f47
Adding basic mouse button support
Jacob Alexander <haata@kiibohd.com>
parents:
369
diff
changeset
|
119 |
369
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
120 // which buttons are currently pressed |
429
970dab727f47
Adding basic mouse button support
Jacob Alexander <haata@kiibohd.com>
parents:
369
diff
changeset
|
121 uint8_t usb_mouse_buttons_state = 0; |
369
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
122 |
429
970dab727f47
Adding basic mouse button support
Jacob Alexander <haata@kiibohd.com>
parents:
369
diff
changeset
|
123 static uint16_t usb_mouse_resolution_x = DEFAULT_XRES; |
970dab727f47
Adding basic mouse button support
Jacob Alexander <haata@kiibohd.com>
parents:
369
diff
changeset
|
124 static uint16_t usb_mouse_resolution_y = DEFAULT_YRES; |
970dab727f47
Adding basic mouse button support
Jacob Alexander <haata@kiibohd.com>
parents:
369
diff
changeset
|
125 static uint16_t usb_mouse_position_x = DEFAULT_XRES / 2; |
970dab727f47
Adding basic mouse button support
Jacob Alexander <haata@kiibohd.com>
parents:
369
diff
changeset
|
126 static uint16_t usb_mouse_position_y = DEFAULT_YRES / 2; |
970dab727f47
Adding basic mouse button support
Jacob Alexander <haata@kiibohd.com>
parents:
369
diff
changeset
|
127 static uint32_t usb_mouse_scale_x = DEFAULT_XSCALE; |
970dab727f47
Adding basic mouse button support
Jacob Alexander <haata@kiibohd.com>
parents:
369
diff
changeset
|
128 static uint32_t usb_mouse_scale_y = DEFAULT_YSCALE; |
970dab727f47
Adding basic mouse button support
Jacob Alexander <haata@kiibohd.com>
parents:
369
diff
changeset
|
129 static uint32_t usb_mouse_offset_x = DEFAULT_XSCALE / 2 - 1; |
970dab727f47
Adding basic mouse button support
Jacob Alexander <haata@kiibohd.com>
parents:
369
diff
changeset
|
130 static uint32_t usb_mouse_offset_y = DEFAULT_YSCALE / 2 - 1; |
369
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
131 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
132 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
133 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
134 // ----- Functions ----- |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
135 |
429
970dab727f47
Adding basic mouse button support
Jacob Alexander <haata@kiibohd.com>
parents:
369
diff
changeset
|
136 // Process pending mouse commands |
970dab727f47
Adding basic mouse button support
Jacob Alexander <haata@kiibohd.com>
parents:
369
diff
changeset
|
137 // XXX Missing mouse movement and wheels |
970dab727f47
Adding basic mouse button support
Jacob Alexander <haata@kiibohd.com>
parents:
369
diff
changeset
|
138 // Proper support will require KLL generation of the USB descriptors |
970dab727f47
Adding basic mouse button support
Jacob Alexander <haata@kiibohd.com>
parents:
369
diff
changeset
|
139 // Similar support will be required for joystick control |
970dab727f47
Adding basic mouse button support
Jacob Alexander <haata@kiibohd.com>
parents:
369
diff
changeset
|
140 void usb_mouse_send() |
369
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
141 { |
429
970dab727f47
Adding basic mouse button support
Jacob Alexander <haata@kiibohd.com>
parents:
369
diff
changeset
|
142 uint32_t wait_count = 0; |
970dab727f47
Adding basic mouse button support
Jacob Alexander <haata@kiibohd.com>
parents:
369
diff
changeset
|
143 usb_packet_t *tx_packet; |
970dab727f47
Adding basic mouse button support
Jacob Alexander <haata@kiibohd.com>
parents:
369
diff
changeset
|
144 |
970dab727f47
Adding basic mouse button support
Jacob Alexander <haata@kiibohd.com>
parents:
369
diff
changeset
|
145 // Wait till ready |
970dab727f47
Adding basic mouse button support
Jacob Alexander <haata@kiibohd.com>
parents:
369
diff
changeset
|
146 while ( 1 ) |
970dab727f47
Adding basic mouse button support
Jacob Alexander <haata@kiibohd.com>
parents:
369
diff
changeset
|
147 { |
970dab727f47
Adding basic mouse button support
Jacob Alexander <haata@kiibohd.com>
parents:
369
diff
changeset
|
148 if ( !usb_configuration ) |
970dab727f47
Adding basic mouse button support
Jacob Alexander <haata@kiibohd.com>
parents:
369
diff
changeset
|
149 { |
970dab727f47
Adding basic mouse button support
Jacob Alexander <haata@kiibohd.com>
parents:
369
diff
changeset
|
150 erro_print("USB not configured..."); |
970dab727f47
Adding basic mouse button support
Jacob Alexander <haata@kiibohd.com>
parents:
369
diff
changeset
|
151 return; |
970dab727f47
Adding basic mouse button support
Jacob Alexander <haata@kiibohd.com>
parents:
369
diff
changeset
|
152 } |
970dab727f47
Adding basic mouse button support
Jacob Alexander <haata@kiibohd.com>
parents:
369
diff
changeset
|
153 |
970dab727f47
Adding basic mouse button support
Jacob Alexander <haata@kiibohd.com>
parents:
369
diff
changeset
|
154 // Attempt to acquire a USB packet for the mouse endpoint |
970dab727f47
Adding basic mouse button support
Jacob Alexander <haata@kiibohd.com>
parents:
369
diff
changeset
|
155 if ( usb_tx_packet_count( MOUSE_ENDPOINT ) < TX_PACKET_LIMIT ) |
970dab727f47
Adding basic mouse button support
Jacob Alexander <haata@kiibohd.com>
parents:
369
diff
changeset
|
156 { |
970dab727f47
Adding basic mouse button support
Jacob Alexander <haata@kiibohd.com>
parents:
369
diff
changeset
|
157 tx_packet = usb_malloc(); |
970dab727f47
Adding basic mouse button support
Jacob Alexander <haata@kiibohd.com>
parents:
369
diff
changeset
|
158 if ( tx_packet ) |
970dab727f47
Adding basic mouse button support
Jacob Alexander <haata@kiibohd.com>
parents:
369
diff
changeset
|
159 break; |
970dab727f47
Adding basic mouse button support
Jacob Alexander <haata@kiibohd.com>
parents:
369
diff
changeset
|
160 } |
369
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
161 |
429
970dab727f47
Adding basic mouse button support
Jacob Alexander <haata@kiibohd.com>
parents:
369
diff
changeset
|
162 if ( ++wait_count > TX_TIMEOUT || transmit_previous_timeout ) |
970dab727f47
Adding basic mouse button support
Jacob Alexander <haata@kiibohd.com>
parents:
369
diff
changeset
|
163 { |
970dab727f47
Adding basic mouse button support
Jacob Alexander <haata@kiibohd.com>
parents:
369
diff
changeset
|
164 transmit_previous_timeout = 1; |
970dab727f47
Adding basic mouse button support
Jacob Alexander <haata@kiibohd.com>
parents:
369
diff
changeset
|
165 warn_print("USB Transmit Timeout..."); |
970dab727f47
Adding basic mouse button support
Jacob Alexander <haata@kiibohd.com>
parents:
369
diff
changeset
|
166 return; |
970dab727f47
Adding basic mouse button support
Jacob Alexander <haata@kiibohd.com>
parents:
369
diff
changeset
|
167 } |
970dab727f47
Adding basic mouse button support
Jacob Alexander <haata@kiibohd.com>
parents:
369
diff
changeset
|
168 yield(); |
970dab727f47
Adding basic mouse button support
Jacob Alexander <haata@kiibohd.com>
parents:
369
diff
changeset
|
169 } |
970dab727f47
Adding basic mouse button support
Jacob Alexander <haata@kiibohd.com>
parents:
369
diff
changeset
|
170 |
970dab727f47
Adding basic mouse button support
Jacob Alexander <haata@kiibohd.com>
parents:
369
diff
changeset
|
171 transmit_previous_timeout = 0; |
970dab727f47
Adding basic mouse button support
Jacob Alexander <haata@kiibohd.com>
parents:
369
diff
changeset
|
172 |
970dab727f47
Adding basic mouse button support
Jacob Alexander <haata@kiibohd.com>
parents:
369
diff
changeset
|
173 // Prepare USB Mouse Packet |
970dab727f47
Adding basic mouse button support
Jacob Alexander <haata@kiibohd.com>
parents:
369
diff
changeset
|
174 // TODO Dynamically generate this code based on KLL requirements |
430
d3cef419c849
Adding relative movement mouse key support
Jacob Alexander <haata@kiibohd.com>
parents:
429
diff
changeset
|
175 uint16_t *packet_data = (uint16_t*)(&tx_packet->buf[0]); |
d3cef419c849
Adding relative movement mouse key support
Jacob Alexander <haata@kiibohd.com>
parents:
429
diff
changeset
|
176 packet_data[0] = USBMouse_Buttons; |
d3cef419c849
Adding relative movement mouse key support
Jacob Alexander <haata@kiibohd.com>
parents:
429
diff
changeset
|
177 packet_data[1] = USBMouse_Relative_x; |
d3cef419c849
Adding relative movement mouse key support
Jacob Alexander <haata@kiibohd.com>
parents:
429
diff
changeset
|
178 packet_data[2] = USBMouse_Relative_y; |
d3cef419c849
Adding relative movement mouse key support
Jacob Alexander <haata@kiibohd.com>
parents:
429
diff
changeset
|
179 tx_packet->len = 6; |
429
970dab727f47
Adding basic mouse button support
Jacob Alexander <haata@kiibohd.com>
parents:
369
diff
changeset
|
180 usb_tx( MOUSE_ENDPOINT, tx_packet ); |
970dab727f47
Adding basic mouse button support
Jacob Alexander <haata@kiibohd.com>
parents:
369
diff
changeset
|
181 |
970dab727f47
Adding basic mouse button support
Jacob Alexander <haata@kiibohd.com>
parents:
369
diff
changeset
|
182 // Clear status and state |
970dab727f47
Adding basic mouse button support
Jacob Alexander <haata@kiibohd.com>
parents:
369
diff
changeset
|
183 USBMouse_Buttons = 0; |
430
d3cef419c849
Adding relative movement mouse key support
Jacob Alexander <haata@kiibohd.com>
parents:
429
diff
changeset
|
184 USBMouse_Relative_x = 0; |
d3cef419c849
Adding relative movement mouse key support
Jacob Alexander <haata@kiibohd.com>
parents:
429
diff
changeset
|
185 USBMouse_Relative_y = 0; |
429
970dab727f47
Adding basic mouse button support
Jacob Alexander <haata@kiibohd.com>
parents:
369
diff
changeset
|
186 USBMouse_Changed = 0; |
369
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
187 } |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
188 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
189 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
190 // Move the mouse. x, y and wheel are -127 to 127. Use 0 for no movement. |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
191 int usb_mouse_move(int8_t x, int8_t y, int8_t wheel) |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
192 { |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
193 uint32_t wait_count=0; |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
194 usb_packet_t *tx_packet; |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
195 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
196 //serial_print("move"); |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
197 //serial_print("\n"); |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
198 if (x == -128) x = -127; |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
199 if (y == -128) y = -127; |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
200 if (wheel == -128) wheel = -127; |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
201 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
202 while (1) { |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
203 if (!usb_configuration) { |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
204 return -1; |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
205 } |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
206 if (usb_tx_packet_count(MOUSE_ENDPOINT) < TX_PACKET_LIMIT) { |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
207 tx_packet = usb_malloc(); |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
208 if (tx_packet) break; |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
209 } |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
210 if (++wait_count > TX_TIMEOUT || transmit_previous_timeout) { |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
211 transmit_previous_timeout = 1; |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
212 return -1; |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
213 } |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
214 yield(); |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
215 } |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
216 transmit_previous_timeout = 0; |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
217 *(tx_packet->buf + 0) = 1; |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
218 *(tx_packet->buf + 1) = usb_mouse_buttons_state; |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
219 *(tx_packet->buf + 2) = x; |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
220 *(tx_packet->buf + 3) = y; |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
221 *(tx_packet->buf + 4) = wheel; |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
222 tx_packet->len = 5; |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
223 usb_tx(MOUSE_ENDPOINT, tx_packet); |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
224 return 0; |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
225 } |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
226 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
227 int usb_mouse_position(uint16_t x, uint16_t y) |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
228 { |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
229 uint32_t wait_count=0, val32; |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
230 usb_packet_t *tx_packet; |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
231 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
232 if (x >= usb_mouse_resolution_x) x = usb_mouse_resolution_x - 1; |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
233 usb_mouse_position_x = x; |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
234 if (y >= usb_mouse_resolution_y) y = usb_mouse_resolution_y - 1; |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
235 usb_mouse_position_y = y; |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
236 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
237 while (1) { |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
238 if (!usb_configuration) { |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
239 return -1; |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
240 } |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
241 if (usb_tx_packet_count(MOUSE_ENDPOINT) < TX_PACKET_LIMIT) { |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
242 tx_packet = usb_malloc(); |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
243 if (tx_packet) break; |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
244 } |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
245 if (++wait_count > TX_TIMEOUT || transmit_previous_timeout) { |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
246 transmit_previous_timeout = 1; |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
247 return -1; |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
248 } |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
249 yield(); |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
250 } |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
251 transmit_previous_timeout = 0; |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
252 *(tx_packet->buf + 0) = 2; |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
253 val32 = usb_mouse_position_x * usb_mouse_scale_x + usb_mouse_offset_x; |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
254 //serial_print("position:"); |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
255 //serial_phex16(usb_mouse_position_x); |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
256 //serial_print("->"); |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
257 //serial_phex32(val32); |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
258 *(tx_packet->buf + 1) = val32 >> 16; |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
259 *(tx_packet->buf + 2) = val32 >> 24; |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
260 val32 = usb_mouse_position_y * usb_mouse_scale_y + usb_mouse_offset_y; |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
261 //serial_print(","); |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
262 //serial_phex16(usb_mouse_position_y); |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
263 //serial_print("->"); |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
264 //serial_phex32(val32); |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
265 //serial_print("\n"); |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
266 *(tx_packet->buf + 3) = val32 >> 16; |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
267 *(tx_packet->buf + 4) = val32 >> 24; |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
268 tx_packet->len = 5; |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
269 usb_tx(MOUSE_ENDPOINT, tx_packet); |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
270 return 0; |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
271 } |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
272 |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
273 void usb_mouse_screen_size(uint16_t width, uint16_t height, uint8_t mac) |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
274 { |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
275 if (width < 128) width = 128; |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
276 else if (width > 7680) width = 7680; |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
277 if (height < 128) height = 128; |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
278 else if (height > 7680) height = 7680; |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
279 usb_mouse_resolution_x = width; |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
280 usb_mouse_resolution_y = height; |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
281 usb_mouse_position_x = width / 2; |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
282 usb_mouse_position_y = height / 2; |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
283 usb_mouse_scale_x = (0x80000000ul + (width >> 1)) / width; |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
284 usb_mouse_scale_y = (0x80000000ul + (height >> 1)) / height; |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
285 usb_mouse_offset_x = (usb_mouse_scale_x >> 1) - 1; |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
286 usb_mouse_offset_y = (usb_mouse_scale_y >> 1) - 1; |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
287 if (mac) { |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
288 // ugly workaround for Mac's HID coordinate scaling: |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
289 // http://lists.apple.com/archives/usb/2011/Jun/msg00032.html |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
290 usb_mouse_offset_x += 161061273ul; |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
291 usb_mouse_offset_y += 161061273ul; |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
292 usb_mouse_scale_x = (1825361101ul + (width >> 1)) / width; |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
293 usb_mouse_scale_y = (1825361101ul + (height >> 1)) / height; |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
294 } |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
295 } |
ce9720634c15
Forgot to add these files in an earlier commit
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
296 |