Changes in uspace/drv/usbhid/main.c [b43bcf1:ad29045] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbhid/main.c
rb43bcf1 rad29045 45 45 #include <str_error.h> 46 46 #include <fibril.h> 47 #include <usb/debug.h>48 #include <usb/classes/classes.h>49 47 #include <usb/classes/hid.h> 50 48 #include <usb/classes/hidparser.h> 51 #include <usb/ request.h>49 #include <usb/devreq.h> 52 50 #include <usb/descriptor.h> 53 51 #include <io/console.h> … … 62 60 63 61 #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 = 073 };74 62 75 63 static void default_connection_handler(device_t *, ipc_callid_t, ipc_call_t *); … … 274 262 } 275 263 264 # if 0 276 265 /* 277 266 * Kbd functions … … 292 281 293 282 // get the descriptor from the device 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, 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, 298 286 &actual_size); 299 287 … … 315 303 usb_standard_configuration_descriptor_t config_desc; 316 304 317 int rc; 318 rc = usb_request_get_bare_configuration_descriptor(&kbd_dev->ctrl_pipe, 319 0, &config_desc); 305 int rc = usb_drv_req_get_bare_configuration_descriptor( 306 kbd_dev->device->parent_phone, kbd_dev->address, 0, &config_desc); 320 307 321 308 if (rc != EOK) { … … 331 318 size_t transferred = 0; 332 319 // get full configuration descriptor 333 rc = usb_ request_get_full_configuration_descriptor(&kbd_dev->ctrl_pipe,334 0, descriptors,320 rc = usb_drv_req_get_full_configuration_descriptor( 321 kbd_dev->device->parent_phone, kbd_dev->address, 0, descriptors, 335 322 config_desc.total_length, &transferred); 336 323 … … 342 329 } 343 330 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_description351 }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 371 331 kbd_dev->conf = (usb_hid_configuration_t *)calloc(1, 372 332 sizeof(usb_hid_configuration_t)); … … 376 336 } 377 337 378 /*rc = usbkbd_parse_descriptors(descriptors, transferred, kbd_dev->conf);338 rc = usbkbd_parse_descriptors(descriptors, transferred, kbd_dev->conf); 379 339 free(descriptors); 380 340 if (rc != EOK) { … … 383 343 } 384 344 385 // get and report descriptors */345 // get and report descriptors 386 346 rc = usbkbd_get_report_descriptor(kbd_dev); 387 347 if (rc != EOK) { … … 400 360 * as the endpoint for polling 401 361 */ 402 362 403 363 return EOK; 404 364 } 405 365 #endif 406 366 static usb_hid_dev_kbd_t *usbkbd_init_device(device_t *dev) 407 367 { 408 int rc;409 410 368 usb_hid_dev_kbd_t *kbd_dev = (usb_hid_dev_kbd_t *)calloc(1, 411 369 sizeof(usb_hid_dev_kbd_t)); … … 418 376 kbd_dev->device = dev; 419 377 378 // get phone to my HC and save it as my parent's phone 379 // TODO: maybe not a good idea if DDF will use parent_phone 380 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 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 /* 400 * will need all descriptors: 401 * 1) choose one configuration from configuration descriptors 402 * (set it to the device) 403 * 2) set endpoints from endpoint descriptors 404 */ 405 406 407 // TODO: get descriptors, parse descriptors and save endpoints 408 //usbkbd_process_descriptors(kbd_dev); 409 usb_drv_req_set_configuration( 410 kbd_dev->device->parent_phone, kbd_dev->address, 1); 411 412 413 420 414 /* 421 415 * Initialize the backing connection to the host controller. … … 431 425 * Initialize device pipes. 432 426 */ 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 controlpipe: %s.\n",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 in pipe: %s.\n", 437 431 str_error(rc)); 438 432 goto error_leave; 439 433 } 440 434 441 /*442 * will need all descriptors:443 * 1) choose one configuration from configuration descriptors444 * (set it to the device)445 * 2) set endpoints from endpoint descriptors446 */447 448 // TODO: get descriptors, parse descriptors and save endpoints449 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 }456 435 457 436 return kbd_dev; … … 611 590 int main(int argc, char *argv[]) 612 591 { 613 usb_log_enable(USB_LOG_LEVEL_INFO, "usbhid");614 592 return driver_main(&kbd_driver); 615 593 }
Note:
See TracChangeset
for help on using the changeset viewer.