Changes in uspace/drv/usbhid/main.c [66d5062:0484d92] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbhid/main.c
r66d5062 r0484d92 43 43 #include <io/console.h> 44 44 #include <errno.h> 45 #include <str_error.h> 45 46 #include <fibril.h> 46 47 #include <usb/classes/hid.h> 47 48 #include <usb/classes/hidparser.h> 48 #include <usb/ devreq.h>49 #include <usb/request.h> 49 50 #include <usb/descriptor.h> 50 51 #include <io/console.h> 52 #include "hid.h" 51 53 #include "descparser.h" 52 54 #include "descdump.h" … … 278 280 279 281 // get the descriptor from the device 280 int rc = usb_drv_req_get_descriptor(kbd_dev->device->parent_phone, 281 kbd_dev->address, USB_REQUEST_TYPE_CLASS, USB_DESCTYPE_HID_REPORT, 282 0, i, kbd_dev->conf->interfaces[i].report_desc, length, 282 int rc = usb_request_get_descriptor(&kbd_dev->ctrl_pipe, 283 USB_REQUEST_TYPE_CLASS, USB_DESCTYPE_HID_REPORT, 284 i, 0, 285 kbd_dev->conf->interfaces[i].report_desc, length, 283 286 &actual_size); 284 287 … … 301 304 usb_standard_configuration_descriptor_t config_desc; 302 305 303 int rc = usb_drv_req_get_bare_configuration_descriptor( 304 kbd_dev->device->parent_phone, kbd_dev->address, 0, &config_desc); 306 int rc; 307 rc = usb_request_get_bare_configuration_descriptor(&kbd_dev->ctrl_pipe, 308 0, &config_desc); 305 309 306 310 if (rc != EOK) { … … 316 320 size_t transferred = 0; 317 321 // get full configuration descriptor 318 rc = usb_ drv_req_get_full_configuration_descriptor(319 kbd_dev->device->parent_phone, kbd_dev->address,0, descriptors,322 rc = usb_request_get_full_configuration_descriptor(&kbd_dev->ctrl_pipe, 323 0, descriptors, 320 324 config_desc.total_length, &transferred); 321 325 … … 364 368 static usb_hid_dev_kbd_t *usbkbd_init_device(device_t *dev) 365 369 { 370 int rc; 371 366 372 usb_hid_dev_kbd_t *kbd_dev = (usb_hid_dev_kbd_t *)calloc(1, 367 373 sizeof(usb_hid_dev_kbd_t)); … … 374 380 kbd_dev->device = dev; 375 381 376 // get phone to my HC and save it as my parent's phone 377 // TODO: maybe not a good idea if DDF will use parent_phone 378 int rc = kbd_dev->device->parent_phone = usb_drv_hc_connect_auto(dev, 0); 379 if (rc < 0) { 380 printf("Problem setting phone to HC.\n"); 381 free(kbd_dev); 382 return NULL; 383 } 384 385 rc = kbd_dev->address = usb_drv_get_my_address(dev->parent_phone, dev); 386 if (rc < 0) { 387 printf("Problem getting address of the device.\n"); 388 free(kbd_dev); 389 return NULL; 390 } 391 392 // doesn't matter now that we have no address 393 // if (kbd_dev->address < 0) { 394 // fprintf(stderr, NAME ": No device address!\n"); 395 // free(kbd_dev); 396 // return NULL; 397 // } 398 399 // default endpoint 400 kbd_dev->poll_endpoint = GUESSED_POLL_ENDPOINT; 401 382 /* 383 * Initialize the backing connection to the host controller. 384 */ 385 rc = usb_device_connection_initialize_from_device(&kbd_dev->wire, dev); 386 if (rc != EOK) { 387 printf("Problem initializing connection to device: %s.\n", 388 str_error(rc)); 389 goto error_leave; 390 } 391 392 /* 393 * Initialize device pipes. 394 */ 395 rc = usb_endpoint_pipe_initialize_default_control(&kbd_dev->ctrl_pipe, 396 &kbd_dev->wire); 397 if (rc != EOK) { 398 printf("Failed to initialize default control pipe: %s.\n", 399 str_error(rc)); 400 goto error_leave; 401 } 402 403 rc = usb_endpoint_pipe_initialize(&kbd_dev->poll_pipe, &kbd_dev->wire, 404 GUESSED_POLL_ENDPOINT, USB_TRANSFER_INTERRUPT, USB_DIRECTION_IN); 405 if (rc != EOK) { 406 printf("Failed to initialize interrupt in pipe: %s.\n", 407 str_error(rc)); 408 goto error_leave; 409 } 410 402 411 /* 403 412 * will need all descriptors: 404 * 1) choose one configuration from configuration descriptors 413 * 1) choose one configuration from configuration descriptors 405 414 * (set it to the device) 406 415 * 2) set endpoints from endpoint descriptors … … 408 417 409 418 // TODO: get descriptors, parse descriptors and save endpoints 419 usb_endpoint_pipe_start_session(&kbd_dev->ctrl_pipe); 410 420 usbkbd_process_descriptors(kbd_dev); 421 usb_endpoint_pipe_end_session(&kbd_dev->ctrl_pipe); 411 422 412 423 return kbd_dev; 424 425 error_leave: 426 free(kbd_dev); 427 return NULL; 413 428 } 414 429 … … 435 450 static void usbkbd_poll_keyboard(usb_hid_dev_kbd_t *kbd_dev) 436 451 { 437 int rc; 438 usb_handle_t handle; 452 int rc, sess_rc; 439 453 uint8_t buffer[BUFFER_SIZE]; 440 454 size_t actual_size; 441 //usb_endpoint_t poll_endpoint = 1;442 443 // usb_address_t my_address = usb_drv_get_my_address(dev->parent_phone,444 // dev);445 // if (my_address < 0) {446 // return;447 // }448 449 usb_target_t poll_target = {450 .address = kbd_dev->address,451 .endpoint = kbd_dev->poll_endpoint452 };453 455 454 456 printf("Polling keyboard...\n"); … … 456 458 while (true) { 457 459 async_usleep(1000 * 1000 * 2); 458 rc = usb_drv_async_interrupt_in(kbd_dev->device->parent_phone, 459 poll_target, buffer, BUFFER_SIZE, &actual_size, &handle); 460 461 sess_rc = usb_endpoint_pipe_start_session(&kbd_dev->poll_pipe); 462 if (sess_rc != EOK) { 463 printf("Failed to start a session: %s.\n", 464 str_error(sess_rc)); 465 continue; 466 } 467 468 rc = usb_endpoint_pipe_read(&kbd_dev->poll_pipe, buffer, 469 BUFFER_SIZE, &actual_size); 470 sess_rc = usb_endpoint_pipe_end_session(&kbd_dev->poll_pipe); 460 471 461 472 if (rc != EOK) { 462 printf("Error in usb_drv_async_interrupt_in(): %d\n", rc); 473 printf("Error polling the keyboard: %s.\n", 474 str_error(rc)); 463 475 continue; 464 476 } 465 477 466 rc = usb_drv_async_wait_for(handle);467 if (rc != EOK) {468 printf("Error in usb_drv_async_wait_for(): %d\n", rc);478 if (sess_rc != EOK) { 479 printf("Error closing session: %s.\n", 480 str_error(sess_rc)); 469 481 continue; 470 482 }
Note:
See TracChangeset
for help on using the changeset viewer.