Changeset cd83f25 in mainline for uspace/drv/usbhid/usbhid.c
- Timestamp:
- 2011-05-27T09:58:08Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- e89bb50
- Parents:
- 63d4d4fd (diff), 848dafc (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbhid/usbhid.c
r63d4d4fd rcd83f25 63 63 static const int USB_HID_MAX_SUBDRIVERS = 10; 64 64 65 static fibril_local bool report_received; 65 /** @todo What happens if this is not fibril local? */ 66 //static fibril_local bool report_number; 66 67 67 68 /*----------------------------------------------------------------------------*/ … … 234 235 } 235 236 236 hid_dev->subdrivers = (usb_hid_subdriver_t *)malloc(count * 237 // add one generic HID subdriver per device 238 239 hid_dev->subdrivers = (usb_hid_subdriver_t *)malloc((count + 1) * 237 240 sizeof(usb_hid_subdriver_t)); 238 241 if (hid_dev->subdrivers == NULL) { … … 247 250 } 248 251 249 hid_dev->subdriver_count = count; 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; 250 258 251 259 return EOK; … … 307 315 308 316 if (matched) { 317 usb_log_debug("Subdriver matched.\n"); 309 318 subdrivers[count++] = &mapping->subdriver; 310 319 } … … 348 357 /*----------------------------------------------------------------------------*/ 349 358 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 350 394 usb_hid_dev_t *usb_hid_new(void) 351 395 { … … 402 446 /* Get the report descriptor and parse it. */ 403 447 rc = usb_hid_process_report_descriptor(hid_dev->usb_dev, 404 hid_dev->report );448 hid_dev->report, &hid_dev->report_desc, &hid_dev->report_desc_size); 405 449 406 450 bool fallback = false; … … 483 527 } 484 528 529 // save max input report size and allocate space for the report 530 rc = usb_hid_init_report(hid_dev); 531 if (rc != EOK) { 532 usb_log_error("Failed to initialize input report buffer.\n"); 533 } 534 485 535 return rc; 486 536 } … … 500 550 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)arg; 501 551 502 int allocated = (hid_dev->input_report != NULL); 503 504 if (!allocated 505 || hid_dev->input_report_size < buffer_size) { 506 uint8_t *input_old = hid_dev->input_report; 507 uint8_t *input_new = (uint8_t *)malloc(buffer_size); 508 509 if (input_new == NULL) { 510 usb_log_error("Failed to allocate space for input " 511 "buffer. This event may not be reported\n"); 512 memset(hid_dev->input_report, 0, 513 hid_dev->input_report_size); 514 } else { 515 memcpy(input_new, input_old, 516 hid_dev->input_report_size); 517 hid_dev->input_report = input_new; 518 if (allocated) { 519 free(input_old); 520 } 521 usb_hid_new_report(); 522 } 523 } 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 // } 524 578 525 579 /*! @todo This should probably be atomic. */ 526 580 memcpy(hid_dev->input_report, buffer, buffer_size); 527 581 hid_dev->input_report_size = buffer_size; 582 usb_hid_new_report(hid_dev); 528 583 529 584 bool cont = false; … … 601 656 /*----------------------------------------------------------------------------*/ 602 657 603 void usb_hid_new_report(void) 604 { 605 report_received = false; 606 } 607 608 /*----------------------------------------------------------------------------*/ 609 610 void usb_hid_report_received(void) 611 { 612 report_received = true; 613 } 614 615 /*----------------------------------------------------------------------------*/ 616 617 bool usb_hid_report_ready(void) 618 { 619 return !report_received; 620 } 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 //} 621 683 622 684 /*----------------------------------------------------------------------------*/
Note:
See TracChangeset
for help on using the changeset viewer.