Ignore:
File:
1 edited

Legend:

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

    rb43bcf1 rad29045  
    4545#include <str_error.h>
    4646#include <fibril.h>
    47 #include <usb/debug.h>
    48 #include <usb/classes/classes.h>
    4947#include <usb/classes/hid.h>
    5048#include <usb/classes/hidparser.h>
    51 #include <usb/request.h>
     49#include <usb/devreq.h>
    5250#include <usb/descriptor.h>
    5351#include <io/console.h>
     
    6260
    6361#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 };
    7462
    7563static void default_connection_handler(device_t *, ipc_callid_t, ipc_call_t *);
     
    274262}
    275263
     264# if 0
    276265/*
    277266 * Kbd functions
     
    292281               
    293282                // 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,
    298286                    &actual_size);
    299287
     
    315303        usb_standard_configuration_descriptor_t config_desc;
    316304       
    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);
    320307       
    321308        if (rc != EOK) {
     
    331318        size_t transferred = 0;
    332319        // 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,
    335322            config_desc.total_length, &transferred);
    336323       
     
    342329        }
    343330       
    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 
    371331        kbd_dev->conf = (usb_hid_configuration_t *)calloc(1,
    372332            sizeof(usb_hid_configuration_t));
     
    376336        }
    377337       
    378         /*rc = usbkbd_parse_descriptors(descriptors, transferred, kbd_dev->conf);
     338        rc = usbkbd_parse_descriptors(descriptors, transferred, kbd_dev->conf);
    379339        free(descriptors);
    380340        if (rc != EOK) {
     
    383343        }
    384344
    385         // get and report descriptors*/
     345        // get and report descriptors
    386346        rc = usbkbd_get_report_descriptor(kbd_dev);
    387347        if (rc != EOK) {
     
    400360     *    as the endpoint for polling
    401361         */
    402 
     362       
    403363        return EOK;
    404364}
    405 
     365#endif
    406366static usb_hid_dev_kbd_t *usbkbd_init_device(device_t *dev)
    407367{
    408         int rc;
    409 
    410368        usb_hid_dev_kbd_t *kbd_dev = (usb_hid_dev_kbd_t *)calloc(1,
    411369            sizeof(usb_hid_dev_kbd_t));
     
    418376        kbd_dev->device = dev;
    419377
     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
    420414        /*
    421415         * Initialize the backing connection to the host controller.
     
    431425         * Initialize device pipes.
    432426         */
    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",
     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",
    437431                    str_error(rc));
    438432                goto error_leave;
    439433        }
    440434
    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         }
    456435
    457436        return kbd_dev;
     
    611590int main(int argc, char *argv[])
    612591{
    613         usb_log_enable(USB_LOG_LEVEL_INFO, "usbhid");
    614592        return driver_main(&kbd_driver);
    615593}
Note: See TracChangeset for help on using the changeset viewer.