Changeset 92574f4 in mainline for uspace/drv/usbhid/main.c
- Timestamp:
- 2011-02-24T12:03:27Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update
- Children:
- e7b7ebd5
- Parents:
- 4837092 (diff), a80849c (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/main.c
r4837092 r92574f4 36 36 */ 37 37 38 #include <usb/usbdrv.h> 39 #include <driver.h> 38 #include <ddf/driver.h> 40 39 #include <ipc/driver.h> 41 40 #include <ipc/kbd.h> … … 45 44 #include <str_error.h> 46 45 #include <fibril.h> 46 #include <usb/debug.h> 47 #include <usb/classes/classes.h> 47 48 #include <usb/classes/hid.h> 48 49 #include <usb/classes/hidparser.h> 49 #include <usb/ devreq.h>50 #include <usb/request.h> 50 51 #include <usb/descriptor.h> 51 #include <usb/debug.h>52 52 #include <io/console.h> 53 53 #include <stdint.h> … … 58 58 #include "layout.h" 59 59 60 #define BUFFER_SIZE 3260 #define BUFFER_SIZE 8 61 61 #define NAME "usbhid" 62 62 … … 64 64 #define BOOTP_REPORT_SIZE 6 65 65 66 static void default_connection_handler(device_t *, ipc_callid_t, ipc_call_t *); 67 static device_ops_t keyboard_ops = { 66 /** Keyboard polling endpoint description for boot protocol class. */ 67 static usb_endpoint_description_t poll_endpoint_description = { 68 .transfer_type = USB_TRANSFER_INTERRUPT, 69 .direction = USB_DIRECTION_IN, 70 .interface_class = USB_CLASS_HID, 71 .interface_subclass = USB_HID_SUBCLASS_BOOT, 72 .interface_protocol = USB_HID_PROTOCOL_KEYBOARD, 73 .flags = 0 74 }; 75 76 static void default_connection_handler(ddf_fun_t *, ipc_callid_t, ipc_call_t *); 77 static ddf_dev_ops_t keyboard_ops = { 68 78 .default_handler = default_connection_handler 69 79 }; … … 77 87 * @param icall Call data. 78 88 */ 79 void default_connection_handler(d evice_t *dev,89 void default_connection_handler(ddf_fun_t *fun, 80 90 ipc_callid_t icallid, ipc_call_t *icall) 81 91 { … … 86 96 87 97 if (console_callback_phone != -1) { 88 ipc_answer_0(icallid, ELIMIT);98 async_answer_0(icallid, ELIMIT); 89 99 return; 90 100 } 91 101 92 102 console_callback_phone = callback; 93 ipc_answer_0(icallid, EOK);103 async_answer_0(icallid, EOK); 94 104 return; 95 105 } 96 106 97 ipc_answer_0(icallid, EINVAL);107 async_answer_0(icallid, EINVAL); 98 108 } 99 109 … … 387 397 388 398 // get the descriptor from the device 389 int rc = usb_ drv_req_get_descriptor(390 kbd_dev->device->parent_phone, kbd_dev->address,391 USB_REQUEST_TYPE_CLASS, USB_DESCTYPE_HID_REPORT,392 0, i, kbd_dev->conf->interfaces[i].report_desc, length,399 int rc = usb_request_get_descriptor(&kbd_dev->ctrl_pipe, 400 USB_REQUEST_TYPE_CLASS, USB_DESCTYPE_HID_REPORT, 401 i, 0, 402 kbd_dev->conf->interfaces[i].report_desc, length, 393 403 &actual_size); 394 404 … … 411 421 usb_standard_configuration_descriptor_t config_desc; 412 422 413 int rc = usb_drv_req_get_bare_configuration_descriptor( 414 kbd_dev->device->parent_phone, kbd_dev->address, 0, &config_desc); 423 int rc; 424 rc = usb_request_get_bare_configuration_descriptor(&kbd_dev->ctrl_pipe, 425 0, &config_desc); 415 426 416 427 if (rc != EOK) { … … 426 437 size_t transferred = 0; 427 438 // get full configuration descriptor 428 rc = usb_ drv_req_get_full_configuration_descriptor(429 kbd_dev->device->parent_phone, kbd_dev->address,0, descriptors,439 rc = usb_request_get_full_configuration_descriptor(&kbd_dev->ctrl_pipe, 440 0, descriptors, 430 441 config_desc.total_length, &transferred); 431 442 … … 437 448 } 438 449 450 /* 451 * Initialize the interrupt in endpoint. 452 */ 453 usb_endpoint_mapping_t endpoint_mapping[1] = { 454 { 455 .pipe = &kbd_dev->poll_pipe, 456 .description = &poll_endpoint_description, 457 .interface_no = 458 usb_device_get_assigned_interface(kbd_dev->device) 459 } 460 }; 461 rc = usb_endpoint_pipe_initialize_from_configuration( 462 endpoint_mapping, 1, 463 descriptors, config_desc.total_length, 464 &kbd_dev->wire); 465 if (rc != EOK) { 466 usb_log_error("Failed to initialize poll pipe: %s.\n", 467 str_error(rc)); 468 return rc; 469 } 470 if (!endpoint_mapping[0].present) { 471 usb_log_warning("Not accepting device, " \ 472 "not boot-protocol keyboard.\n"); 473 return EREFUSED; 474 } 475 476 477 478 439 479 kbd_dev->conf = (usb_hid_configuration_t *)calloc(1, 440 480 sizeof(usb_hid_configuration_t)); … … 444 484 } 445 485 446 rc = usbkbd_parse_descriptors(descriptors, transferred, kbd_dev->conf);486 /*rc = usbkbd_parse_descriptors(descriptors, transferred, kbd_dev->conf); 447 487 free(descriptors); 448 488 if (rc != EOK) { … … 451 491 } 452 492 453 // get and report descriptors 493 // get and report descriptors*/ 454 494 rc = usbkbd_get_report_descriptor(kbd_dev); 455 495 if (rc != EOK) { … … 469 509 * as the endpoint for polling 470 510 */ 471 511 472 512 return EOK; 473 513 } 474 514 475 static usb_hid_dev_kbd_t *usbkbd_init_device(device_t *dev) 476 { 515 static usb_hid_dev_kbd_t *usbkbd_init_device(ddf_dev_t *dev) 516 { 517 int rc; 518 477 519 usb_hid_dev_kbd_t *kbd_dev = (usb_hid_dev_kbd_t *)calloc(1, 478 520 sizeof(usb_hid_dev_kbd_t)); … … 485 527 kbd_dev->device = dev; 486 528 487 // get phone to my HC and save it as my parent's phone 488 // TODO: maybe not a good idea if DDF will use parent_phone 489 int rc = kbd_dev->device->parent_phone = usb_drv_hc_connect_auto(dev, 0); 490 if (rc < 0) { 491 usb_log_error("Problem setting phone to HC.\n"); 529 /* 530 * Initialize the backing connection to the host controller. 531 */ 532 rc = usb_device_connection_initialize_from_device(&kbd_dev->wire, dev); 533 if (rc != EOK) { 534 printf("Problem initializing connection to device: %s.\n", 535 str_error(rc)); 492 536 goto error_leave; 493 537 } 494 538 495 rc = kbd_dev->address = usb_drv_get_my_address(dev->parent_phone, dev); 496 if (rc < 0) { 497 usb_log_error("Problem getting address of the device.\n"); 539 /* 540 * Initialize device pipes. 541 */ 542 rc = usb_endpoint_pipe_initialize_default_control(&kbd_dev->ctrl_pipe, 543 &kbd_dev->wire); 544 if (rc != EOK) { 545 printf("Failed to initialize default control pipe: %s.\n", 546 str_error(rc)); 498 547 goto error_leave; 499 548 } 500 549 501 // doesn't matter now that we have no address502 // if (kbd_dev->address < 0) {503 // usb_log_error("No device address!\n");504 // free(kbd_dev);505 // return NULL;506 // }507 508 550 /* 509 551 * will need all descriptors: 510 * 1) choose one configuration from configuration descriptors 552 * 1) choose one configuration from configuration descriptors 511 553 * (set it to the device) 512 554 * 2) set endpoints from endpoint descriptors 513 555 */ 514 556 515 usbkbd_process_descriptors(kbd_dev); 516 517 // save the size of the report 518 kbd_dev->keycode_count = BOOTP_REPORT_SIZE; 519 kbd_dev->keycodes = (uint8_t *)calloc( 520 kbd_dev->keycode_count, sizeof(uint8_t)); 521 522 if (kbd_dev->keycodes == NULL) { 523 usb_log_fatal("No memory!\n"); 557 // TODO: get descriptors, parse descriptors and save endpoints 558 usb_endpoint_pipe_start_session(&kbd_dev->ctrl_pipe); 559 //usb_request_set_configuration(&kbd_dev->ctrl_pipe, 1); 560 rc = usbkbd_process_descriptors(kbd_dev); 561 usb_endpoint_pipe_end_session(&kbd_dev->ctrl_pipe); 562 if (rc != EOK) { 524 563 goto error_leave; 525 564 } 526 527 // set configuration to the first one528 // TODO: handle case with no configurations529 usb_drv_req_set_configuration(kbd_dev->device->parent_phone,530 kbd_dev->address,531 kbd_dev->conf->config_descriptor.configuration_number);532 533 /*534 * Initialize the backing connection to the host controller.535 */536 rc = usb_device_connection_initialize_from_device(&kbd_dev->wire, dev);537 if (rc != EOK) {538 usb_log_error("Problem initializing connection to device: %s."539 "\n", str_error(rc));540 goto error_leave;541 }542 543 /*544 * Initialize device pipes.545 */546 rc = usb_endpoint_pipe_initialize(&kbd_dev->poll_pipe, &kbd_dev->wire,547 GUESSED_POLL_ENDPOINT, USB_TRANSFER_INTERRUPT, USB_DIRECTION_IN);548 if (rc != EOK) {549 usb_log_error("Failed to initialize interrupt in pipe: %s.\n",550 str_error(rc));551 goto error_leave;552 }553 554 565 555 566 return kbd_dev; … … 591 602 592 603 while (true) { 593 async_usleep(1000 * 10 00 * 2);604 async_usleep(1000 * 10); 594 605 595 606 sess_rc = usb_endpoint_pipe_start_session(&kbd_dev->poll_pipe); … … 643 654 } 644 655 645 d evice_t *dev = (device_t *)arg;656 ddf_dev_t *dev = (ddf_dev_t *)arg; 646 657 647 658 // initialize device (get and process descriptors, get address, etc.) … … 657 668 } 658 669 659 static int usbkbd_add_device(d evice_t *dev)670 static int usbkbd_add_device(ddf_dev_t *dev) 660 671 { 661 672 /* For now, fail immediately. */ … … 679 690 680 691 /* 692 * Create default function. 693 */ 694 // FIXME - check for errors 695 ddf_fun_t *kbd_fun = ddf_fun_create(dev, fun_exposed, "keyboard"); 696 assert(kbd_fun != NULL); 697 kbd_fun->ops = &keyboard_ops; 698 699 int rc = ddf_fun_bind(kbd_fun); 700 assert(rc == EOK); 701 rc = ddf_fun_add_to_class(kbd_fun, "keyboard"); 702 assert(rc == EOK); 703 704 /* 681 705 * Create new fibril for handling this keyboard 682 706 */ … … 688 712 fibril_add_ready(fid); 689 713 690 dev->ops = &keyboard_ops; 691 692 add_device_to_class(dev, "keyboard"); 714 //dev->ops = &keyboard_ops; 715 (void)keyboard_ops; 716 717 //add_device_to_class(dev, "keyboard"); 693 718 694 719 /* … … 710 735 { 711 736 usb_log_enable(USB_LOG_LEVEL_MAX, NAME); 712 return d river_main(&kbd_driver);737 return ddf_driver_main(&kbd_driver); 713 738 } 714 739
Note:
See TracChangeset
for help on using the changeset viewer.