Changes in uspace/drv/bus/usb/usbhid/usbhid.c [9d58539:e2dfa86] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/usbhid/usbhid.c
r9d58539 re2dfa86 41 41 #include <usb/hid/hidreport.h> 42 42 #include <usb/hid/request.h> 43 43 44 #include <errno.h> 45 #include <macros.h> 44 46 #include <str_error.h> 45 47 … … 58 60 NULL 59 61 }; 60 /*----------------------------------------------------------------------------*/ 62 61 63 static int usb_hid_set_boot_kbd_subdriver(usb_hid_dev_t *hid_dev) 62 64 { … … 74 76 return EOK; 75 77 } 76 /*----------------------------------------------------------------------------*/ 78 77 79 static int usb_hid_set_boot_mouse_subdriver(usb_hid_dev_t *hid_dev) 78 80 { … … 90 92 return EOK; 91 93 } 92 /*----------------------------------------------------------------------------*/ 94 93 95 static int usb_hid_set_generic_hid_subdriver(usb_hid_dev_t *hid_dev) 94 96 { … … 110 112 return EOK; 111 113 } 112 /*----------------------------------------------------------------------------*/ 114 113 115 static bool usb_hid_ids_match(const usb_hid_dev_t *hid_dev, 114 116 const usb_hid_subdriver_mapping_t *mapping) 115 117 { 116 assert(hid_dev != NULL); 117 assert(hid_dev->usb_dev != NULL); 118 119 return (hid_dev->usb_dev->descriptors.device.vendor_id 120 == mapping->vendor_id 121 && hid_dev->usb_dev->descriptors.device.product_id 122 == mapping->product_id); 123 } 124 /*----------------------------------------------------------------------------*/ 118 assert(hid_dev); 119 assert(hid_dev->usb_dev); 120 assert(mapping); 121 const usb_standard_device_descriptor_t *d = 122 &usb_device_descriptors(hid_dev->usb_dev)->device; 123 124 return (d->vendor_id == mapping->vendor_id) 125 && (d->product_id == mapping->product_id); 126 } 127 125 128 static bool usb_hid_path_matches(usb_hid_dev_t *hid_dev, 126 129 const usb_hid_subdriver_mapping_t *mapping) … … 178 181 return matches; 179 182 } 180 /*----------------------------------------------------------------------------*/ 183 181 184 static int usb_hid_save_subdrivers(usb_hid_dev_t *hid_dev, 182 185 const usb_hid_subdriver_t **subdrivers, unsigned count) … … 211 214 return EOK; 212 215 } 213 /*----------------------------------------------------------------------------*/ 216 214 217 static int usb_hid_find_subdrivers(usb_hid_dev_t *hid_dev) 215 218 { … … 263 266 return usb_hid_save_subdrivers(hid_dev, subdrivers, count); 264 267 } 265 /*----------------------------------------------------------------------------*/ 266 static int usb_hid_check_pipes(usb_hid_dev_t *hid_dev, constusb_device_t *dev)268 269 static int usb_hid_check_pipes(usb_hid_dev_t *hid_dev, usb_device_t *dev) 267 270 { 268 271 assert(hid_dev); … … 270 273 271 274 static const struct { 272 unsigned ep_number;275 const usb_endpoint_description_t *desc; 273 276 const char* description; 274 277 } endpoints[] = { 275 { USB_HID_KBD_POLL_EP_NO, "Keyboard endpoint"},276 { USB_HID_MOUSE_POLL_EP_NO, "Mouse endpoint"},277 { USB_HID_GENERIC_POLL_EP_NO, "Generic HID endpoint"},278 {&usb_hid_kbd_poll_endpoint_description, "Keyboard endpoint"}, 279 {&usb_hid_mouse_poll_endpoint_description, "Mouse endpoint"}, 280 {&usb_hid_generic_poll_endpoint_description, "Generic HID endpoint"}, 278 281 }; 279 282 280 for (unsigned i = 0; i < sizeof(endpoints)/sizeof(endpoints[0]); ++i) { 281 if (endpoints[i].ep_number >= dev->pipes_count) { 282 return EINVAL; 283 } 284 if (dev->pipes[endpoints[i].ep_number].present) { 283 for (unsigned i = 0; i < ARRAY_SIZE(endpoints); ++i) { 284 usb_endpoint_mapping_t *epm = 285 usb_device_get_mapped_ep_desc(dev, endpoints[i].desc); 286 if (epm && epm->present) { 285 287 usb_log_debug("Found: %s.\n", endpoints[i].description); 286 hid_dev->poll_pipe_ index = endpoints[i].ep_number;288 hid_dev->poll_pipe_mapping = epm; 287 289 return EOK; 288 290 } … … 290 292 return ENOTSUP; 291 293 } 292 /*----------------------------------------------------------------------------*/ 294 293 295 static int usb_hid_init_report(usb_hid_dev_t *hid_dev) 294 296 { … … 322 324 return EOK; 323 325 } 324 /*----------------------------------------------------------------------------*/ 326 325 327 /* 326 328 * This functions initializes required structures from the device's descriptors … … 351 353 /* The USB device should already be initialized, save it in structure */ 352 354 hid_dev->usb_dev = dev; 353 hid_dev->poll_pipe_ index = -1;355 hid_dev->poll_pipe_mapping = NULL; 354 356 355 357 int rc = usb_hid_check_pipes(hid_dev, dev); … … 381 383 "boot protocol.\n"); 382 384 383 switch (hid_dev->poll_pipe_ index) {384 case USB_HID_ KBD_POLL_EP_NO:385 switch (hid_dev->poll_pipe_mapping->interface->interface_protocol) { 386 case USB_HID_PROTOCOL_KEYBOARD: 385 387 usb_log_info("Falling back to kbd boot protocol.\n"); 386 388 rc = usb_kbd_set_boot_protocol(hid_dev); … … 389 391 } 390 392 break; 391 case USB_HID_ MOUSE_POLL_EP_NO:393 case USB_HID_PROTOCOL_MOUSE: 392 394 usb_log_info("Falling back to mouse boot protocol.\n"); 393 395 rc = usb_mouse_set_boot_protocol(hid_dev); … … 397 399 break; 398 400 default: 399 assert(hid_dev->poll_pipe_index400 == USB_HID_GENERIC_POLL_EP_NO);401 401 usb_log_info("Falling back to generic HID driver.\n"); 402 402 usb_hid_set_generic_hid_subdriver(hid_dev); … … 458 458 return rc; 459 459 } 460 /*----------------------------------------------------------------------------*/ 460 461 461 bool usb_hid_polling_callback(usb_device_t *dev, uint8_t *buffer, 462 462 size_t buffer_size, void *arg) … … 485 485 &hid_dev->report, buffer, buffer_size, &hid_dev->report_id); 486 486 if (rc != EOK) { 487 usb_log_warning(" Errorin usb_hid_parse_report():"487 usb_log_warning("Failure in usb_hid_parse_report():" 488 488 "%s\n", str_error(rc)); 489 489 } … … 500 500 return cont; 501 501 } 502 /*----------------------------------------------------------------------------*/ 502 503 503 void usb_hid_polling_ended_callback(usb_device_t *dev, bool reason, void *arg) 504 504 { … … 517 517 hid_dev->running = false; 518 518 } 519 /*----------------------------------------------------------------------------*/ 519 520 520 void usb_hid_new_report(usb_hid_dev_t *hid_dev) 521 521 { 522 522 ++hid_dev->report_nr; 523 523 } 524 /*----------------------------------------------------------------------------*/ 524 525 525 int usb_hid_report_number(const usb_hid_dev_t *hid_dev) 526 526 { 527 527 return hid_dev->report_nr; 528 528 } 529 /*----------------------------------------------------------------------------*/ 529 530 530 void usb_hid_deinit(usb_hid_dev_t *hid_dev) 531 531 {
Note:
See TracChangeset
for help on using the changeset viewer.