Changeset 17c1d9db in mainline
- Timestamp:
- 2018-01-14T21:25:16Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 01d9707
- Parents:
- 8b71f3e
- Location:
- uspace/drv/hid/usbhid
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/hid/usbhid/usbhid.c
r8b71f3e r17c1d9db 325 325 } 326 326 327 static bool usb_hid_polling_callback(usb_device_t *dev, uint8_t *buffer, 328 size_t buffer_size, void *arg) 329 { 330 if (dev == NULL || arg == NULL || buffer == NULL) { 331 usb_log_error("Missing arguments to polling callback.\n"); 332 return false; 333 } 334 usb_hid_dev_t *hid_dev = arg; 335 336 assert(hid_dev->input_report != NULL); 337 338 usb_log_debug("New data [%zu/%zu]: %s\n", buffer_size, 339 hid_dev->max_input_report_size, 340 usb_debug_str_buffer(buffer, buffer_size, 0)); 341 342 if (hid_dev->max_input_report_size >= buffer_size) { 343 /*! @todo This should probably be atomic. */ 344 memcpy(hid_dev->input_report, buffer, buffer_size); 345 hid_dev->input_report_size = buffer_size; 346 usb_hid_new_report(hid_dev); 347 } 348 349 /* Parse the input report */ 350 const int rc = usb_hid_parse_report( 351 &hid_dev->report, buffer, buffer_size, &hid_dev->report_id); 352 if (rc != EOK) { 353 usb_log_warning("Failure in usb_hid_parse_report():" 354 "%s\n", str_error(rc)); 355 } 356 357 bool cont = false; 358 /* Continue if at least one of the subdrivers want to continue */ 359 for (unsigned i = 0; i < hid_dev->subdriver_count; ++i) { 360 if (hid_dev->subdrivers[i].poll != NULL) { 361 cont = cont || hid_dev->subdrivers[i].poll( 362 hid_dev, hid_dev->subdrivers[i].data); 363 } 364 } 365 366 return cont; 367 } 368 369 static bool usb_hid_polling_error_callback(usb_device_t *dev, int err_code, void *arg) 370 { 371 assert(dev); 372 assert(arg); 373 usb_hid_dev_t *hid_dev = arg; 374 375 usb_log_error("Device %s polling error: %s", usb_device_get_name(dev), 376 str_error(err_code)); 377 378 /* Continue polling until the device is about to be removed. */ 379 return hid_dev->running; 380 } 381 382 static void usb_hid_polling_ended_callback(usb_device_t *dev, bool reason, void *arg) 383 { 384 assert(dev); 385 assert(arg); 386 387 usb_hid_dev_t *hid_dev = arg; 388 389 for (unsigned i = 0; i < hid_dev->subdriver_count; ++i) { 390 if (hid_dev->subdrivers[i].poll_end != NULL) { 391 hid_dev->subdrivers[i].poll_end( 392 hid_dev, hid_dev->subdrivers[i].data, reason); 393 } 394 } 395 396 hid_dev->running = false; 397 } 398 327 399 /* 328 400 * This functions initializes required structures from the device's descriptors … … 464 536 } 465 537 466 bool usb_hid_polling_callback(usb_device_t *dev, uint8_t *buffer,467 size_t buffer_size, void *arg)468 {469 if (dev == NULL || arg == NULL || buffer == NULL) {470 usb_log_error("Missing arguments to polling callback.\n");471 return false;472 }473 usb_hid_dev_t *hid_dev = arg;474 475 assert(hid_dev->input_report != NULL);476 477 usb_log_debug("New data [%zu/%zu]: %s\n", buffer_size,478 hid_dev->max_input_report_size,479 usb_debug_str_buffer(buffer, buffer_size, 0));480 481 if (hid_dev->max_input_report_size >= buffer_size) {482 /*! @todo This should probably be atomic. */483 memcpy(hid_dev->input_report, buffer, buffer_size);484 hid_dev->input_report_size = buffer_size;485 usb_hid_new_report(hid_dev);486 }487 488 /* Parse the input report */489 const int rc = usb_hid_parse_report(490 &hid_dev->report, buffer, buffer_size, &hid_dev->report_id);491 if (rc != EOK) {492 usb_log_warning("Failure in usb_hid_parse_report():"493 "%s\n", str_error(rc));494 }495 496 bool cont = false;497 /* Continue if at least one of the subdrivers want to continue */498 for (unsigned i = 0; i < hid_dev->subdriver_count; ++i) {499 if (hid_dev->subdrivers[i].poll != NULL) {500 cont = cont || hid_dev->subdrivers[i].poll(501 hid_dev, hid_dev->subdrivers[i].data);502 }503 }504 505 return cont;506 }507 508 bool usb_hid_polling_error_callback(usb_device_t *dev, int err_code, void *arg)509 {510 assert(dev);511 assert(arg);512 usb_hid_dev_t *hid_dev = arg;513 514 usb_log_error("Device %s polling error: %s", usb_device_get_name(dev),515 str_error(err_code));516 517 /* Continue polling until the device is about to be removed. */518 return hid_dev->running;519 }520 521 void usb_hid_polling_ended_callback(usb_device_t *dev, bool reason, void *arg)522 {523 assert(dev);524 assert(arg);525 526 usb_hid_dev_t *hid_dev = arg;527 528 for (unsigned i = 0; i < hid_dev->subdriver_count; ++i) {529 if (hid_dev->subdrivers[i].poll_end != NULL) {530 hid_dev->subdrivers[i].poll_end(531 hid_dev, hid_dev->subdrivers[i].data, reason);532 }533 }534 535 hid_dev->running = false;536 }537 538 538 void usb_hid_new_report(usb_hid_dev_t *hid_dev) 539 539 { -
uspace/drv/hid/usbhid/usbhid.h
r8b71f3e r17c1d9db 142 142 void usb_hid_deinit(usb_hid_dev_t *hid_dev); 143 143 144 bool usb_hid_polling_callback(usb_device_t *dev,145 uint8_t *buffer, size_t buffer_size, void *arg);146 147 bool usb_hid_polling_error_callback(usb_device_t *dev, int err_code, void *arg);148 149 void usb_hid_polling_ended_callback(usb_device_t *dev, bool reason, void *arg);150 151 144 void usb_hid_new_report(usb_hid_dev_t *hid_dev); 152 145
Note:
See TracChangeset
for help on using the changeset viewer.