Changeset 50ba203 in mainline for uspace/drv/usbhid/main.c
- Timestamp:
- 2011-02-20T15:46:48Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 6bb83c7
- Parents:
- d81ef61c (diff), 0c00dac (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
rd81ef61c r50ba203 45 45 #include <str_error.h> 46 46 #include <fibril.h> 47 #include <usb/debug.h> 48 #include <usb/classes/classes.h> 47 49 #include <usb/classes/hid.h> 48 50 #include <usb/classes/hidparser.h> 49 #include <usb/ devreq.h>51 #include <usb/request.h> 50 52 #include <usb/descriptor.h> 51 53 #include <io/console.h> … … 60 62 61 63 #define GUESSED_POLL_ENDPOINT 1 64 65 /** Keyboard polling endpoint description for boot protocol class. */ 66 static usb_endpoint_description_t poll_endpoint_description = { 67 .transfer_type = USB_TRANSFER_INTERRUPT, 68 .direction = USB_DIRECTION_IN, 69 .interface_class = USB_CLASS_HID, 70 .interface_subclass = USB_HID_SUBCLASS_BOOT, 71 .interface_protocol = USB_HID_PROTOCOL_KEYBOARD, 72 .flags = 0 73 }; 62 74 63 75 static void default_connection_handler(device_t *, ipc_callid_t, ipc_call_t *); … … 262 274 } 263 275 264 # if 0265 276 /* 266 277 * Kbd functions … … 281 292 282 293 // get the descriptor from the device 283 int rc = usb_drv_req_get_descriptor(kbd_dev->device->parent_phone, 284 kbd_dev->address, USB_REQUEST_TYPE_CLASS, USB_DESCTYPE_HID_REPORT, 285 0, i, kbd_dev->conf->interfaces[i].report_desc, length, 294 int rc = usb_request_get_descriptor(&kbd_dev->ctrl_pipe, 295 USB_REQUEST_TYPE_CLASS, USB_DESCTYPE_HID_REPORT, 296 i, 0, 297 kbd_dev->conf->interfaces[i].report_desc, length, 286 298 &actual_size); 287 299 … … 303 315 usb_standard_configuration_descriptor_t config_desc; 304 316 305 int rc = usb_drv_req_get_bare_configuration_descriptor( 306 kbd_dev->device->parent_phone, kbd_dev->address, 0, &config_desc); 317 int rc; 318 rc = usb_request_get_bare_configuration_descriptor(&kbd_dev->ctrl_pipe, 319 0, &config_desc); 307 320 308 321 if (rc != EOK) { … … 318 331 size_t transferred = 0; 319 332 // get full configuration descriptor 320 rc = usb_ drv_req_get_full_configuration_descriptor(321 kbd_dev->device->parent_phone, kbd_dev->address,0, descriptors,333 rc = usb_request_get_full_configuration_descriptor(&kbd_dev->ctrl_pipe, 334 0, descriptors, 322 335 config_desc.total_length, &transferred); 323 336 … … 329 342 } 330 343 344 /* 345 * Initialize the interrupt in endpoint. 346 */ 347 usb_endpoint_mapping_t endpoint_mapping[1] = { 348 { 349 .pipe = &kbd_dev->poll_pipe, 350 .description = &poll_endpoint_description 351 } 352 }; 353 rc = usb_endpoint_pipe_initialize_from_configuration( 354 endpoint_mapping, 1, 355 descriptors, config_desc.total_length, 356 &kbd_dev->wire); 357 if (rc != EOK) { 358 usb_log_error("Failed to initialize poll pipe: %s.\n", 359 str_error(rc)); 360 return rc; 361 } 362 if (!endpoint_mapping[0].present) { 363 usb_log_warning("Not accepting device, " \ 364 "not boot-protocol keyboard.\n"); 365 return EREFUSED; 366 } 367 368 369 370 331 371 kbd_dev->conf = (usb_hid_configuration_t *)calloc(1, 332 372 sizeof(usb_hid_configuration_t)); … … 336 376 } 337 377 338 rc = usbkbd_parse_descriptors(descriptors, transferred, kbd_dev->conf);378 /*rc = usbkbd_parse_descriptors(descriptors, transferred, kbd_dev->conf); 339 379 free(descriptors); 340 380 if (rc != EOK) { … … 343 383 } 344 384 345 // get and report descriptors 385 // get and report descriptors*/ 346 386 rc = usbkbd_get_report_descriptor(kbd_dev); 347 387 if (rc != EOK) { … … 360 400 * as the endpoint for polling 361 401 */ 362 402 363 403 return EOK; 364 404 } 365 #endif 405 366 406 static usb_hid_dev_kbd_t *usbkbd_init_device(device_t *dev) 367 407 { 408 int rc; 409 368 410 usb_hid_dev_kbd_t *kbd_dev = (usb_hid_dev_kbd_t *)calloc(1, 369 411 sizeof(usb_hid_dev_kbd_t)); … … 376 418 kbd_dev->device = dev; 377 419 378 // get phone to my HC and save it as my parent's phone379 // TODO: maybe not a good idea if DDF will use parent_phone380 int rc = kbd_dev->device->parent_phone = usb_drv_hc_connect_auto(dev, 0);381 if (rc < 0) {382 printf("Problem setting phone to HC.\n");383 goto error_leave;384 }385 386 rc = kbd_dev->address = usb_drv_get_my_address(dev->parent_phone, dev);387 if (rc < 0) {388 printf("Problem getting address of the device.\n");389 goto error_leave;390 }391 392 // doesn't matter now that we have no address393 // if (kbd_dev->address < 0) {394 // fprintf(stderr, NAME ": No device address!\n");395 // free(kbd_dev);396 // return NULL;397 // }398 399 /*400 * will need all descriptors:401 * 1) choose one configuration from configuration descriptors402 * (set it to the device)403 * 2) set endpoints from endpoint descriptors404 */405 406 407 // TODO: get descriptors, parse descriptors and save endpoints408 //usbkbd_process_descriptors(kbd_dev);409 usb_drv_req_set_configuration(410 kbd_dev->device->parent_phone, kbd_dev->address, 1);411 412 413 414 420 /* 415 421 * Initialize the backing connection to the host controller. … … 425 431 * Initialize device pipes. 426 432 */ 427 rc = usb_endpoint_pipe_initialize (&kbd_dev->poll_pipe, &kbd_dev->wire,428 GUESSED_POLL_ENDPOINT, USB_TRANSFER_INTERRUPT, USB_DIRECTION_IN);429 if (rc != EOK) { 430 printf("Failed to initialize interrupt inpipe: %s.\n",433 rc = usb_endpoint_pipe_initialize_default_control(&kbd_dev->ctrl_pipe, 434 &kbd_dev->wire); 435 if (rc != EOK) { 436 printf("Failed to initialize default control pipe: %s.\n", 431 437 str_error(rc)); 432 438 goto error_leave; 433 439 } 434 440 441 /* 442 * will need all descriptors: 443 * 1) choose one configuration from configuration descriptors 444 * (set it to the device) 445 * 2) set endpoints from endpoint descriptors 446 */ 447 448 // TODO: get descriptors, parse descriptors and save endpoints 449 usb_endpoint_pipe_start_session(&kbd_dev->ctrl_pipe); 450 //usb_request_set_configuration(&kbd_dev->ctrl_pipe, 1); 451 rc = usbkbd_process_descriptors(kbd_dev); 452 usb_endpoint_pipe_end_session(&kbd_dev->ctrl_pipe); 453 if (rc != EOK) { 454 goto error_leave; 455 } 435 456 436 457 return kbd_dev; … … 590 611 int main(int argc, char *argv[]) 591 612 { 613 usb_log_enable(USB_LOG_LEVEL_INFO, "usbhid"); 592 614 return driver_main(&kbd_driver); 593 615 }
Note:
See TracChangeset
for help on using the changeset viewer.