Changes in uspace/drv/usbhid/main.c [0484d92:66d5062] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbhid/main.c
r0484d92 r66d5062 43 43 #include <io/console.h> 44 44 #include <errno.h> 45 #include <str_error.h>46 45 #include <fibril.h> 47 46 #include <usb/classes/hid.h> 48 47 #include <usb/classes/hidparser.h> 49 #include <usb/ request.h>48 #include <usb/devreq.h> 50 49 #include <usb/descriptor.h> 51 50 #include <io/console.h> 52 #include "hid.h"53 51 #include "descparser.h" 54 52 #include "descdump.h" … … 280 278 281 279 // get the descriptor from the device 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, 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, 286 283 &actual_size); 287 284 … … 304 301 usb_standard_configuration_descriptor_t config_desc; 305 302 306 int rc; 307 rc = usb_request_get_bare_configuration_descriptor(&kbd_dev->ctrl_pipe, 308 0, &config_desc); 303 int rc = usb_drv_req_get_bare_configuration_descriptor( 304 kbd_dev->device->parent_phone, kbd_dev->address, 0, &config_desc); 309 305 310 306 if (rc != EOK) { … … 320 316 size_t transferred = 0; 321 317 // get full configuration descriptor 322 rc = usb_ request_get_full_configuration_descriptor(&kbd_dev->ctrl_pipe,323 0, descriptors,318 rc = usb_drv_req_get_full_configuration_descriptor( 319 kbd_dev->device->parent_phone, kbd_dev->address, 0, descriptors, 324 320 config_desc.total_length, &transferred); 325 321 … … 368 364 static usb_hid_dev_kbd_t *usbkbd_init_device(device_t *dev) 369 365 { 370 int rc;371 372 366 usb_hid_dev_kbd_t *kbd_dev = (usb_hid_dev_kbd_t *)calloc(1, 373 367 sizeof(usb_hid_dev_kbd_t)); … … 380 374 kbd_dev->device = dev; 381 375 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 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 411 402 /* 412 403 * will need all descriptors: 413 * 1) choose one configuration from configuration descriptors 404 * 1) choose one configuration from configuration descriptors 414 405 * (set it to the device) 415 406 * 2) set endpoints from endpoint descriptors … … 417 408 418 409 // TODO: get descriptors, parse descriptors and save endpoints 419 usb_endpoint_pipe_start_session(&kbd_dev->ctrl_pipe);420 410 usbkbd_process_descriptors(kbd_dev); 421 usb_endpoint_pipe_end_session(&kbd_dev->ctrl_pipe);422 411 423 412 return kbd_dev; 424 425 error_leave:426 free(kbd_dev);427 return NULL;428 413 } 429 414 … … 450 435 static void usbkbd_poll_keyboard(usb_hid_dev_kbd_t *kbd_dev) 451 436 { 452 int rc, sess_rc; 437 int rc; 438 usb_handle_t handle; 453 439 uint8_t buffer[BUFFER_SIZE]; 454 440 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_endpoint 452 }; 455 453 456 454 printf("Polling keyboard...\n"); … … 458 456 while (true) { 459 457 async_usleep(1000 * 1000 * 2); 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));458 rc = usb_drv_async_interrupt_in(kbd_dev->device->parent_phone, 459 poll_target, buffer, BUFFER_SIZE, &actual_size, &handle); 460 461 if (rc != EOK) { 462 printf("Error in usb_drv_async_interrupt_in(): %d\n", rc); 465 463 continue; 466 464 } 467 465 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); 471 466 rc = usb_drv_async_wait_for(handle); 472 467 if (rc != EOK) { 473 printf("Error polling the keyboard: %s.\n", 474 str_error(rc)); 475 continue; 476 } 477 478 if (sess_rc != EOK) { 479 printf("Error closing session: %s.\n", 480 str_error(sess_rc)); 468 printf("Error in usb_drv_async_wait_for(): %d\n", rc); 481 469 continue; 482 470 }
Note:
See TracChangeset
for help on using the changeset viewer.