Ignore:
File:
1 edited

Legend:

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

    re3c78efc r5f6e25e  
    4242#include <errno.h>
    4343#include <async.h>
     44#include <async_obsolete.h>
    4445#include <str_error.h>
    4546#include <ipc/mouseev.h>
     
    5556#define ARROWS_PER_SINGLE_WHEEL 3
    5657
     58// FIXME: remove this header
     59#include <abi/ipc/methods.h>
     60
    5761#define NAME "mouse"
    5862
    5963/*----------------------------------------------------------------------------*/
    6064
    61 const usb_endpoint_description_t usb_hid_mouse_poll_endpoint_description = {
     65usb_endpoint_description_t usb_hid_mouse_poll_endpoint_description = {
    6266        .transfer_type = USB_TRANSFER_INTERRUPT,
    6367        .direction = USB_DIRECTION_IN,
     
    7579/** Default idle rate for mouses. */
    7680static const uint8_t IDLE_RATE = 0;
    77 
    78 /*----------------------------------------------------------------------------*/
    79 static const uint8_t USB_MOUSE_BOOT_REPORT_DESCRIPTOR[] = {
     81static const size_t USB_MOUSE_BUTTON_COUNT = 3;
     82
     83/*----------------------------------------------------------------------------*/
     84
     85enum {
     86        USB_MOUSE_BOOT_REPORT_DESCRIPTOR_SIZE = 63
     87};
     88
     89static const uint8_t USB_MOUSE_BOOT_REPORT_DESCRIPTOR[
     90    USB_MOUSE_BOOT_REPORT_DESCRIPTOR_SIZE] = {
    8091        0x05, 0x01,                    // USAGE_PAGE (Generic Desktop)
    8192        0x09, 0x02,                    // USAGE (Mouse)
     
    117128    ipc_callid_t icallid, ipc_call_t *icall)
    118129{
    119         usb_mouse_t *mouse_dev = fun->driver_data;
    120 
     130        sysarg_t method = IPC_GET_IMETHOD(*icall);
     131       
     132        usb_mouse_t *mouse_dev = (usb_mouse_t *)fun->driver_data;
     133       
    121134        if (mouse_dev == NULL) {
    122                 usb_log_debug("%s: Missing parameters.\n", __FUNCTION__);
     135                usb_log_debug("default_connection_handler: Missing "
     136                    "parameters.\n");
    123137                async_answer_0(icallid, EINVAL);
    124138                return;
    125139        }
    126 
    127         usb_log_debug("%s: fun->name: %s\n", __FUNCTION__, fun->name);
    128         usb_log_debug("%s: mouse_sess: %p, wheel_sess: %p\n",
    129             __FUNCTION__, mouse_dev->mouse_sess, mouse_dev->wheel_sess);
    130 
    131         async_sess_t **sess_ptr = (fun == mouse_dev->mouse_fun) ?
    132             &mouse_dev->mouse_sess : &mouse_dev->wheel_sess;
    133 
    134         async_sess_t *sess =
    135             async_callback_receive_start(EXCHANGE_SERIALIZE, icall);
    136         if (sess != NULL) {
    137                 if (*sess_ptr == NULL) {
    138                         *sess_ptr = sess;
    139                         usb_log_debug("Console session to %s set ok (%p).\n",
    140                             fun->name, sess);
    141                         async_answer_0(icallid, EOK);
    142                 } else {
    143                         usb_log_error("Console session to %s already set.\n",
    144                             fun->name);
     140       
     141        usb_log_debug("default_connection_handler: fun->name: %s\n",
     142                      fun->name);
     143        usb_log_debug("default_connection_handler: mouse_phone: %d, wheel "
     144            "phone: %d\n", mouse_dev->mouse_phone, mouse_dev->wheel_phone);
     145       
     146        int *phone = (str_cmp(fun->name, HID_MOUSE_FUN_NAME) == 0)
     147                     ? &mouse_dev->mouse_phone : &mouse_dev->wheel_phone;
     148       
     149        if (method == IPC_M_CONNECT_TO_ME) {
     150                int callback = IPC_GET_ARG5(*icall);
     151
     152                if (*phone != -1) {
     153                        usb_log_debug("default_connection_handler: Console "
     154                            "phone to mouse already set.\n");
    145155                        async_answer_0(icallid, ELIMIT);
     156                        return;
    146157                }
    147         } else {
    148                 usb_log_debug("%s: Invalid function.\n", __FUNCTION__);
    149                 async_answer_0(icallid, EINVAL);
     158
     159                *phone = callback;
     160                usb_log_debug("Console phone to mouse set ok (%d).\n", *phone);
     161                async_answer_0(icallid, EOK);
     162                return;
     163        }
     164
     165        usb_log_debug("default_connection_handler: Invalid function.\n");
     166        async_answer_0(icallid, EINVAL);
     167}
     168
     169/*----------------------------------------------------------------------------*/
     170
     171static usb_mouse_t *usb_mouse_new(void)
     172{
     173        usb_mouse_t *mouse = calloc(1, sizeof(usb_mouse_t));
     174        if (mouse == NULL) {
     175                return NULL;
     176        }
     177        mouse->mouse_phone = -1;
     178        mouse->wheel_phone = -1;
     179       
     180        return mouse;
     181}
     182
     183/*----------------------------------------------------------------------------*/
     184
     185static void usb_mouse_destroy(usb_mouse_t *mouse_dev)
     186{
     187        assert(mouse_dev != NULL);
     188       
     189        // hangup phone to the console
     190        if (mouse_dev->mouse_phone >= 0) {
     191                async_obsolete_hangup(mouse_dev->mouse_phone);
     192        }
     193       
     194        if (mouse_dev->wheel_phone >= 0) {
     195                async_obsolete_hangup(mouse_dev->wheel_phone);
    150196        }
    151197}
     
    157203        unsigned int key = (wheel > 0) ? KC_UP : KC_DOWN;
    158204
    159         if (mouse_dev->wheel_sess == NULL) {
     205        if (mouse_dev->wheel_phone < 0) {
    160206                usb_log_warning(
    161207                    "Connection to console not ready, wheel roll discarded.\n");
    162208                return;
    163209        }
    164 
    165         const unsigned count =
    166             ((wheel < 0) ? -wheel : wheel) * ARROWS_PER_SINGLE_WHEEL;
    167         for (unsigned i = 0; i < count; i++) {
     210       
     211        int count = ((wheel < 0) ? -wheel : wheel) * ARROWS_PER_SINGLE_WHEEL;
     212        int i;
     213       
     214        for (i = 0; i < count; i++) {
    168215                /* Send arrow press and release. */
    169216                usb_log_debug2("Sending key %d to the console\n", key);
    170                
    171                 async_exch_t *exch = async_exchange_begin(mouse_dev->wheel_sess);
    172                
    173                 async_msg_4(exch, KBDEV_EVENT, KEY_PRESS, key, 0, 0);
    174                 async_msg_4(exch, KBDEV_EVENT, KEY_RELEASE, key, 0, 0);
    175                
    176                 async_exchange_end(exch);
     217                async_obsolete_msg_4(mouse_dev->wheel_phone, KBDEV_EVENT,
     218                    KEY_PRESS, key, 0, 0);
     219                async_obsolete_msg_4(mouse_dev->wheel_phone, KBDEV_EVENT,
     220                    KEY_RELEASE, key, 0, 0);
    177221        }
    178222}
     
    208252{
    209253        assert(mouse_dev != NULL);
    210 
    211         if (mouse_dev->mouse_sess == NULL) {
    212                 usb_log_warning(NAME " No console session.\n");
     254       
     255        if (mouse_dev->mouse_phone < 0) {
     256                usb_log_warning(NAME " No console phone.\n");
    213257                return true;
    214258        }
    215259
    216         const int shift_x = get_mouse_axis_move_value(hid_dev->report_id,
    217             &hid_dev->report, USB_HIDUT_USAGE_GENERIC_DESKTOP_X);
    218         const int shift_y = get_mouse_axis_move_value(hid_dev->report_id,
    219             &hid_dev->report, USB_HIDUT_USAGE_GENERIC_DESKTOP_Y);
    220         const int wheel = get_mouse_axis_move_value(hid_dev->report_id,
    221             &hid_dev->report, USB_HIDUT_USAGE_GENERIC_DESKTOP_WHEEL);
     260        int shift_x = get_mouse_axis_move_value(hid_dev->report_id,
     261            hid_dev->report, USB_HIDUT_USAGE_GENERIC_DESKTOP_X);
     262        int shift_y = get_mouse_axis_move_value(hid_dev->report_id,
     263            hid_dev->report, USB_HIDUT_USAGE_GENERIC_DESKTOP_Y);
     264        int wheel = get_mouse_axis_move_value(hid_dev->report_id,
     265            hid_dev->report, USB_HIDUT_USAGE_GENERIC_DESKTOP_WHEEL);
    222266
    223267        if ((shift_x != 0) || (shift_y != 0)) {
    224                 async_exch_t *exch =
    225                     async_exchange_begin(mouse_dev->mouse_sess);
    226                 if (exch != NULL) {
    227                         async_req_2_0(exch, MOUSEEV_MOVE_EVENT, shift_x, shift_y);
    228                         async_exchange_end(exch);
    229                 }
    230         }
    231 
    232         if (wheel != 0)
     268                async_obsolete_req_2_0(mouse_dev->mouse_phone,
     269                    MOUSEEV_MOVE_EVENT, shift_x, shift_y);
     270        }
     271
     272        if (wheel != 0) {
    233273                usb_mouse_send_wheel(mouse_dev, wheel);
    234 
    235         /* Buttons */
     274        }
     275       
     276        /*
     277         * Buttons
     278         */
    236279        usb_hid_report_path_t *path = usb_hid_report_path();
    237         if (path == NULL) {
    238                 usb_log_warning("Failed to create USB HID report path.\n");
    239                 return true;
    240         }
    241         int ret =
    242            usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_BUTTON, 0);
    243         if (ret != EOK) {
    244                 usb_hid_report_path_free(path);
    245                 usb_log_warning("Failed to add buttons to report path.\n");
    246                 return true;
    247         }
     280        usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_BUTTON, 0);
    248281        usb_hid_report_path_set_report_id(path, hid_dev->report_id);
    249 
     282       
    250283        usb_hid_report_field_t *field = usb_hid_report_get_sibling(
    251             &hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END
    252             | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, USB_HID_REPORT_TYPE_INPUT);
     284            hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END
     285            | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,
     286            USB_HID_REPORT_TYPE_INPUT);
    253287
    254288        while (field != NULL) {
    255289                usb_log_debug2(NAME " VALUE(%X) USAGE(%X)\n", field->value,
    256290                    field->usage);
    257                 assert(field->usage > field->usage_minimum);
    258                 const unsigned index = field->usage - field->usage_minimum;
    259                 assert(index < mouse_dev->buttons_count);
    260 
    261                 if (mouse_dev->buttons[index] == 0 && field->value != 0) {
    262                         async_exch_t *exch =
    263                             async_exchange_begin(mouse_dev->mouse_sess);
    264                         if (exch != NULL) {
    265                                 async_req_2_0(exch, MOUSEEV_BUTTON_EVENT,
    266                                     field->usage, 1);
    267                                 async_exchange_end(exch);
    268                                 mouse_dev->buttons[index] = field->value;
    269                         }
    270 
    271                 } else if (mouse_dev->buttons[index] != 0 && field->value == 0) {
    272                         async_exch_t *exch =
    273                             async_exchange_begin(mouse_dev->mouse_sess);
    274                         if (exch != NULL) {
    275                                 async_req_2_0(exch, MOUSEEV_BUTTON_EVENT,
    276                                     field->usage, 0);
    277                                 async_exchange_end(exch);
    278                                 mouse_dev->buttons[index] = field->value;
    279                         }
     291               
     292                if (mouse_dev->buttons[field->usage - field->usage_minimum] == 0
     293                    && field->value != 0) {
     294                        async_obsolete_req_2_0(mouse_dev->mouse_phone,
     295                            MOUSEEV_BUTTON_EVENT, field->usage, 1);
     296                        mouse_dev->buttons[field->usage - field->usage_minimum]
     297                            = field->value;
     298                } else if (mouse_dev->buttons[field->usage - field->usage_minimum] != 0
     299                    && field->value == 0) {
     300                        async_obsolete_req_2_0(mouse_dev->mouse_phone,
     301                           MOUSEEV_BUTTON_EVENT, field->usage, 0);
     302                        mouse_dev->buttons[field->usage - field->usage_minimum] =
     303                           field->value;
    280304                }
    281 
     305               
    282306                field = usb_hid_report_get_sibling(
    283                     &hid_dev->report, field, path, USB_HID_PATH_COMPARE_END
    284                     | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,
     307                    hid_dev->report, field, path, USB_HID_PATH_COMPARE_END
     308                    | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 
    285309                    USB_HID_REPORT_TYPE_INPUT);
    286310        }
    287 
     311       
    288312        usb_hid_report_path_free(path);
    289313
    290314        return true;
    291315}
    292 /*----------------------------------------------------------------------------*/
    293 #define FUN_UNBIND_DESTROY(fun) \
    294 if (fun) { \
    295         if (ddf_fun_unbind((fun)) == EOK) { \
    296                 (fun)->driver_data = NULL; \
    297                 ddf_fun_destroy((fun)); \
    298         } else { \
    299                 usb_log_error("Could not unbind function `%s', it " \
    300                     "will not be destroyed.\n", (fun)->name); \
    301         } \
    302 } else (void)0
    303 /*----------------------------------------------------------------------------*/
     316
     317/*----------------------------------------------------------------------------*/
     318
    304319static int usb_mouse_create_function(usb_hid_dev_t *hid_dev, usb_mouse_t *mouse)
    305320{
    306321        assert(hid_dev != NULL);
    307322        assert(mouse != NULL);
    308 
     323       
    309324        /* Create the exposed function. */
    310325        usb_log_debug("Creating DDF function %s...\n", HID_MOUSE_FUN_NAME);
    311         ddf_fun_t *fun = ddf_fun_create(hid_dev->usb_dev->ddf_dev, fun_exposed,
     326        ddf_fun_t *fun = ddf_fun_create(hid_dev->usb_dev->ddf_dev, fun_exposed, 
    312327            HID_MOUSE_FUN_NAME);
    313328        if (fun == NULL) {
    314                 usb_log_error("Could not create DDF function node `%s'.\n",
    315                     HID_MOUSE_FUN_NAME);
     329                usb_log_error("Could not create DDF function node.\n");
    316330                return ENOMEM;
    317331        }
    318 
     332       
    319333        fun->ops = &mouse->ops;
    320334        fun->driver_data = mouse;
     
    322336        int rc = ddf_fun_bind(fun);
    323337        if (rc != EOK) {
    324                 usb_log_error("Could not bind DDF function `%s': %s.\n",
    325                     fun->name, str_error(rc));
    326                 fun->driver_data = NULL;
     338                usb_log_error("Could not bind DDF function: %s.\n",
     339                    str_error(rc));
    327340                ddf_fun_destroy(fun);
    328341                return rc;
    329342        }
    330 
    331         usb_log_debug("Adding DDF function `%s' to category %s...\n",
    332             fun->name, HID_MOUSE_CATEGORY);
     343       
     344        usb_log_debug("Adding DDF function to category %s...\n",
     345            HID_MOUSE_CATEGORY);
    333346        rc = ddf_fun_add_to_category(fun, HID_MOUSE_CATEGORY);
    334347        if (rc != EOK) {
     
    336349                    "Could not add DDF function to category %s: %s.\n",
    337350                    HID_MOUSE_CATEGORY, str_error(rc));
    338                 FUN_UNBIND_DESTROY(fun);
    339                 return rc;
    340         }
    341         mouse->mouse_fun = fun;
    342 
     351                ddf_fun_destroy(fun);
     352                return rc;
     353        }
     354       
    343355        /*
    344356         * Special function for acting as keyboard (wheel)
    345357         */
    346         usb_log_debug("Creating DDF function %s...\n",
     358        usb_log_debug("Creating DDF function %s...\n", 
    347359                      HID_MOUSE_WHEEL_FUN_NAME);
    348         fun = ddf_fun_create(hid_dev->usb_dev->ddf_dev, fun_exposed,
     360        fun = ddf_fun_create(hid_dev->usb_dev->ddf_dev, fun_exposed, 
    349361            HID_MOUSE_WHEEL_FUN_NAME);
    350362        if (fun == NULL) {
    351                 usb_log_error("Could not create DDF function node `%s'.\n",
    352                     HID_MOUSE_WHEEL_FUN_NAME);
    353                 FUN_UNBIND_DESTROY(mouse->mouse_fun);
    354                 mouse->mouse_fun = NULL;
     363                usb_log_error("Could not create DDF function node.\n");
    355364                return ENOMEM;
    356365        }
    357 
     366       
    358367        /*
    359368         * Store the initialized HID device and HID ops
     
    365374        rc = ddf_fun_bind(fun);
    366375        if (rc != EOK) {
    367                 usb_log_error("Could not bind DDF function `%s': %s.\n",
    368                     fun->name, str_error(rc));
    369                 FUN_UNBIND_DESTROY(mouse->mouse_fun);
    370                 mouse->mouse_fun = NULL;
    371 
    372                 fun->driver_data = NULL;
     376                usb_log_error("Could not bind DDF function: %s.\n",
     377                    str_error(rc));
    373378                ddf_fun_destroy(fun);
    374379                return rc;
    375380        }
    376 
     381       
    377382        usb_log_debug("Adding DDF function to category %s...\n",
    378383            HID_MOUSE_WHEEL_CATEGORY);
     
    382387                    "Could not add DDF function to category %s: %s.\n",
    383388                    HID_MOUSE_WHEEL_CATEGORY, str_error(rc));
    384 
    385                 FUN_UNBIND_DESTROY(mouse->mouse_fun);
    386                 mouse->mouse_fun = NULL;
    387                 FUN_UNBIND_DESTROY(fun);
    388                 return rc;
    389         }
    390         mouse->wheel_fun = fun;
    391 
     389                ddf_fun_destroy(fun);
     390                return rc;
     391        }
     392       
    392393        return EOK;
    393394}
     
    395396/*----------------------------------------------------------------------------*/
    396397
    397 /** Get highest index of a button mentioned in given report.
    398  *
    399  * @param report HID report.
    400  * @param report_id Report id we are interested in.
    401  * @return Highest button mentioned in the report.
    402  * @retval 1 No button was mentioned.
    403  *
    404  */
    405 static size_t usb_mouse_get_highest_button(usb_hid_report_t *report, uint8_t report_id)
    406 {
    407         size_t highest_button = 0;
    408 
    409         usb_hid_report_path_t *path = usb_hid_report_path();
    410         usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_BUTTON, 0);
    411         usb_hid_report_path_set_report_id(path, report_id);
    412 
    413         usb_hid_report_field_t *field = NULL;
    414 
    415         /* Break from within. */
    416         while (1) {
    417                 field = usb_hid_report_get_sibling(
    418                     report, field, path,
    419                     USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,
    420                     USB_HID_REPORT_TYPE_INPUT);
    421                 /* No more buttons? */
    422                 if (field == NULL) {
    423                         break;
    424                 }
    425 
    426                 size_t current_button = field->usage - field->usage_minimum;
    427                 if (current_button > highest_button) {
    428                         highest_button = current_button;
    429                 }
    430         }
    431 
    432         usb_hid_report_path_free(path);
    433 
    434         return highest_button;
    435 }
    436 /*----------------------------------------------------------------------------*/
    437398int usb_mouse_init(usb_hid_dev_t *hid_dev, void **data)
    438399{
    439400        usb_log_debug("Initializing HID/Mouse structure...\n");
    440 
     401       
    441402        if (hid_dev == NULL) {
    442403                usb_log_error("Failed to init keyboard structure: no structure"
     
    444405                return EINVAL;
    445406        }
    446 
    447         usb_mouse_t *mouse_dev = calloc(1, sizeof(usb_mouse_t));
     407       
     408        usb_mouse_t *mouse_dev = usb_mouse_new();
    448409        if (mouse_dev == NULL) {
    449410                usb_log_error("Error while creating USB/HID Mouse device "
     
    451412                return ENOMEM;
    452413        }
    453 
    454         // FIXME: This may not be optimal since stupid hardware vendor may
    455         // use buttons 1, 2, 3 and 6000 and we would allocate array of
    456         // 6001*4B and use only 4 items in it.
    457         // Since I doubt that hardware producers would do that, I think
    458         // that the current solution is good enough.
    459         /* Adding 1 because we will be accessing buttons[highest]. */
    460         mouse_dev->buttons_count = 1 + usb_mouse_get_highest_button(
    461             &hid_dev->report, hid_dev->report_id);
    462         mouse_dev->buttons = calloc(mouse_dev->buttons_count, sizeof(int32_t));
    463 
     414       
     415        mouse_dev->buttons = (int32_t *)calloc(USB_MOUSE_BUTTON_COUNT,
     416            sizeof(int32_t));
     417       
    464418        if (mouse_dev->buttons == NULL) {
    465                 usb_log_error(NAME ": out of memory, giving up on device!\n");
     419                usb_log_fatal("No memory!\n");
    466420                free(mouse_dev);
    467421                return ENOMEM;
    468422        }
    469 
     423       
     424        // save the Mouse device structure into the HID device structure
     425        *data = mouse_dev;
     426       
    470427        // set handler for incoming calls
    471428        mouse_dev->ops.default_handler = default_connection_handler;
    472 
     429       
    473430        // TODO: how to know if the device supports the request???
    474         usbhid_req_set_idle(&hid_dev->usb_dev->ctrl_pipe,
     431        usbhid_req_set_idle(&hid_dev->usb_dev->ctrl_pipe, 
    475432            hid_dev->usb_dev->interface_no, IDLE_RATE);
    476 
     433       
    477434        int rc = usb_mouse_create_function(hid_dev, mouse_dev);
    478435        if (rc != EOK) {
    479                 free(mouse_dev->buttons);
    480                 free(mouse_dev);
    481                 return rc;
    482         }
    483 
    484         /* Save the Mouse device structure into the HID device structure. */
    485         *data = mouse_dev;
    486 
     436                usb_mouse_destroy(mouse_dev);
     437                return rc;
     438        }
     439       
    487440        return EOK;
    488441}
    489 /*----------------------------------------------------------------------------*/
     442
     443/*----------------------------------------------------------------------------*/
     444
    490445bool usb_mouse_polling_callback(usb_hid_dev_t *hid_dev, void *data)
    491446{
    492447        if (hid_dev == NULL || data == NULL) {
    493                 usb_log_error(
    494                     "Missing argument to the mouse polling callback.\n");
     448                usb_log_error("Missing argument to the mouse polling callback."
     449                    "\n");
    495450                return false;
    496451        }
    497 
    498         usb_mouse_t *mouse_dev = data;
    499 
     452       
     453        usb_mouse_t *mouse_dev = (usb_mouse_t *)data;
     454               
    500455        return usb_mouse_process_report(hid_dev, mouse_dev);
    501456}
    502 /*----------------------------------------------------------------------------*/
     457
     458/*----------------------------------------------------------------------------*/
     459
    503460void usb_mouse_deinit(usb_hid_dev_t *hid_dev, void *data)
    504461{
    505         if (data == NULL)
    506                 return;
    507 
    508         usb_mouse_t *mouse_dev = data;
    509 
    510         /* Hangup session to the console */
    511         if (mouse_dev->mouse_sess != NULL) {
    512                 const int ret = async_hangup(mouse_dev->mouse_sess);
    513                 if (ret != EOK)
    514                         usb_log_warning("Failed to hang up mouse session: "
    515                             "%p, %s.\n", mouse_dev->mouse_sess, str_error(ret));
    516         }
    517 
    518         if (mouse_dev->wheel_sess != NULL) {
    519                 const int ret = async_hangup(mouse_dev->wheel_sess);
    520                 if (ret != EOK)
    521                         usb_log_warning("Failed to hang up wheel session: "
    522                             "%p, %s.\n", mouse_dev->wheel_sess, str_error(ret));
    523         }
    524 
    525         FUN_UNBIND_DESTROY(mouse_dev->mouse_fun);
    526         FUN_UNBIND_DESTROY(mouse_dev->wheel_fun);
    527 
    528         free(mouse_dev->buttons);
    529         free(mouse_dev);
    530 }
    531 /*----------------------------------------------------------------------------*/
     462        if (data != NULL) {
     463                usb_mouse_destroy((usb_mouse_t *)data);
     464        }
     465}
     466
     467/*----------------------------------------------------------------------------*/
     468
    532469int usb_mouse_set_boot_protocol(usb_hid_dev_t *hid_dev)
    533470{
    534         int rc = usb_hid_parse_report_descriptor(
    535             &hid_dev->report, USB_MOUSE_BOOT_REPORT_DESCRIPTOR,
    536             sizeof(USB_MOUSE_BOOT_REPORT_DESCRIPTOR));
    537 
     471        int rc = usb_hid_parse_report_descriptor(hid_dev->report,
     472            USB_MOUSE_BOOT_REPORT_DESCRIPTOR,
     473            USB_MOUSE_BOOT_REPORT_DESCRIPTOR_SIZE);
     474       
    538475        if (rc != EOK) {
    539476                usb_log_error("Failed to parse boot report descriptor: %s\n",
     
    541478                return rc;
    542479        }
    543 
    544         rc = usbhid_req_set_protocol(&hid_dev->usb_dev->ctrl_pipe,
     480       
     481        rc = usbhid_req_set_protocol(&hid_dev->usb_dev->ctrl_pipe, 
    545482            hid_dev->usb_dev->interface_no, USB_HID_PROTOCOL_BOOT);
    546 
     483       
    547484        if (rc != EOK) {
    548485                usb_log_warning("Failed to set boot protocol to the device: "
     
    550487                return rc;
    551488        }
    552 
     489       
    553490        return EOK;
    554491}
Note: See TracChangeset for help on using the changeset viewer.