Changes in uspace/drv/usbhid/mouse/mousedev.c [31cfee16:e60436b] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbhid/mouse/mousedev.c
r31cfee16 re60436b 39 39 #include <usb/classes/hid.h> 40 40 #include <usb/classes/hidreq.h> 41 #include <usb/classes/hidut.h>42 41 #include <errno.h> 43 42 #include <str_error.h> … … 46 45 #include "mousedev.h" 47 46 #include "../usbhid.h" 48 49 #define NAME "mouse"50 47 51 48 /*----------------------------------------------------------------------------*/ … … 65 62 /** Default idle rate for mouses. */ 66 63 static const uint8_t IDLE_RATE = 0; 67 static const size_t USB_MOUSE_BUTTON_COUNT = 3;68 64 69 65 /*----------------------------------------------------------------------------*/ … … 174 170 /*----------------------------------------------------------------------------*/ 175 171 176 static bool usb_mouse_process_boot_report(usb_ hid_dev_t *hid_dev,172 static bool usb_mouse_process_boot_report(usb_mouse_t *mouse_dev, 177 173 uint8_t *buffer, size_t buffer_size) 178 174 { 179 usb_mouse_t *mouse_dev = (usb_mouse_t *)hid_dev->data;180 181 175 usb_log_debug2("got buffer: %s.\n", 182 176 usb_debug_str_buffer(buffer, buffer_size, 0)); 183 184 if (mouse_dev->console_phone < 0) { 185 usb_log_error(NAME " No console phone.\n"); 186 return false; // ?? 187 } 188 189 /* 190 * parse the input report 191 */ 192 193 usb_log_debug(NAME " Calling usb_hid_parse_report() with " 194 "buffer %s\n", usb_debug_str_buffer(buffer, buffer_size, 0)); 195 196 uint8_t report_id; 197 198 int rc = usb_hid_parse_report(hid_dev->report, buffer, buffer_size, 199 &report_id); 200 201 if (rc != EOK) { 202 usb_log_warning(NAME "Error in usb_hid_parse_report(): %s\n", 203 str_error(rc)); 204 return true; 205 } 206 207 /* 208 * X 209 */ 210 int shift_x = 0; 211 212 usb_hid_report_path_t *path = usb_hid_report_path(); 213 usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_GENERIC_DESKTOP, 214 USB_HIDUT_USAGE_GENERIC_DESKTOP_X); 215 216 usb_hid_report_path_set_report_id(path, report_id); 217 218 usb_hid_report_field_t *field = usb_hid_report_get_sibling( 219 hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END, 220 USB_HID_REPORT_TYPE_INPUT); 221 222 if (field != NULL) { 223 usb_log_debug(NAME " VALUE(%X) USAGE(%X)\n", field->value, 224 field->usage); 225 shift_x = field->value; 226 } 227 228 usb_hid_report_path_free(path); 229 230 /* 231 * Y 232 */ 233 int shift_y = 0; 234 235 path = usb_hid_report_path(); 236 usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_GENERIC_DESKTOP, 237 USB_HIDUT_USAGE_GENERIC_DESKTOP_Y); 238 239 usb_hid_report_path_set_report_id(path, report_id); 240 241 field = usb_hid_report_get_sibling( 242 hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END, 243 USB_HID_REPORT_TYPE_INPUT); 244 245 if (field != NULL) { 246 usb_log_debug(NAME " VALUE(%X) USAGE(%X)\n", field->value, 247 field->usage); 248 shift_y = field->value; 249 } 250 251 usb_hid_report_path_free(path); 252 253 if ((shift_x != 0) || (shift_y != 0)) { 254 async_req_2_0(mouse_dev->console_phone, 255 MEVENT_MOVE, shift_x, shift_y); 256 } 257 258 /* 259 * Buttons 260 */ 261 path = usb_hid_report_path(); 262 usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_BUTTON, 0); 263 usb_hid_report_path_set_report_id(path, report_id); 264 265 field = usb_hid_report_get_sibling( 266 hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END 267 | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 268 USB_HID_REPORT_TYPE_INPUT); 269 270 if (field != NULL) { 271 usb_log_debug(NAME " VALUE(%X) USAGE(%X)\n", field->value, 272 field->usage); 273 274 if (mouse_dev->buttons[field->usage - field->usage_minimum] == 0 275 && field->value != 0) { 177 178 uint8_t butt = buffer[0]; 179 char str_buttons[4] = { 180 butt & 1 ? '#' : '.', 181 butt & 2 ? '#' : '.', 182 butt & 4 ? '#' : '.', 183 0 184 }; 185 186 int shift_x = ((int) buffer[1]) - 127; 187 int shift_y = ((int) buffer[2]) - 127; 188 int wheel = ((int) buffer[3]) - 127; 189 190 if (buffer[1] == 0) { 191 shift_x = 0; 192 } 193 if (buffer[2] == 0) { 194 shift_y = 0; 195 } 196 if (buffer[3] == 0) { 197 wheel = 0; 198 } 199 200 if (mouse_dev->console_phone >= 0) { 201 usb_log_debug("Console phone: %d\n", mouse_dev->console_phone); 202 if ((shift_x != 0) || (shift_y != 0)) { 203 /* FIXME: guessed for QEMU */ 276 204 async_req_2_0(mouse_dev->console_phone, 277 MEVENT_BUTTON, field->usage, 1); 278 mouse_dev->buttons[field->usage - field->usage_minimum] 279 = field->value; 280 } else if ( 281 mouse_dev->buttons[field->usage - field->usage_minimum] != 0 282 && field->value == 0) { 283 async_req_2_0(mouse_dev->console_phone, 284 MEVENT_BUTTON, field->usage, 0); 285 mouse_dev->buttons[field->usage - field->usage_minimum] 286 = field->value; 287 } 288 289 field = usb_hid_report_get_sibling( 290 hid_dev->report, field, path, USB_HID_PATH_COMPARE_END 291 | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 292 USB_HID_REPORT_TYPE_INPUT); 293 } 294 295 usb_hid_report_path_free(path); 205 MEVENT_MOVE, 206 - shift_x / 10, - shift_y / 10); 207 } else { 208 usb_log_error("No move reported\n"); 209 } 210 if (butt) { 211 /* FIXME: proper button clicking. */ 212 async_req_2_0(mouse_dev->console_phone, 213 MEVENT_BUTTON, 1, 1); 214 async_req_2_0(mouse_dev->console_phone, 215 MEVENT_BUTTON, 1, 0); 216 } 217 } else { 218 usb_log_error("No console phone in mouse!!\n"); 219 } 220 221 usb_log_debug("buttons=%s dX=%+3d dY=%+3d wheel=%+3d\n", 222 str_buttons, shift_x, shift_y, wheel); 223 224 /* Guess. */ 225 //async_usleep(1000); 226 // no sleep right now 296 227 297 228 return true; 298 }299 300 /*----------------------------------------------------------------------------*/301 302 static int usb_mouse_create_function(usb_hid_dev_t *hid_dev)303 {304 /* Create the function exposed under /dev/devices. */305 usb_log_debug("Creating DDF function %s...\n", HID_MOUSE_FUN_NAME);306 ddf_fun_t *fun = ddf_fun_create(hid_dev->usb_dev->ddf_dev, fun_exposed,307 HID_MOUSE_FUN_NAME);308 if (fun == NULL) {309 usb_log_error("Could not create DDF function node.\n");310 return ENOMEM;311 }312 313 /*314 * Store the initialized HID device and HID ops315 * to the DDF function.316 */317 fun->ops = &hid_dev->ops;318 fun->driver_data = hid_dev; // TODO: maybe change to hid_dev->data319 320 int rc = ddf_fun_bind(fun);321 if (rc != EOK) {322 usb_log_error("Could not bind DDF function: %s.\n",323 str_error(rc));324 ddf_fun_destroy(fun);325 return rc;326 }327 328 usb_log_debug("Adding DDF function to class %s...\n",329 HID_MOUSE_CLASS_NAME);330 rc = ddf_fun_add_to_class(fun, HID_MOUSE_CLASS_NAME);331 if (rc != EOK) {332 usb_log_error(333 "Could not add DDF function to class %s: %s.\n",334 HID_MOUSE_CLASS_NAME, str_error(rc));335 ddf_fun_destroy(fun);336 return rc;337 }338 339 return EOK;340 229 } 341 230 … … 359 248 } 360 249 361 mouse_dev->buttons = (int32_t *)calloc(USB_MOUSE_BUTTON_COUNT,362 sizeof(int32_t));363 364 if (mouse_dev->buttons == NULL) {365 usb_log_fatal("No memory!\n");366 free(mouse_dev);367 return ENOMEM;368 }369 370 250 // save the Mouse device structure into the HID device structure 371 251 hid_dev->data = mouse_dev; … … 375 255 376 256 // TODO: how to know if the device supports the request??? 377 // usbhid_req_set_idle(&hid_dev->usb_dev->ctrl_pipe, 378 // hid_dev->usb_dev->interface_no, IDLE_RATE); 379 380 int rc = usb_mouse_create_function(hid_dev); 381 if (rc != EOK) { 382 usb_mouse_free(&mouse_dev); 383 return rc; 384 } 257 usbhid_req_set_idle(&hid_dev->usb_dev->ctrl_pipe, 258 hid_dev->usb_dev->interface_no, IDLE_RATE); 385 259 386 260 return EOK; … … 406 280 return false; 407 281 } 408 409 return usb_mouse_process_boot_report(hid_dev, buffer, buffer_size); 282 usb_mouse_t *mouse_dev = (usb_mouse_t *)hid_dev->data; 283 284 return usb_mouse_process_boot_report(mouse_dev, buffer, buffer_size); 410 285 } 411 286
Note:
See TracChangeset
for help on using the changeset viewer.