Changeset 3f8f09f in mainline
- Timestamp:
- 2011-10-15T15:34:03Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 93d2684
- Parents:
- b803845
- Location:
- uspace/drv/bus/usb/usbhid
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/usbhid/subdrivers.c
rb803845 r3f8f09f 42 42 #include "generic/hiddev.h" 43 43 44 static usb_hid_subdriver_usage_t path_kbd[] = {45 {USB_HIDUT_PAGE_GENERIC_DESKTOP, 46 USB_HIDUT_USAGE_GENERIC_DESKTOP_KEYBOARD}, 44 static const usb_hid_subdriver_usage_t path_kbd[] = { 45 {USB_HIDUT_PAGE_GENERIC_DESKTOP, 46 USB_HIDUT_USAGE_GENERIC_DESKTOP_KEYBOARD}, 47 47 {0, 0} 48 48 }; 49 49 50 static usb_hid_subdriver_usage_t path_mouse[] = {50 static const usb_hid_subdriver_usage_t path_mouse[] = { 51 51 {USB_HIDUT_PAGE_GENERIC_DESKTOP, USB_HIDUT_USAGE_GENERIC_DESKTOP_MOUSE}, 52 52 {0, 0} 53 53 }; 54 54 55 static usb_hid_subdriver_usage_t multim_key_path[] = {55 static const usb_hid_subdriver_usage_t multim_key_path[] = { 56 56 {USB_HIDUT_PAGE_CONSUMER, USB_HIDUT_USAGE_CONSUMER_CONSUMER_CONTROL}, 57 57 {0, 0} … … 71 71 .poll_end = NULL 72 72 }, 73 74 73 }, 75 74 { -
uspace/drv/bus/usb/usbhid/subdrivers.h
rb803845 r3f8f09f 78 78 79 79 /** Subdriver for controlling this device. */ 80 usb_hid_subdriver_t subdriver;80 const usb_hid_subdriver_t subdriver; 81 81 } usb_hid_subdriver_mapping_t; 82 82 -
uspace/drv/bus/usb/usbhid/usbhid.c
rb803845 r3f8f09f 67 67 static int usb_hid_set_boot_kbd_subdriver(usb_hid_dev_t *hid_dev) 68 68 { 69 assert(hid_dev != NULL && hid_dev->subdriver_count == 0);70 71 hid_dev->subdrivers = (usb_hid_subdriver_t *)malloc( 72 69 assert(hid_dev != NULL); 70 assert(hid_dev->subdriver_count == 0); 71 72 hid_dev->subdrivers = malloc(sizeof(usb_hid_subdriver_t)); 73 73 if (hid_dev->subdrivers == NULL) { 74 74 return ENOMEM; 75 75 } 76 77 assert(hid_dev->subdriver_count >= 0); 78 79 // set the init callback 80 hid_dev->subdrivers[hid_dev->subdriver_count].init = usb_kbd_init; 81 82 // set the polling callback 83 hid_dev->subdrivers[hid_dev->subdriver_count].poll = 84 usb_kbd_polling_callback; 85 86 // set the polling ended callback 87 hid_dev->subdrivers[hid_dev->subdriver_count].poll_end = NULL; 88 89 // set the deinit callback 90 hid_dev->subdrivers[hid_dev->subdriver_count].deinit = usb_kbd_deinit; 91 92 // set subdriver count 93 ++hid_dev->subdriver_count; 76 hid_dev->subdriver_count = 1; 77 // TODO 0 should be keyboard, but find a better way 78 hid_dev->subdrivers[0] = usb_hid_subdrivers[0].subdriver; 94 79 95 80 return EOK; … … 100 85 static int usb_hid_set_boot_mouse_subdriver(usb_hid_dev_t *hid_dev) 101 86 { 102 assert(hid_dev != NULL && hid_dev->subdriver_count == 0);103 104 hid_dev->subdrivers = (usb_hid_subdriver_t *)malloc( 105 87 assert(hid_dev != NULL); 88 assert(hid_dev->subdriver_count == 0); 89 90 hid_dev->subdrivers = malloc(sizeof(usb_hid_subdriver_t)); 106 91 if (hid_dev->subdrivers == NULL) { 107 92 return ENOMEM; 108 93 } 109 110 assert(hid_dev->subdriver_count >= 0); 111 112 // set the init callback 113 hid_dev->subdrivers[hid_dev->subdriver_count].init = usb_mouse_init; 114 115 // set the polling callback 116 hid_dev->subdrivers[hid_dev->subdriver_count].poll = 117 usb_mouse_polling_callback; 118 119 // set the polling ended callback 120 hid_dev->subdrivers[hid_dev->subdriver_count].poll_end = NULL; 121 122 // set the deinit callback 123 hid_dev->subdrivers[hid_dev->subdriver_count].deinit = usb_mouse_deinit; 124 125 // set subdriver count 126 ++hid_dev->subdriver_count; 94 hid_dev->subdriver_count = 1; 95 // TODO 2 should be mouse, but find a better way 96 hid_dev->subdrivers[2] = usb_hid_subdrivers[0].subdriver; 127 97 128 98 return EOK; … … 135 105 assert(hid_dev != NULL && hid_dev->subdriver_count == 0); 136 106 137 hid_dev->subdrivers = (usb_hid_subdriver_t *)malloc( 138 sizeof(usb_hid_subdriver_t)); 107 hid_dev->subdrivers = malloc(sizeof(usb_hid_subdriver_t)); 139 108 if (hid_dev->subdrivers == NULL) { 140 109 return ENOMEM; 141 110 } 142 143 assert(hid_dev->subdriver_count >= 0); 144 145 // set the init callback 146 hid_dev->subdrivers[hid_dev->subdriver_count].init = 147 usb_generic_hid_init; 148 149 // set the polling callback 150 hid_dev->subdrivers[hid_dev->subdriver_count].poll = 151 usb_generic_hid_polling_callback; 152 153 // set the polling ended callback 154 hid_dev->subdrivers[hid_dev->subdriver_count].poll_end = NULL; 155 156 // set the deinit callback 157 hid_dev->subdrivers[hid_dev->subdriver_count].deinit = 158 usb_generic_hid_deinit; 159 160 // set subdriver count 161 ++hid_dev->subdriver_count; 111 hid_dev->subdriver_count = 1; 112 113 /* Set generic hid subdriver routines */ 114 hid_dev->subdrivers[0].init = usb_generic_hid_init; 115 hid_dev->subdrivers[0].poll = usb_generic_hid_polling_callback; 116 hid_dev->subdrivers[0].poll_end = NULL; 117 hid_dev->subdrivers[0].deinit = usb_generic_hid_deinit; 162 118 163 119 return EOK; … … 166 122 /*----------------------------------------------------------------------------*/ 167 123 168 static bool usb_hid_ids_match( usb_hid_dev_t *hid_dev,124 static bool usb_hid_ids_match(const usb_hid_dev_t *hid_dev, 169 125 const usb_hid_subdriver_mapping_t *mapping) 170 126 { … … 172 128 assert(hid_dev->usb_dev != NULL); 173 129 174 return (hid_dev->usb_dev->descriptors.device.vendor_id 130 return (hid_dev->usb_dev->descriptors.device.vendor_id 175 131 == mapping->vendor_id 176 132 && hid_dev->usb_dev->descriptors.device.product_id … … 180 136 /*----------------------------------------------------------------------------*/ 181 137 182 static bool usb_hid_path_matches(usb_hid_dev_t *hid_dev, 138 static bool usb_hid_path_matches(usb_hid_dev_t *hid_dev, 183 139 const usb_hid_subdriver_mapping_t *mapping) 184 140 { … … 192 148 } 193 149 int i = 0; 194 while (mapping->usage_path[i].usage != 0 150 while (mapping->usage_path[i].usage != 0 195 151 || mapping->usage_path[i].usage_page != 0) { 196 if (usb_hid_report_path_append_item(usage_path, 197 mapping->usage_path[i].usage_page, 152 if (usb_hid_report_path_append_item(usage_path, 153 mapping->usage_path[i].usage_page, 198 154 mapping->usage_path[i].usage) != EOK) { 199 155 usb_log_debug("Failed to append to usage path.\n"); … … 239 195 /*----------------------------------------------------------------------------*/ 240 196 241 static int usb_hid_save_subdrivers(usb_hid_dev_t *hid_dev, 197 static int usb_hid_save_subdrivers(usb_hid_dev_t *hid_dev, 242 198 const usb_hid_subdriver_t **subdrivers, int count) 243 199 { … … 250 206 } 251 207 252 // add one generic HID subdriver per device 253 254 hid_dev->subdrivers = (usb_hid_subdriver_t *)malloc((count + 1) * 255 sizeof(usb_hid_subdriver_t)); 208 /* +1 for generic hid subdriver */ 209 hid_dev->subdrivers = calloc((count + 1), sizeof(usb_hid_subdriver_t)); 256 210 if (hid_dev->subdrivers == NULL) { 257 211 return ENOMEM; … … 265 219 } 266 220 221 /* Add one generic HID subdriver per device */ 267 222 hid_dev->subdrivers[count].init = usb_generic_hid_init; 268 223 hid_dev->subdrivers[count].poll = usb_generic_hid_polling_callback; … … 303 258 return EINVAL; 304 259 } 305 260 306 261 ids_matched = false; 307 262 matched = false; 308 263 309 264 if (mapping->vendor_id >= 0) { 310 265 assert(mapping->product_id >= 0); … … 317 272 } 318 273 } 319 274 320 275 if (mapping->usage_path != NULL) { 321 276 usb_log_debug("Comparing device against usage path.\n"); … … 328 283 matched = ids_matched; 329 284 } 330 285 331 286 if (matched) { 332 287 usb_log_debug("Subdriver matched.\n"); 333 288 subdrivers[count++] = &mapping->subdriver; 334 289 } 335 290 336 291 mapping = &usb_hid_subdrivers[++i]; 337 292 } 338 293 339 // we have all subdrivers determined, save them into the hid device 294 /* We have all subdrivers determined, save them into the hid device */ 295 // TODO Dowe really need this complicated stuff if there is 296 // max_subdrivers limitation? 340 297 return usb_hid_save_subdrivers(hid_dev, subdrivers, count); 341 298 } … … 343 300 /*----------------------------------------------------------------------------*/ 344 301 345 static int usb_hid_check_pipes(usb_hid_dev_t *hid_dev, usb_device_t *dev) 346 { 347 assert(hid_dev != NULL && dev != NULL); 348 349 int rc = EOK; 302 static int usb_hid_check_pipes(usb_hid_dev_t *hid_dev, const usb_device_t *dev) 303 { 304 assert(hid_dev); 305 assert(dev); 350 306 351 307 if (dev->pipes[USB_HID_KBD_POLL_EP_NO].present) { … … 364 320 usb_log_error("None of supported endpoints found - probably" 365 321 " not a supported device.\n"); 366 r c =ENOTSUP;367 } 368 369 return rc;322 return ENOTSUP; 323 } 324 325 return EOK; 370 326 } 371 327 … … 393 349 usb_log_debug("Max size of input report: %zu\n", max_size); 394 350 395 hid_dev->max_input_report_size = max_size;396 351 assert(hid_dev->input_report == NULL); 397 352 398 hid_dev->input_report = malloc(max_size);353 hid_dev->input_report = calloc(1, max_size); 399 354 if (hid_dev->input_report == NULL) { 400 355 return ENOMEM; 401 356 } 402 memset(hid_dev->input_report, 0, max_size);357 hid_dev->max_input_report_size = max_size; 403 358 404 359 return EOK; … … 477 432 break; 478 433 default: 479 assert(hid_dev->poll_pipe_index 434 assert(hid_dev->poll_pipe_index 480 435 == USB_HID_GENERIC_POLL_EP_NO); 481 436 482 437 usb_log_info("Falling back to generic HID driver.\n"); 483 438 rc = usb_hid_set_generic_hid_subdriver(hid_dev); … … 488 443 usb_log_error("No subdriver for handling this device could be" 489 444 " initialized: %s.\n", str_error(rc)); 490 usb_log_debug("Subdriver count: %d\n", 445 usb_log_debug("Subdriver count: %d\n", 491 446 hid_dev->subdriver_count); 492 493 447 } else { 494 448 bool ok = false; 495 496 usb_log_debug("Subdriver count: %d\n", 449 450 usb_log_debug("Subdriver count: %d\n", 497 451 hid_dev->subdriver_count); 498 452 499 453 for (i = 0; i < hid_dev->subdriver_count; ++i) { 500 454 if (hid_dev->subdrivers[i].init != NULL) { … … 527 481 } 528 482 529 530 483 return rc; 531 484 } … … 533 486 /*----------------------------------------------------------------------------*/ 534 487 535 bool usb_hid_polling_callback(usb_device_t *dev, uint8_t *buffer, 488 bool usb_hid_polling_callback(usb_device_t *dev, uint8_t *buffer, 536 489 size_t buffer_size, void *arg) 537 490 { 538 int i;539 540 491 if (dev == NULL || arg == NULL || buffer == NULL) { 541 492 usb_log_error("Missing arguments to polling callback.\n"); 542 493 return false; 543 494 } 544 545 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)arg; 495 usb_hid_dev_t *hid_dev = arg; 546 496 547 497 assert(hid_dev->input_report != NULL); 498 548 499 usb_log_debug("New data [%zu/%zu]: %s\n", buffer_size, 549 500 hid_dev->max_input_report_size, … … 557 508 } 558 509 559 // parse the input report 560 561 int rc = usb_hid_parse_report(&hid_dev->report, buffer, buffer_size, 562 &hid_dev->report_id); 563 510 /* Parse the input report */ 511 const int rc = usb_hid_parse_report( 512 &hid_dev->report, buffer, buffer_size, &hid_dev->report_id); 564 513 if (rc != EOK) { 565 514 usb_log_warning("Error in usb_hid_parse_report():" … … 568 517 569 518 bool cont = false; 570 571 // continue if at least one of the subdrivers want to continue 572 for (i = 0; i < hid_dev->subdriver_count; ++i) { 573 if (hid_dev->subdrivers[i].poll != NULL 574 && hid_dev->subdrivers[i].poll(hid_dev, 575 hid_dev->subdrivers[i].data)) { 576 cont = true; 519 /* Continue if at least one of the subdrivers want to continue */ 520 for (int i = 0; i < hid_dev->subdriver_count; ++i) { 521 if (hid_dev->subdrivers[i].poll != NULL) { 522 cont = cont || hid_dev->subdrivers[i].poll( 523 hid_dev, hid_dev->subdrivers[i].data); 577 524 } 578 525 } … … 583 530 /*----------------------------------------------------------------------------*/ 584 531 585 void usb_hid_polling_ended_callback(usb_device_t *dev, bool reason, 586 void *arg) 587 { 588 int i; 589 590 if (dev == NULL || arg == NULL) { 591 return; 592 } 593 594 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)arg; 595 596 for (i = 0; i < hid_dev->subdriver_count; ++i) { 532 void usb_hid_polling_ended_callback(usb_device_t *dev, bool reason, void *arg) 533 { 534 assert(dev); 535 assert(arg); 536 537 usb_hid_dev_t *hid_dev = arg; 538 539 for (int i = 0; i < hid_dev->subdriver_count; ++i) { 597 540 if (hid_dev->subdrivers[i].poll_end != NULL) { 598 hid_dev->subdrivers[i].poll_end( hid_dev,599 hid_dev ->subdrivers[i].data, reason);541 hid_dev->subdrivers[i].poll_end( 542 hid_dev, hid_dev->subdrivers[i].data, reason); 600 543 } 601 544 } … … 613 556 /*----------------------------------------------------------------------------*/ 614 557 615 int usb_hid_report_number( usb_hid_dev_t *hid_dev)558 int usb_hid_report_number(const usb_hid_dev_t *hid_dev) 616 559 { 617 560 return hid_dev->report_nr; … … 622 565 void usb_hid_deinit(usb_hid_dev_t *hid_dev) 623 566 { 624 int i; 625 626 if (hid_dev == NULL) { 627 return; 628 } 567 assert(hid_dev); 568 assert(hid_dev->subdrivers != NULL || hid_dev->subdriver_count == 0); 569 629 570 630 571 usb_log_debug("Subdrivers: %p, subdriver count: %d\n", 631 572 hid_dev->subdrivers, hid_dev->subdriver_count); 632 573 633 assert(hid_dev->subdrivers != NULL 634 || hid_dev->subdriver_count == 0); 635 636 for (i = 0; i < hid_dev->subdriver_count; ++i) { 574 for (int i = 0; i < hid_dev->subdriver_count; ++i) { 637 575 if (hid_dev->subdrivers[i].deinit != NULL) { 638 576 hid_dev->subdrivers[i].deinit(hid_dev, -
uspace/drv/bus/usb/usbhid/usbhid.h
rb803845 r3f8f09f 146 146 147 147 int usb_hid_init(usb_hid_dev_t *hid_dev, usb_device_t *dev); 148 148 149 void usb_hid_deinit(usb_hid_dev_t *hid_dev); 149 150 … … 155 156 void usb_hid_new_report(usb_hid_dev_t *hid_dev); 156 157 157 int usb_hid_report_number( usb_hid_dev_t *hid_dev);158 int usb_hid_report_number(const usb_hid_dev_t *hid_dev); 158 159 159 160 #endif /* USB_HID_USBHID_H_ */
Note:
See TracChangeset
for help on using the changeset viewer.