Changeset bb70637 in mainline for uspace/drv/bus/usb/usbhid/usbhid.c


Ignore:
Timestamp:
2013-01-26T23:35:12Z (11 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
35bc430
Parents:
3e23316
Message:

usb: Rework polling to accept either ep numbers or descriptions.

Switch usbhub and usbhid to new polling.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/usbhid/usbhid.c

    r3e23316 rbb70637  
    4141#include <usb/hid/hidreport.h>
    4242#include <usb/hid/request.h>
     43
    4344#include <errno.h>
     45#include <macros.h>
    4446#include <str_error.h>
    4547
     
    265267}
    266268
    267 static int usb_hid_check_pipes(usb_hid_dev_t *hid_dev, const usb_device_t *dev)
     269static int usb_hid_check_pipes(usb_hid_dev_t *hid_dev, usb_device_t *dev)
    268270{
    269271        assert(hid_dev);
     
    271273
    272274        static const struct {
    273                 unsigned ep_number;
     275                const usb_endpoint_description_t *desc;
    274276                const char* description;
    275277        } endpoints[] = {
    276                 {USB_HID_KBD_POLL_EP_NO, "Keyboard endpoint"},
    277                 {USB_HID_MOUSE_POLL_EP_NO, "Mouse endpoint"},
    278                 {USB_HID_GENERIC_POLL_EP_NO, "Generic HID endpoint"},
     278                {&usb_hid_kbd_poll_endpoint_description, "Keyboard endpoint"},
     279                {&usb_hid_mouse_poll_endpoint_description, "Mouse endpoint"},
     280                {&usb_hid_generic_poll_endpoint_description, "Generic HID endpoint"},
    279281        };
    280282
    281         for (unsigned i = 0; i < sizeof(endpoints)/sizeof(endpoints[0]); ++i) {
    282                 if (endpoints[i].ep_number >= dev->pipes_count) {
    283                         return EINVAL;
    284                 }
    285                 if (dev->pipes[endpoints[i].ep_number].present) {
     283        for (unsigned i = 0; i < ARRAY_SIZE(endpoints); ++i) {
     284                usb_endpoint_mapping_t *epm =
     285                    usb_device_get_mapped_ep_desc(dev, endpoints[i].desc);
     286                if (epm && epm->present) {
    286287                        usb_log_debug("Found: %s.\n", endpoints[i].description);
    287                         hid_dev->poll_pipe_index = endpoints[i].ep_number;
     288                        hid_dev->poll_pipe_mapping = epm;
    288289                        return EOK;
    289290                }
     
    352353        /* The USB device should already be initialized, save it in structure */
    353354        hid_dev->usb_dev = dev;
    354         hid_dev->poll_pipe_index = -1;
     355        hid_dev->poll_pipe_mapping = NULL;
    355356
    356357        int rc = usb_hid_check_pipes(hid_dev, dev);
     
    382383                    "boot protocol.\n");
    383384
    384                 switch (hid_dev->poll_pipe_index) {
    385                 case USB_HID_KBD_POLL_EP_NO:
     385                switch (hid_dev->poll_pipe_mapping->interface->interface_protocol) {
     386                case USB_HID_PROTOCOL_KEYBOARD:
    386387                        usb_log_info("Falling back to kbd boot protocol.\n");
    387388                        rc = usb_kbd_set_boot_protocol(hid_dev);
     
    390391                        }
    391392                        break;
    392                 case USB_HID_MOUSE_POLL_EP_NO:
     393                case USB_HID_PROTOCOL_MOUSE:
    393394                        usb_log_info("Falling back to mouse boot protocol.\n");
    394395                        rc = usb_mouse_set_boot_protocol(hid_dev);
     
    398399                        break;
    399400                default:
    400                         assert(hid_dev->poll_pipe_index
    401                             == USB_HID_GENERIC_POLL_EP_NO);
    402401                        usb_log_info("Falling back to generic HID driver.\n");
    403402                        usb_hid_set_generic_hid_subdriver(hid_dev);
Note: See TracChangeset for help on using the changeset viewer.