Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/usbhid/main.c

    r0484d92 r66d5062  
    4343#include <io/console.h>
    4444#include <errno.h>
    45 #include <str_error.h>
    4645#include <fibril.h>
    4746#include <usb/classes/hid.h>
    4847#include <usb/classes/hidparser.h>
    49 #include <usb/request.h>
     48#include <usb/devreq.h>
    5049#include <usb/descriptor.h>
    5150#include <io/console.h>
    52 #include "hid.h"
    5351#include "descparser.h"
    5452#include "descdump.h"
     
    280278               
    281279                // 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,
    286283                    &actual_size);
    287284
     
    304301        usb_standard_configuration_descriptor_t config_desc;
    305302       
    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);
    309305       
    310306        if (rc != EOK) {
     
    320316        size_t transferred = 0;
    321317        // 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,
    324320            config_desc.total_length, &transferred);
    325321       
     
    368364static usb_hid_dev_kbd_t *usbkbd_init_device(device_t *dev)
    369365{
    370         int rc;
    371 
    372366        usb_hid_dev_kbd_t *kbd_dev = (usb_hid_dev_kbd_t *)calloc(1,
    373367            sizeof(usb_hid_dev_kbd_t));
     
    380374        kbd_dev->device = dev;
    381375
    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       
    411402        /*
    412403         * will need all descriptors:
    413          * 1) choose one configuration from configuration descriptors
     404         * 1) choose one configuration from configuration descriptors 
    414405         *    (set it to the device)
    415406         * 2) set endpoints from endpoint descriptors
     
    417408
    418409        // TODO: get descriptors, parse descriptors and save endpoints
    419         usb_endpoint_pipe_start_session(&kbd_dev->ctrl_pipe);
    420410        usbkbd_process_descriptors(kbd_dev);
    421         usb_endpoint_pipe_end_session(&kbd_dev->ctrl_pipe);
    422411
    423412        return kbd_dev;
    424 
    425 error_leave:
    426         free(kbd_dev);
    427         return NULL;
    428413}
    429414
     
    450435static void usbkbd_poll_keyboard(usb_hid_dev_kbd_t *kbd_dev)
    451436{
    452         int rc, sess_rc;
     437        int rc;
     438        usb_handle_t handle;
    453439        uint8_t buffer[BUFFER_SIZE];
    454440        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        };
    455453
    456454        printf("Polling keyboard...\n");
     
    458456        while (true) {
    459457                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);
    465463                        continue;
    466464                }
    467465
    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);
    472467                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);
    481469                        continue;
    482470                }
Note: See TracChangeset for help on using the changeset viewer.