Changes in uspace/drv/usbhid/usbhid.c [8fb45e08:faa44e58] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbhid/usbhid.c
r8fb45e08 rfaa44e58 63 63 static const int USB_HID_MAX_SUBDRIVERS = 10; 64 64 65 /** @todo What happens if this is not fibril local? */ 66 //static fibril_local bool report_number; 65 static fibril_local bool report_received; 67 66 68 67 /*----------------------------------------------------------------------------*/ … … 204 203 205 204 usb_log_debug("Compare flags: %d\n", mapping->compare); 206 // size_t size = usb_hid_report_size(hid_dev->report, 0, 207 // USB_HID_REPORT_TYPE_INPUT); 208 size_t size = 0; 209 usb_hid_report_field_t *field = usb_hid_report_get_sibling (hid_dev->report, 210 NULL, usage_path, mapping->compare, USB_HID_REPORT_TYPE_INPUT); 211 while(field != NULL) { 212 size++; 213 field = usb_hid_report_get_sibling (hid_dev->report, 214 field, usage_path, mapping->compare, 215 USB_HID_REPORT_TYPE_INPUT); 216 } 217 205 size_t size = usb_hid_report_input_length(hid_dev->report, usage_path, 206 mapping->compare); 218 207 usb_log_debug("Size of the input report: %zuB\n", size); 208 219 209 usb_hid_report_path_free(usage_path); 220 210 … … 235 225 } 236 226 237 // add one generic HID subdriver per device 238 239 hid_dev->subdrivers = (usb_hid_subdriver_t *)malloc((count + 1) * 227 hid_dev->subdrivers = (usb_hid_subdriver_t *)malloc(count * 240 228 sizeof(usb_hid_subdriver_t)); 241 229 if (hid_dev->subdrivers == NULL) { … … 250 238 } 251 239 252 hid_dev->subdrivers[count].init = usb_generic_hid_init; 253 hid_dev->subdrivers[count].poll = usb_generic_hid_polling_callback; 254 hid_dev->subdrivers[count].deinit = NULL; 255 hid_dev->subdrivers[count].poll_end = NULL; 256 257 hid_dev->subdriver_count = count + 1; 240 hid_dev->subdriver_count = count; 258 241 259 242 return EOK; … … 315 298 316 299 if (matched) { 317 usb_log_debug("Subdriver matched.\n");318 300 subdrivers[count++] = &mapping->subdriver; 319 301 } … … 357 339 /*----------------------------------------------------------------------------*/ 358 340 359 static int usb_hid_init_report(usb_hid_dev_t *hid_dev)360 {361 assert(hid_dev != NULL && hid_dev->report != NULL);362 363 uint8_t report_id = 0;364 size_t size;/* = usb_hid_report_byte_size(hid_dev->report, report_id,365 USB_HID_REPORT_TYPE_INPUT);*/366 367 size_t max_size = 0;368 369 do {370 size = usb_hid_report_byte_size(hid_dev->report, report_id,371 USB_HID_REPORT_TYPE_INPUT);372 usb_log_debug("Report ID: %u, size: %zu\n", report_id, size);373 max_size = (size > max_size) ? size : max_size;374 report_id = usb_hid_get_next_report_id(hid_dev->report,375 report_id, USB_HID_REPORT_TYPE_INPUT);376 } while (report_id != 0);377 378 usb_log_debug("Max size of input report: %zu\n", max_size);379 380 hid_dev->max_input_report_size = max_size;381 assert(hid_dev->input_report == NULL);382 383 hid_dev->input_report = malloc(max_size);384 if (hid_dev->input_report == NULL) {385 return ENOMEM;386 }387 memset(hid_dev->input_report, 0, max_size);388 389 return EOK;390 }391 392 /*----------------------------------------------------------------------------*/393 394 341 usb_hid_dev_t *usb_hid_new(void) 395 342 { … … 446 393 /* Get the report descriptor and parse it. */ 447 394 rc = usb_hid_process_report_descriptor(hid_dev->usb_dev, 448 hid_dev->report , &hid_dev->report_desc, &hid_dev->report_desc_size);395 hid_dev->report); 449 396 450 397 bool fallback = false; … … 510 457 if (hid_dev->subdrivers[i].init != NULL) { 511 458 usb_log_debug("Initializing subdriver %d.\n",i); 512 rc = hid_dev->subdrivers[i].init(hid_dev, 513 &hid_dev->subdrivers[i].data); 459 rc = hid_dev->subdrivers[i].init(hid_dev); 514 460 if (rc != EOK) { 515 461 usb_log_warning("Failed to initialize" … … 527 473 } 528 474 529 // save max input report size and allocate space for the report530 rc = usb_hid_init_report(hid_dev);531 if (rc != EOK) {532 usb_log_error("Failed to initialize input report buffer.\n");533 }534 535 475 return rc; 536 476 } … … 550 490 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)arg; 551 491 552 // int allocated = (hid_dev->input_report != NULL); 553 assert(hid_dev->input_report != NULL); 554 usb_log_debug("Max input report size: %zu, buffer size: %zu\n", 555 hid_dev->max_input_report_size, buffer_size); 556 assert(hid_dev->max_input_report_size >= buffer_size); 557 558 // if (/*!allocated*/ 559 // /*|| *//*hid_dev->input_report_size < buffer_size*/) { 560 // uint8_t *input_old = hid_dev->input_report; 561 // uint8_t *input_new = (uint8_t *)malloc(buffer_size); 562 563 // if (input_new == NULL) { 564 // usb_log_error("Failed to allocate space for input " 565 // "buffer. This event may not be reported\n"); 566 // memset(hid_dev->input_report, 0, 567 // hid_dev->input_report_size); 568 // } else { 569 // memcpy(input_new, input_old, 570 // hid_dev->input_report_size); 571 // hid_dev->input_report = input_new; 572 // if (allocated) { 573 // free(input_old); 574 // } 575 // usb_hid_new_report(); 576 // } 577 // } 492 int allocated = (hid_dev->input_report != NULL); 493 494 if (!allocated 495 || hid_dev->input_report_size < buffer_size) { 496 uint8_t *input_old = hid_dev->input_report; 497 uint8_t *input_new = (uint8_t *)malloc(buffer_size); 498 499 if (input_new == NULL) { 500 usb_log_error("Failed to allocate space for input " 501 "buffer. This event may not be reported\n"); 502 memset(hid_dev->input_report, 0, 503 hid_dev->input_report_size); 504 } else { 505 memcpy(input_new, input_old, 506 hid_dev->input_report_size); 507 hid_dev->input_report = input_new; 508 if (allocated) { 509 free(input_old); 510 } 511 usb_hid_new_report(); 512 } 513 } 578 514 579 515 /*! @todo This should probably be atomic. */ 580 516 memcpy(hid_dev->input_report, buffer, buffer_size); 581 517 hid_dev->input_report_size = buffer_size; 582 usb_hid_new_report(hid_dev);583 518 584 519 bool cont = false; … … 587 522 for (i = 0; i < hid_dev->subdriver_count; ++i) { 588 523 if (hid_dev->subdrivers[i].poll != NULL 589 && hid_dev->subdrivers[i].poll(hid_dev, 590 hid_dev->subdrivers[i].data, buffer,buffer_size)) {524 && hid_dev->subdrivers[i].poll(hid_dev, buffer, 525 buffer_size)) { 591 526 cont = true; 592 527 } … … 611 546 for (i = 0; i < hid_dev->subdriver_count; ++i) { 612 547 if (hid_dev->subdrivers[i].poll_end != NULL) { 613 hid_dev->subdrivers[i].poll_end(hid_dev, 614 hid_dev->subdrivers[i].data, reason); 548 hid_dev->subdrivers[i].poll_end(hid_dev, reason); 615 549 } 616 550 } … … 656 590 /*----------------------------------------------------------------------------*/ 657 591 658 void usb_hid_new_report(usb_hid_dev_t *hid_dev) 659 { 660 ++hid_dev->report_nr; 661 } 662 663 /*----------------------------------------------------------------------------*/ 664 665 int usb_hid_report_number(usb_hid_dev_t *hid_dev) 666 { 667 return hid_dev->report_nr; 668 } 669 670 /*----------------------------------------------------------------------------*/ 671 672 //void usb_hid_report_received(void) 673 //{ 674 // ++report_number; 675 //} 676 677 /*----------------------------------------------------------------------------*/ 678 679 //bool usb_hid_report_ready(void) 680 //{ 681 // return !report_received; 682 //} 592 void usb_hid_new_report(void) 593 { 594 report_received = false; 595 } 596 597 /*----------------------------------------------------------------------------*/ 598 599 void usb_hid_report_received(void) 600 { 601 report_received = true; 602 } 603 604 /*----------------------------------------------------------------------------*/ 605 606 bool usb_hid_report_ready(void) 607 { 608 return !report_received; 609 } 683 610 684 611 /*----------------------------------------------------------------------------*/ … … 700 627 for (i = 0; i < (*hid_dev)->subdriver_count; ++i) { 701 628 if ((*hid_dev)->subdrivers[i].deinit != NULL) { 702 (*hid_dev)->subdrivers[i].deinit(*hid_dev, 703 (*hid_dev)->subdrivers[i].data); 629 (*hid_dev)->subdrivers[i].deinit(*hid_dev); 704 630 } 705 631 }
Note:
See TracChangeset
for help on using the changeset viewer.