Changeset d1fb591 in mainline
- Timestamp:
- 2011-05-20T10:24:12Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- e765ccb
- Parents:
- 4939490
- Location:
- uspace/drv/usbhid
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbhid/usbhid.c
r4939490 rd1fb591 314 314 315 315 if (matched) { 316 usb_log_debug("Subdriver matched.\n"); 316 317 subdrivers[count++] = &mapping->subdriver; 317 318 } … … 351 352 352 353 return rc; 354 } 355 356 /*----------------------------------------------------------------------------*/ 357 358 static int usb_hid_init_report(usb_hid_dev_t *hid_dev) 359 { 360 assert(hid_dev != NULL && hid_dev->report != NULL); 361 362 uint8_t report_id = 0; 363 size_t size = usb_hid_report_size(hid_dev->report, report_id, 364 USB_HID_REPORT_TYPE_INPUT); 365 366 size_t max_size = 0; 367 368 while (size > 0) { 369 max_size = (size > max_size) ? size : max_size; 370 size = usb_hid_report_size(hid_dev->report, report_id, 371 USB_HID_REPORT_TYPE_INPUT); 372 ++report_id; 373 } 374 375 usb_log_debug("Max size of input report: %zu\n", max_size); 376 377 hid_dev->max_input_report_size = max_size; 378 assert(hid_dev->input_report == NULL); 379 380 hid_dev->input_report = malloc(max_size); 381 if (hid_dev->input_report == NULL) { 382 return ENOMEM; 383 } 384 memset(hid_dev->input_report, 0, max_size); 385 386 return EOK; 353 387 } 354 388 … … 490 524 } 491 525 526 // save max input report size and allocate space for the report 527 rc = usb_hid_init_report(hid_dev); 528 if (rc != EOK) { 529 usb_log_error("Failed to initialize input report buffer.\n"); 530 } 531 492 532 return rc; 493 533 } … … 507 547 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)arg; 508 548 509 int allocated = (hid_dev->input_report != NULL); 510 511 if (!allocated 512 || hid_dev->input_report_size < buffer_size) { 513 uint8_t *input_old = hid_dev->input_report; 514 uint8_t *input_new = (uint8_t *)malloc(buffer_size); 515 516 if (input_new == NULL) { 517 usb_log_error("Failed to allocate space for input " 518 "buffer. This event may not be reported\n"); 519 memset(hid_dev->input_report, 0, 520 hid_dev->input_report_size); 521 } else { 522 memcpy(input_new, input_old, 523 hid_dev->input_report_size); 524 hid_dev->input_report = input_new; 525 if (allocated) { 526 free(input_old); 527 } 528 usb_hid_new_report(); 529 } 530 } 549 // int allocated = (hid_dev->input_report != NULL); 550 assert(hid_dev->input_report != NULL); 551 assert(hid_dev->max_input_report_size >= buffer_size); 552 553 // if (/*!allocated*/ 554 // /*|| *//*hid_dev->input_report_size < buffer_size*/) { 555 // uint8_t *input_old = hid_dev->input_report; 556 // uint8_t *input_new = (uint8_t *)malloc(buffer_size); 557 558 // if (input_new == NULL) { 559 // usb_log_error("Failed to allocate space for input " 560 // "buffer. This event may not be reported\n"); 561 // memset(hid_dev->input_report, 0, 562 // hid_dev->input_report_size); 563 // } else { 564 // memcpy(input_new, input_old, 565 // hid_dev->input_report_size); 566 // hid_dev->input_report = input_new; 567 // if (allocated) { 568 // free(input_old); 569 // } 570 // usb_hid_new_report(); 571 // } 572 // } 531 573 532 574 /*! @todo This should probably be atomic. */ 533 575 memcpy(hid_dev->input_report, buffer, buffer_size); 534 576 hid_dev->input_report_size = buffer_size; 577 usb_hid_new_report(); 535 578 536 579 bool cont = false; -
uspace/drv/usbhid/usbhid.h
r4939490 rd1fb591 98 98 99 99 size_t input_report_size; 100 size_t max_input_report_size; 100 101 } usb_hid_dev_t; 101 102
Note:
See TracChangeset
for help on using the changeset viewer.