Changeset 9097c16a in mainline for uspace/drv/usbhid/main.c
- Timestamp:
- 2011-02-04T13:14:14Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 9e7cdf8
- Parents:
- 11797d5 (diff), ff244e6 (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 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbhid/main.c
r11797d5 r9097c16a 1 1 /* 2 2 * Copyright (c) 2010 Vojtech Horky 3 * Copyright (c) 2011 Lubos Slovak 3 4 * All rights reserved. 4 5 * … … 26 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 28 */ 29 30 /** @addtogroup drvusbhid 31 * @{ 32 */ 33 /** 34 * @file 35 * Main routines of USB HID driver. 36 */ 37 28 38 #include <usb/usbdrv.h> 29 39 #include <driver.h> … … 33 43 #include <io/console.h> 34 44 #include <errno.h> 45 #include <str_error.h> 35 46 #include <fibril.h> 36 47 #include <usb/classes/hid.h> … … 39 50 #include <usb/descriptor.h> 40 51 #include <io/console.h> 52 #include "hid.h" 41 53 #include "descparser.h" 42 54 #include "descdump.h" … … 45 57 46 58 #define BUFFER_SIZE 32 47 #define NAME "usb kbd"59 #define NAME "usbhid" 48 60 49 61 #define GUESSED_POLL_ENDPOINT 1 … … 369 381 if (rc < 0) { 370 382 printf("Problem setting phone to HC.\n"); 371 free(kbd_dev); 372 return NULL; 383 goto error_leave; 373 384 } 374 385 … … 376 387 if (rc < 0) { 377 388 printf("Problem getting address of the device.\n"); 378 free(kbd_dev); 379 return NULL; 389 goto error_leave; 380 390 } 381 391 … … 387 397 // } 388 398 389 // default endpoint390 kbd_dev->poll_endpoint = GUESSED_POLL_ENDPOINT;391 392 399 /* 393 400 * will need all descriptors: … … 400 407 usbkbd_process_descriptors(kbd_dev); 401 408 409 410 411 /* 412 * Initialize the backing connection to the host controller. 413 */ 414 rc = usb_device_connection_initialize_from_device(&kbd_dev->wire, dev); 415 if (rc != EOK) { 416 printf("Problem initializing connection to device: %s.\n", 417 str_error(rc)); 418 goto error_leave; 419 } 420 421 /* 422 * Initialize device pipes. 423 */ 424 rc = usb_endpoint_pipe_initialize(&kbd_dev->poll_pipe, &kbd_dev->wire, 425 GUESSED_POLL_ENDPOINT, USB_TRANSFER_INTERRUPT, USB_DIRECTION_IN); 426 if (rc != EOK) { 427 printf("Failed to initialize interrupt in pipe: %s.\n", 428 str_error(rc)); 429 goto error_leave; 430 } 431 432 402 433 return kbd_dev; 434 435 error_leave: 436 free(kbd_dev); 437 return NULL; 403 438 } 404 439 … … 413 448 //usb_hid_parse_report(kbd_dev->parser, buffer, actual_size, callbacks, 414 449 // NULL); 415 printf("Calling usb_hid_boot_keyboard_input_report() with size % d\n",450 printf("Calling usb_hid_boot_keyboard_input_report() with size %zu\n", 416 451 actual_size); 417 452 //dump_buffer("bufffer: ", buffer, actual_size); … … 425 460 static void usbkbd_poll_keyboard(usb_hid_dev_kbd_t *kbd_dev) 426 461 { 427 int rc; 428 usb_handle_t handle; 462 int rc, sess_rc; 429 463 uint8_t buffer[BUFFER_SIZE]; 430 464 size_t actual_size; 431 //usb_endpoint_t poll_endpoint = 1;432 433 // usb_address_t my_address = usb_drv_get_my_address(dev->parent_phone,434 // dev);435 // if (my_address < 0) {436 // return;437 // }438 439 usb_target_t poll_target = {440 .address = kbd_dev->address,441 .endpoint = kbd_dev->poll_endpoint442 };443 465 444 466 printf("Polling keyboard...\n"); … … 446 468 while (true) { 447 469 async_usleep(1000 * 1000 * 2); 448 rc = usb_drv_async_interrupt_in(kbd_dev->device->parent_phone, 449 poll_target, buffer, BUFFER_SIZE, &actual_size, &handle); 470 471 sess_rc = usb_endpoint_pipe_start_session(&kbd_dev->poll_pipe); 472 if (sess_rc != EOK) { 473 printf("Failed to start a session: %s.\n", 474 str_error(sess_rc)); 475 continue; 476 } 477 478 rc = usb_endpoint_pipe_read(&kbd_dev->poll_pipe, buffer, 479 BUFFER_SIZE, &actual_size); 480 sess_rc = usb_endpoint_pipe_end_session(&kbd_dev->poll_pipe); 450 481 451 482 if (rc != EOK) { 452 printf("Error in usb_drv_async_interrupt_in(): %d\n", rc); 483 printf("Error polling the keyboard: %s.\n", 484 str_error(rc)); 453 485 continue; 454 486 } 455 487 456 rc = usb_drv_async_wait_for(handle);457 if (rc != EOK) {458 printf("Error in usb_drv_async_wait_for(): %d\n", rc);488 if (sess_rc != EOK) { 489 printf("Error closing session: %s.\n", 490 str_error(sess_rc)); 459 491 continue; 460 492 } … … 557 589 return driver_main(&kbd_driver); 558 590 } 591 592 /** 593 * @} 594 */
Note:
See TracChangeset
for help on using the changeset viewer.