Ignore:
File:
1 edited

Legend:

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

    re2dfa86 r9d58539  
    4141#include <usb/hid/hidreport.h>
    4242#include <usb/hid/request.h>
    43 
    4443#include <errno.h>
    45 #include <macros.h>
    4644#include <str_error.h>
    4745
     
    6058        NULL
    6159};
    62 
     60/*----------------------------------------------------------------------------*/
    6361static int usb_hid_set_boot_kbd_subdriver(usb_hid_dev_t *hid_dev)
    6462{
     
    7674        return EOK;
    7775}
    78 
     76/*----------------------------------------------------------------------------*/
    7977static int usb_hid_set_boot_mouse_subdriver(usb_hid_dev_t *hid_dev)
    8078{
     
    9290        return EOK;
    9391}
    94 
     92/*----------------------------------------------------------------------------*/
    9593static int usb_hid_set_generic_hid_subdriver(usb_hid_dev_t *hid_dev)
    9694{
     
    112110        return EOK;
    113111}
    114 
     112/*----------------------------------------------------------------------------*/
    115113static bool usb_hid_ids_match(const usb_hid_dev_t *hid_dev,
    116114    const usb_hid_subdriver_mapping_t *mapping)
    117115{
    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);
    126 }
    127 
     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);
     123}
     124/*----------------------------------------------------------------------------*/
    128125static bool usb_hid_path_matches(usb_hid_dev_t *hid_dev,
    129126    const usb_hid_subdriver_mapping_t *mapping)
     
    181178        return matches;
    182179}
    183 
     180/*----------------------------------------------------------------------------*/
    184181static int usb_hid_save_subdrivers(usb_hid_dev_t *hid_dev,
    185182    const usb_hid_subdriver_t **subdrivers, unsigned count)
     
    214211        return EOK;
    215212}
    216 
     213/*----------------------------------------------------------------------------*/
    217214static int usb_hid_find_subdrivers(usb_hid_dev_t *hid_dev)
    218215{
     
    266263        return usb_hid_save_subdrivers(hid_dev, subdrivers, count);
    267264}
    268 
    269 static int usb_hid_check_pipes(usb_hid_dev_t *hid_dev, usb_device_t *dev)
     265/*----------------------------------------------------------------------------*/
     266static int usb_hid_check_pipes(usb_hid_dev_t *hid_dev, const usb_device_t *dev)
    270267{
    271268        assert(hid_dev);
     
    273270
    274271        static const struct {
    275                 const usb_endpoint_description_t *desc;
     272                unsigned ep_number;
    276273                const char* description;
    277274        } endpoints[] = {
    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"},
     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"},
    281278        };
    282279
    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) {
     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) {
    287285                        usb_log_debug("Found: %s.\n", endpoints[i].description);
    288                         hid_dev->poll_pipe_mapping = epm;
     286                        hid_dev->poll_pipe_index = endpoints[i].ep_number;
    289287                        return EOK;
    290288                }
     
    292290        return ENOTSUP;
    293291}
    294 
     292/*----------------------------------------------------------------------------*/
    295293static int usb_hid_init_report(usb_hid_dev_t *hid_dev)
    296294{
     
    324322        return EOK;
    325323}
    326 
     324/*----------------------------------------------------------------------------*/
    327325/*
    328326 * This functions initializes required structures from the device's descriptors
     
    353351        /* The USB device should already be initialized, save it in structure */
    354352        hid_dev->usb_dev = dev;
    355         hid_dev->poll_pipe_mapping = NULL;
     353        hid_dev->poll_pipe_index = -1;
    356354
    357355        int rc = usb_hid_check_pipes(hid_dev, dev);
     
    383381                    "boot protocol.\n");
    384382
    385                 switch (hid_dev->poll_pipe_mapping->interface->interface_protocol) {
    386                 case USB_HID_PROTOCOL_KEYBOARD:
     383                switch (hid_dev->poll_pipe_index) {
     384                case USB_HID_KBD_POLL_EP_NO:
    387385                        usb_log_info("Falling back to kbd boot protocol.\n");
    388386                        rc = usb_kbd_set_boot_protocol(hid_dev);
     
    391389                        }
    392390                        break;
    393                 case USB_HID_PROTOCOL_MOUSE:
     391                case USB_HID_MOUSE_POLL_EP_NO:
    394392                        usb_log_info("Falling back to mouse boot protocol.\n");
    395393                        rc = usb_mouse_set_boot_protocol(hid_dev);
     
    399397                        break;
    400398                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);
     
    458458        return rc;
    459459}
    460 
     460/*----------------------------------------------------------------------------*/
    461461bool usb_hid_polling_callback(usb_device_t *dev, uint8_t *buffer,
    462462    size_t buffer_size, void *arg)
     
    485485            &hid_dev->report, buffer, buffer_size, &hid_dev->report_id);
    486486        if (rc != EOK) {
    487                 usb_log_warning("Failure in usb_hid_parse_report():"
     487                usb_log_warning("Error in usb_hid_parse_report():"
    488488                    "%s\n", str_error(rc));
    489489        }
     
    500500        return cont;
    501501}
    502 
     502/*----------------------------------------------------------------------------*/
    503503void usb_hid_polling_ended_callback(usb_device_t *dev, bool reason, void *arg)
    504504{
     
    517517        hid_dev->running = false;
    518518}
    519 
     519/*----------------------------------------------------------------------------*/
    520520void usb_hid_new_report(usb_hid_dev_t *hid_dev)
    521521{
    522522        ++hid_dev->report_nr;
    523523}
    524 
     524/*----------------------------------------------------------------------------*/
    525525int usb_hid_report_number(const usb_hid_dev_t *hid_dev)
    526526{
    527527        return hid_dev->report_nr;
    528528}
    529 
     529/*----------------------------------------------------------------------------*/
    530530void usb_hid_deinit(usb_hid_dev_t *hid_dev)
    531531{
Note: See TracChangeset for help on using the changeset viewer.