Changes in uspace/drv/usbhid/usbhid.c [fa8d346:faa44e58] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbhid/usbhid.c
rfa8d346 rfaa44e58 203 203 204 204 usb_log_debug("Compare flags: %d\n", mapping->compare); 205 // size_t size = usb_hid_report_size(hid_dev->report, 0, 206 // USB_HID_REPORT_TYPE_INPUT); 207 size_t size = 0; 208 usb_hid_report_field_t *field = usb_hid_report_get_sibling (hid_dev->report, 209 NULL, usage_path, mapping->compare, USB_HID_REPORT_TYPE_INPUT); 210 while(field != NULL) { 211 size++; 212 field = usb_hid_report_get_sibling (hid_dev->report, 213 field, usage_path, mapping->compare, 214 USB_HID_REPORT_TYPE_INPUT); 215 } 216 205 size_t size = usb_hid_report_input_length(hid_dev->report, usage_path, 206 mapping->compare); 217 207 usb_log_debug("Size of the input report: %zuB\n", size); 208 218 209 usb_hid_report_path_free(usage_path); 219 210 … … 234 225 } 235 226 236 // add one generic HID subdriver per device 237 238 hid_dev->subdrivers = (usb_hid_subdriver_t *)malloc((count + 1) * 227 hid_dev->subdrivers = (usb_hid_subdriver_t *)malloc(count * 239 228 sizeof(usb_hid_subdriver_t)); 240 229 if (hid_dev->subdrivers == NULL) { … … 249 238 } 250 239 251 hid_dev->subdrivers[count].init = usb_generic_hid_init; 252 hid_dev->subdrivers[count].poll = usb_generic_hid_polling_callback; 253 hid_dev->subdrivers[count].deinit = NULL; 254 hid_dev->subdrivers[count].poll_end = NULL; 255 256 hid_dev->subdriver_count = count + 1; 240 hid_dev->subdriver_count = count; 257 241 258 242 return EOK; … … 314 298 315 299 if (matched) { 316 usb_log_debug("Subdriver matched.\n");317 300 subdrivers[count++] = &mapping->subdriver; 318 301 } … … 356 339 /*----------------------------------------------------------------------------*/ 357 340 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;387 }388 389 /*----------------------------------------------------------------------------*/390 391 341 usb_hid_dev_t *usb_hid_new(void) 392 342 { … … 443 393 /* Get the report descriptor and parse it. */ 444 394 rc = usb_hid_process_report_descriptor(hid_dev->usb_dev, 445 hid_dev->report , &hid_dev->report_desc, &hid_dev->report_desc_size);395 hid_dev->report); 446 396 447 397 bool fallback = false; … … 507 457 if (hid_dev->subdrivers[i].init != NULL) { 508 458 usb_log_debug("Initializing subdriver %d.\n",i); 509 rc = hid_dev->subdrivers[i].init(hid_dev, 510 &hid_dev->subdrivers[i].data); 459 rc = hid_dev->subdrivers[i].init(hid_dev); 511 460 if (rc != EOK) { 512 461 usb_log_warning("Failed to initialize" … … 524 473 } 525 474 526 // save max input report size and allocate space for the report527 rc = usb_hid_init_report(hid_dev);528 if (rc != EOK) {529 usb_log_error("Failed to initialize input report buffer.\n");530 }531 532 475 return rc; 533 476 } … … 547 490 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)arg; 548 491 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 // } 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 } 573 514 574 515 /*! @todo This should probably be atomic. */ 575 516 memcpy(hid_dev->input_report, buffer, buffer_size); 576 517 hid_dev->input_report_size = buffer_size; 577 usb_hid_new_report();578 518 579 519 bool cont = false; … … 582 522 for (i = 0; i < hid_dev->subdriver_count; ++i) { 583 523 if (hid_dev->subdrivers[i].poll != NULL 584 && hid_dev->subdrivers[i].poll(hid_dev, 585 hid_dev->subdrivers[i].data, buffer,buffer_size)) {524 && hid_dev->subdrivers[i].poll(hid_dev, buffer, 525 buffer_size)) { 586 526 cont = true; 587 527 } … … 606 546 for (i = 0; i < hid_dev->subdriver_count; ++i) { 607 547 if (hid_dev->subdrivers[i].poll_end != NULL) { 608 hid_dev->subdrivers[i].poll_end(hid_dev, 609 hid_dev->subdrivers[i].data, reason); 548 hid_dev->subdrivers[i].poll_end(hid_dev, reason); 610 549 } 611 550 } … … 688 627 for (i = 0; i < (*hid_dev)->subdriver_count; ++i) { 689 628 if ((*hid_dev)->subdrivers[i].deinit != NULL) { 690 (*hid_dev)->subdrivers[i].deinit(*hid_dev, 691 (*hid_dev)->subdrivers[i].data); 629 (*hid_dev)->subdrivers[i].deinit(*hid_dev); 692 630 } 693 631 }
Note:
See TracChangeset
for help on using the changeset viewer.