Changeset 50ba203 in mainline for uspace/drv/usbhid/main.c


Ignore:
Timestamp:
2011-02-20T15:46:48Z (13 years ago)
Author:
Matus Dekanek <smekideki@…>
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.
Message:

merge with usb/development

File:
1 edited

Legend:

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

    rd81ef61c r50ba203  
    4545#include <str_error.h>
    4646#include <fibril.h>
     47#include <usb/debug.h>
     48#include <usb/classes/classes.h>
    4749#include <usb/classes/hid.h>
    4850#include <usb/classes/hidparser.h>
    49 #include <usb/devreq.h>
     51#include <usb/request.h>
    5052#include <usb/descriptor.h>
    5153#include <io/console.h>
     
    6062
    6163#define GUESSED_POLL_ENDPOINT 1
     64
     65/** Keyboard polling endpoint description for boot protocol class. */
     66static 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};
    6274
    6375static void default_connection_handler(device_t *, ipc_callid_t, ipc_call_t *);
     
    262274}
    263275
    264 # if 0
    265276/*
    266277 * Kbd functions
     
    281292               
    282293                // 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,
    286298                    &actual_size);
    287299
     
    303315        usb_standard_configuration_descriptor_t config_desc;
    304316       
    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);
    307320       
    308321        if (rc != EOK) {
     
    318331        size_t transferred = 0;
    319332        // 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,
    322335            config_desc.total_length, &transferred);
    323336       
     
    329342        }
    330343       
     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
    331371        kbd_dev->conf = (usb_hid_configuration_t *)calloc(1,
    332372            sizeof(usb_hid_configuration_t));
     
    336376        }
    337377       
    338         rc = usbkbd_parse_descriptors(descriptors, transferred, kbd_dev->conf);
     378        /*rc = usbkbd_parse_descriptors(descriptors, transferred, kbd_dev->conf);
    339379        free(descriptors);
    340380        if (rc != EOK) {
     
    343383        }
    344384
    345         // get and report descriptors
     385        // get and report descriptors*/
    346386        rc = usbkbd_get_report_descriptor(kbd_dev);
    347387        if (rc != EOK) {
     
    360400     *    as the endpoint for polling
    361401         */
    362        
     402
    363403        return EOK;
    364404}
    365 #endif
     405
    366406static usb_hid_dev_kbd_t *usbkbd_init_device(device_t *dev)
    367407{
     408        int rc;
     409
    368410        usb_hid_dev_kbd_t *kbd_dev = (usb_hid_dev_kbd_t *)calloc(1,
    369411            sizeof(usb_hid_dev_kbd_t));
     
    376418        kbd_dev->device = dev;
    377419
    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 
    414420        /*
    415421         * Initialize the backing connection to the host controller.
     
    425431         * Initialize device pipes.
    426432         */
    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",
     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",
    431437                    str_error(rc));
    432438                goto error_leave;
    433439        }
    434440
     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        }
    435456
    436457        return kbd_dev;
     
    590611int main(int argc, char *argv[])
    591612{
     613        usb_log_enable(USB_LOG_LEVEL_INFO, "usbhid");
    592614        return driver_main(&kbd_driver);
    593615}
Note: See TracChangeset for help on using the changeset viewer.