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


Ignore:
Timestamp:
2016-07-22T08:24:47Z (8 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f76d2c2
Parents:
5b18137 (diff), 8351f9a4 (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 from lp:~jan.vesely/helenos/usb

File:
1 edited

Legend:

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

    r5b18137 rb4b534ac  
    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
     
    114116    const usb_hid_subdriver_mapping_t *mapping)
    115117{
    116         assert(hid_dev != NULL);
    117         assert(hid_dev->usb_dev != NULL);
    118 
    119         return (hid_dev->usb_dev->descriptors.device.vendor_id
    120             == mapping->vendor_id
    121             && hid_dev->usb_dev->descriptors.device.product_id
    122             == mapping->product_id);
     118        assert(hid_dev);
     119        assert(hid_dev->usb_dev);
     120        assert(mapping);
     121        const usb_standard_device_descriptor_t *d =
     122            &usb_device_descriptors(hid_dev->usb_dev)->device;
     123
     124        return (d->vendor_id == mapping->vendor_id)
     125            && (d->product_id == mapping->product_id);
    123126}
    124127
     
    264267}
    265268
    266 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)
    267270{
    268271        assert(hid_dev);
     
    270273
    271274        static const struct {
    272                 unsigned ep_number;
     275                const usb_endpoint_description_t *desc;
    273276                const char* description;
    274277        } endpoints[] = {
    275                 {USB_HID_KBD_POLL_EP_NO, "Keyboard endpoint"},
    276                 {USB_HID_MOUSE_POLL_EP_NO, "Mouse endpoint"},
    277                 {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"},
    278281        };
    279282
    280         for (unsigned i = 0; i < sizeof(endpoints)/sizeof(endpoints[0]); ++i) {
    281                 if (endpoints[i].ep_number >= dev->pipes_count) {
    282                         return EINVAL;
    283                 }
    284                 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) {
    285287                        usb_log_debug("Found: %s.\n", endpoints[i].description);
    286                         hid_dev->poll_pipe_index = endpoints[i].ep_number;
     288                        hid_dev->poll_pipe_mapping = epm;
    287289                        return EOK;
    288290                }
     
    351353        /* The USB device should already be initialized, save it in structure */
    352354        hid_dev->usb_dev = dev;
    353         hid_dev->poll_pipe_index = -1;
     355        hid_dev->poll_pipe_mapping = NULL;
    354356
    355357        int rc = usb_hid_check_pipes(hid_dev, dev);
     
    381383                    "boot protocol.\n");
    382384
    383                 switch (hid_dev->poll_pipe_index) {
    384                 case USB_HID_KBD_POLL_EP_NO:
     385                switch (hid_dev->poll_pipe_mapping->interface->interface_protocol) {
     386                case USB_HID_PROTOCOL_KEYBOARD:
    385387                        usb_log_info("Falling back to kbd boot protocol.\n");
    386388                        rc = usb_kbd_set_boot_protocol(hid_dev);
     
    389391                        }
    390392                        break;
    391                 case USB_HID_MOUSE_POLL_EP_NO:
     393                case USB_HID_PROTOCOL_MOUSE:
    392394                        usb_log_info("Falling back to mouse boot protocol.\n");
    393395                        rc = usb_mouse_set_boot_protocol(hid_dev);
     
    397399                        break;
    398400                default:
    399                         assert(hid_dev->poll_pipe_index
    400                             == USB_HID_GENERIC_POLL_EP_NO);
    401401                        usb_log_info("Falling back to generic HID driver.\n");
    402402                        usb_hid_set_generic_hid_subdriver(hid_dev);
     
    476476            &hid_dev->report, buffer, buffer_size, &hid_dev->report_id);
    477477        if (rc != EOK) {
    478                 usb_log_warning("Error in usb_hid_parse_report():"
     478                usb_log_warning("Failure in usb_hid_parse_report():"
    479479                    "%s\n", str_error(rc));
    480480        }
Note: See TracChangeset for help on using the changeset viewer.