comparison Output/pjrcUSB/arm/usb_mouse.c @ 429:970dab727f47

Adding basic mouse button support - Full Mouse support will have to wait for KLL 0.6 * This will include dynamic HID descriptor generation for many wheels and axis depending on the KLL needs - HID descriptor is currently limited to 8 buttons - Technically mouse movement also works (tested by accident), but it's disable for now (needs some API thought) - Adding additional udev rules - Added KRO mode default define
author Jacob Alexander <haata@kiibohd.com>
date Mon, 21 Mar 2016 00:43:19 -0700
parents ce9720634c15
children d3cef419c849
comparison
equal deleted inserted replaced
428:b5746c43904e 429:970dab727f47
1 /* Teensyduino Core Library 1 /* Teensyduino Core Library
2 * http://www.pjrc.com/teensy/ 2 * http://www.pjrc.com/teensy/
3 * Copyright (c) 2013 PJRC.COM, LLC. 3 * Copyright (c) 2013 PJRC.COM, LLC.
4 * Modified by Jacob Alexander (2015) 4 * Modified by Jacob Alexander (2015-2016)
5 * 5 *
6 * Permission is hereby granted, free of charge, to any person obtaining 6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the 7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including 8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish, 9 * without limitation the rights to use, copy, modify, merge, publish,
113 113
114 114
115 115
116 // ----- Variables ----- 116 // ----- Variables -----
117 117
118 static uint8_t transmit_previous_timeout = 0;
119
118 // which buttons are currently pressed 120 // which buttons are currently pressed
119 uint8_t usb_mouse_buttons_state=0; 121 uint8_t usb_mouse_buttons_state = 0;
120 122
121 static uint16_t usb_mouse_resolution_x=DEFAULT_XRES; 123 static uint16_t usb_mouse_resolution_x = DEFAULT_XRES;
122 static uint16_t usb_mouse_resolution_y=DEFAULT_YRES; 124 static uint16_t usb_mouse_resolution_y = DEFAULT_YRES;
123 static uint16_t usb_mouse_position_x=DEFAULT_XRES/2; 125 static uint16_t usb_mouse_position_x = DEFAULT_XRES / 2;
124 static uint16_t usb_mouse_position_y=DEFAULT_YRES/2; 126 static uint16_t usb_mouse_position_y = DEFAULT_YRES / 2;
125 static uint32_t usb_mouse_scale_x=DEFAULT_XSCALE; 127 static uint32_t usb_mouse_scale_x = DEFAULT_XSCALE;
126 static uint32_t usb_mouse_scale_y=DEFAULT_YSCALE; 128 static uint32_t usb_mouse_scale_y = DEFAULT_YSCALE;
127 static uint32_t usb_mouse_offset_x=DEFAULT_XSCALE/2-1; 129 static uint32_t usb_mouse_offset_x = DEFAULT_XSCALE / 2 - 1;
128 static uint32_t usb_mouse_offset_y=DEFAULT_YSCALE/2-1; 130 static uint32_t usb_mouse_offset_y = DEFAULT_YSCALE / 2 - 1;
129 131
130 132
131 133
132 // ----- Functions ----- 134 // ----- Functions -----
133 135
134 // Set the mouse buttons. To create a "click", 2 calls are needed, 136 // Process pending mouse commands
135 // one to push the button down and the second to release it 137 // XXX Missing mouse movement and wheels
136 int usb_mouse_buttons(uint8_t left, uint8_t middle, uint8_t right) 138 // Proper support will require KLL generation of the USB descriptors
137 { 139 // Similar support will be required for joystick control
138 uint8_t mask=0; 140 void usb_mouse_send()
139 141 {
140 if (left) mask |= 1; 142 uint32_t wait_count = 0;
141 if (middle) mask |= 4; 143 usb_packet_t *tx_packet;
142 if (right) mask |= 2; 144
143 usb_mouse_buttons_state = mask; 145 // Wait till ready
144 return usb_mouse_move(0, 0, 0); 146 while ( 1 )
145 } 147 {
146 148 if ( !usb_configuration )
147 149 {
148 static uint8_t transmit_previous_timeout=0; 150 erro_print("USB not configured...");
151 return;
152 }
153
154 // Attempt to acquire a USB packet for the mouse endpoint
155 if ( usb_tx_packet_count( MOUSE_ENDPOINT ) < TX_PACKET_LIMIT )
156 {
157 tx_packet = usb_malloc();
158 if ( tx_packet )
159 break;
160 }
161
162 if ( ++wait_count > TX_TIMEOUT || transmit_previous_timeout )
163 {
164 transmit_previous_timeout = 1;
165 warn_print("USB Transmit Timeout...");
166 return;
167 }
168 yield();
169 }
170
171 transmit_previous_timeout = 0;
172
173 // Prepare USB Mouse Packet
174 // TODO Document each byte
175 // TODO Dynamically generate this code based on KLL requirements
176 *(tx_packet->buf + 0) = USBMouse_Buttons;
177 *(tx_packet->buf + 1) = 0;
178 *(tx_packet->buf + 2) = 0;
179 *(tx_packet->buf + 3) = 0;
180 *(tx_packet->buf + 4) = 0;
181 tx_packet->len = 5;
182 usb_tx( MOUSE_ENDPOINT, tx_packet );
183
184 // Clear status and state
185 USBMouse_Buttons = 0;
186 USBMouse_Changed = 0;
187 }
188
149 189
150 // Move the mouse. x, y and wheel are -127 to 127. Use 0 for no movement. 190 // Move the mouse. x, y and wheel are -127 to 127. Use 0 for no movement.
151 int usb_mouse_move(int8_t x, int8_t y, int8_t wheel) 191 int usb_mouse_move(int8_t x, int8_t y, int8_t wheel)
152 { 192 {
153 uint32_t wait_count=0; 193 uint32_t wait_count=0;