Ignore:
Timestamp:
2011-09-04T11:30:58Z (13 years ago)
Author:
Maurizio Lombardi <m.lombardi85@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
03bc76a
Parents:
d2c67e7 (diff), deac215e (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 mainline changes

File:
1 moved

Legend:

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

    rd2c67e7 r8ff0bd2  
    4444#include <async_obsolete.h>
    4545#include <str_error.h>
    46 #include <ipc/mouse.h>
     46#include <ipc/mouseev.h>
    4747#include <io/console.h>
    4848
    49 #include <ipc/kbd.h>
     49#include <ipc/kbdev.h>
    5050#include <io/keycode.h>
    5151
     
    5353#include "../usbhid.h"
    5454
     55/** Number of simulated arrow-key presses for singel wheel step. */
     56#define ARROWS_PER_SINGLE_WHEEL 3
     57
    5558// FIXME: remove this header
    56 #include <kernel/ipc/ipc_methods.h>
     59#include <abi/ipc/methods.h>
    5760
    5861#define NAME "mouse"
     
    7174const char *HID_MOUSE_FUN_NAME = "mouse";
    7275const char *HID_MOUSE_WHEEL_FUN_NAME = "mouse-wheel";
    73 const char *HID_MOUSE_CLASS_NAME = "mouse";
    74 const char *HID_MOUSE_WHEEL_CLASS_NAME = "keyboard";
     76const char *HID_MOUSE_CATEGORY = "mouse";
     77const char *HID_MOUSE_WHEEL_CATEGORY = "keyboard";
    7578
    7679/** Default idle rate for mouses. */
     
    180183/*----------------------------------------------------------------------------*/
    181184
    182 static void usb_mouse_free(usb_mouse_t **mouse_dev)
    183 {
    184         assert(mouse_dev != NULL && *mouse_dev != NULL);
     185static void usb_mouse_destroy(usb_mouse_t *mouse_dev)
     186{
     187        assert(mouse_dev != NULL);
    185188       
    186189        // hangup phone to the console
    187         if ((*mouse_dev)->mouse_phone >= 0) {
    188                 async_obsolete_hangup((*mouse_dev)->mouse_phone);
    189         }
    190        
    191         if ((*mouse_dev)->wheel_phone >= 0) {
    192                 async_obsolete_hangup((*mouse_dev)->wheel_phone);
    193         }
    194        
    195         free(*mouse_dev);
    196         *mouse_dev = NULL;
     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);
     196        }
    197197}
    198198
     
    201201static void usb_mouse_send_wheel(const usb_mouse_t *mouse_dev, int wheel)
    202202{
    203         kbd_event_t ev;
    204        
    205         ev.type = KEY_PRESS;
    206         ev.key = (wheel > 0) ? KC_UP : (wheel < 0) ? KC_DOWN : 0;
    207         ev.mods = 0;
    208         ev.c = 0;
     203        unsigned int key = (wheel > 0) ? KC_UP : KC_DOWN;
    209204
    210205        if (mouse_dev->wheel_phone < 0) {
    211206                usb_log_warning(
    212                     "Connection to console not ready, key discarded.\n");
     207                    "Connection to console not ready, wheel roll discarded.\n");
    213208                return;
    214209        }
    215210       
    216         int count = (wheel < 0) ? -wheel : wheel;
     211        int count = ((wheel < 0) ? -wheel : wheel) * ARROWS_PER_SINGLE_WHEEL;
    217212        int i;
    218213       
    219         for (i = 0; i < count * 3; ++i) {
    220                 usb_log_debug2("Sending key %d to the console\n", ev.key);
    221                 async_obsolete_msg_4(mouse_dev->wheel_phone, KBD_EVENT, ev.type,
    222                     ev.key, ev.mods, ev.c);
    223                 // send key release right away
    224                 async_obsolete_msg_4(mouse_dev->wheel_phone, KBD_EVENT, KEY_RELEASE,
    225                     ev.key, ev.mods, ev.c);
    226         }
    227 }
    228 
    229 /*----------------------------------------------------------------------------*/
    230 
    231 static bool usb_mouse_process_report(usb_hid_dev_t *hid_dev,
    232                                      usb_mouse_t *mouse_dev, uint8_t *buffer,
    233                                      size_t buffer_size)
     214        for (i = 0; i < count; i++) {
     215                /* Send arrow press and release. */
     216                usb_log_debug2("Sending key %d to the console\n", key);
     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);
     221        }
     222}
     223
     224/*----------------------------------------------------------------------------*/
     225
     226static int get_mouse_axis_move_value(uint8_t rid, usb_hid_report_t *report,
     227    int32_t usage)
     228{
     229        int result = 0;
     230
     231        usb_hid_report_path_t *path = usb_hid_report_path();
     232        usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_GENERIC_DESKTOP,
     233            usage);
     234
     235        usb_hid_report_path_set_report_id(path, rid);
     236
     237        usb_hid_report_field_t *field = usb_hid_report_get_sibling(
     238            report, NULL, path, USB_HID_PATH_COMPARE_END,
     239            USB_HID_REPORT_TYPE_INPUT);
     240
     241        if (field != NULL) {
     242                result = field->value;
     243        }
     244
     245        usb_hid_report_path_free(path);
     246
     247        return result;
     248}
     249
     250static bool usb_mouse_process_report(usb_hid_dev_t *hid_dev,
     251    usb_mouse_t *mouse_dev)
    234252{
    235253        assert(mouse_dev != NULL);
    236        
    237         usb_log_debug2("got buffer: %s.\n",
    238             usb_debug_str_buffer(buffer, buffer_size, 0));
    239254       
    240255        if (mouse_dev->mouse_phone < 0) {
     
    243258        }
    244259
    245         /*
    246          * parse the input report
    247          */
    248        
    249         usb_log_debug(NAME " Calling usb_hid_parse_report() with "
    250             "buffer %s\n", usb_debug_str_buffer(buffer, buffer_size, 0));
    251        
    252         uint8_t report_id;
    253        
    254         int rc = usb_hid_parse_report(hid_dev->report, buffer, buffer_size,
    255             &report_id);
    256        
    257         if (rc != EOK) {
    258                 usb_log_warning(NAME "Error in usb_hid_parse_report(): %s\n",
    259                     str_error(rc));
    260                 return true;
    261         }
    262        
    263         /*
    264          * X
    265          */
    266         int shift_x = 0;
    267        
    268         usb_hid_report_path_t *path = usb_hid_report_path();
    269         usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_GENERIC_DESKTOP,
    270             USB_HIDUT_USAGE_GENERIC_DESKTOP_X);
    271 
    272         usb_hid_report_path_set_report_id(path, report_id);
    273 
    274         usb_hid_report_field_t *field = usb_hid_report_get_sibling(
    275             hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END,
    276             USB_HID_REPORT_TYPE_INPUT);
    277 
    278         if (field != NULL) {
    279                 usb_log_debug(NAME " VALUE(%X) USAGE(%X)\n", field->value,
    280                     field->usage);
    281                 shift_x = field->value;
    282         }
    283 
    284         usb_hid_report_path_free(path);
    285        
    286         /*
    287          * Y
    288          */
    289         int shift_y = 0;
    290        
    291         path = usb_hid_report_path();
    292         usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_GENERIC_DESKTOP,
    293             USB_HIDUT_USAGE_GENERIC_DESKTOP_Y);
    294 
    295         usb_hid_report_path_set_report_id(path, report_id);
    296 
    297         field = usb_hid_report_get_sibling(
    298             hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END,
    299             USB_HID_REPORT_TYPE_INPUT);
    300 
    301         if (field != NULL) {
    302                 usb_log_debug(NAME " VALUE(%X) USAGE(%X)\n", field->value,
    303                     field->usage);
    304                 shift_y = field->value;
    305         }
    306 
    307         usb_hid_report_path_free(path);
    308        
     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);
     266
    309267        if ((shift_x != 0) || (shift_y != 0)) {
    310268                async_obsolete_req_2_0(mouse_dev->mouse_phone,
    311                     MEVENT_MOVE, shift_x, shift_y);
    312         }
    313        
    314         /*
    315          * Wheel
    316          */
    317         int wheel = 0;
    318        
    319         path = usb_hid_report_path();
    320         usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_GENERIC_DESKTOP,
    321             USB_HIDUT_USAGE_GENERIC_DESKTOP_WHEEL);
    322 
    323         usb_hid_report_path_set_report_id(path, report_id);
    324        
    325         field = usb_hid_report_get_sibling(
    326             hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END,
    327             USB_HID_REPORT_TYPE_INPUT);
    328 
    329         if (field != NULL) {
    330                 usb_log_debug(NAME " VALUE(%X) USAGE(%X)\n", field->value,
    331                     field->usage);
    332                 wheel = field->value;
    333         }
    334 
    335         usb_hid_report_path_free(path);
    336        
    337         // send arrow up for positive direction and arrow down for negative
    338         // direction; three arrows for difference of 1
    339         usb_mouse_send_wheel(mouse_dev, wheel);
    340        
     269                    MOUSEEV_MOVE_EVENT, shift_x, shift_y);
     270        }
     271
     272        if (wheel != 0) {
     273                usb_mouse_send_wheel(mouse_dev, wheel);
     274        }
    341275       
    342276        /*
    343277         * Buttons
    344278         */
    345         path = usb_hid_report_path();
     279        usb_hid_report_path_t *path = usb_hid_report_path();
    346280        usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_BUTTON, 0);
    347         usb_hid_report_path_set_report_id(path, report_id);
    348        
    349         field = usb_hid_report_get_sibling(
     281        usb_hid_report_path_set_report_id(path, hid_dev->report_id);
     282       
     283        usb_hid_report_field_t *field = usb_hid_report_get_sibling(
    350284            hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END
    351285            | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,
     
    353287
    354288        while (field != NULL) {
    355                 usb_log_debug(NAME " VALUE(%X) USAGE(%X)\n", field->value,
     289                usb_log_debug2(NAME " VALUE(%X) USAGE(%X)\n", field->value,
    356290                    field->usage);
    357291               
     
    359293                    && field->value != 0) {
    360294                        async_obsolete_req_2_0(mouse_dev->mouse_phone,
    361                             MEVENT_BUTTON, field->usage, 1);
     295                            MOUSEEV_BUTTON_EVENT, field->usage, 1);
    362296                        mouse_dev->buttons[field->usage - field->usage_minimum]
    363297                            = field->value;
    364                 } else if (
    365                     mouse_dev->buttons[field->usage - field->usage_minimum] != 0
     298                } else if (mouse_dev->buttons[field->usage - field->usage_minimum] != 0
    366299                    && field->value == 0) {
    367                        async_obsolete_req_2_0(mouse_dev->mouse_phone,
    368                            MEVENT_BUTTON, field->usage, 0);
    369                        mouse_dev->buttons[field->usage - field->usage_minimum]
    370                            = field->value;
    371                }
     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;
     304                }
    372305               
    373306                field = usb_hid_report_get_sibling(
     
    389322        assert(mouse != NULL);
    390323       
    391         /* Create the function exposed under /dev/devices. */
     324        /* Create the exposed function. */
    392325        usb_log_debug("Creating DDF function %s...\n", HID_MOUSE_FUN_NAME);
    393326        ddf_fun_t *fun = ddf_fun_create(hid_dev->usb_dev->ddf_dev, fun_exposed,
     
    409342        }
    410343       
    411         usb_log_debug("Adding DDF function to class %s...\n",
    412             HID_MOUSE_CLASS_NAME);
    413         rc = ddf_fun_add_to_class(fun, HID_MOUSE_CLASS_NAME);
     344        usb_log_debug("Adding DDF function to category %s...\n",
     345            HID_MOUSE_CATEGORY);
     346        rc = ddf_fun_add_to_category(fun, HID_MOUSE_CATEGORY);
    414347        if (rc != EOK) {
    415348                usb_log_error(
    416                     "Could not add DDF function to class %s: %s.\n",
    417                     HID_MOUSE_CLASS_NAME, str_error(rc));
     349                    "Could not add DDF function to category %s: %s.\n",
     350                    HID_MOUSE_CATEGORY, str_error(rc));
    418351                ddf_fun_destroy(fun);
    419352                return rc;
     
    447380        }
    448381       
    449         usb_log_debug("Adding DDF function to class %s...\n",
    450             HID_MOUSE_WHEEL_CLASS_NAME);
    451         rc = ddf_fun_add_to_class(fun, HID_MOUSE_WHEEL_CLASS_NAME);
     382        usb_log_debug("Adding DDF function to category %s...\n",
     383            HID_MOUSE_WHEEL_CATEGORY);
     384        rc = ddf_fun_add_to_category(fun, HID_MOUSE_WHEEL_CATEGORY);
    452385        if (rc != EOK) {
    453386                usb_log_error(
    454                     "Could not add DDF function to class %s: %s.\n",
    455                     HID_MOUSE_WHEEL_CLASS_NAME, str_error(rc));
     387                    "Could not add DDF function to category %s: %s.\n",
     388                    HID_MOUSE_WHEEL_CATEGORY, str_error(rc));
    456389                ddf_fun_destroy(fun);
    457390                return rc;
     
    501434        int rc = usb_mouse_create_function(hid_dev, mouse_dev);
    502435        if (rc != EOK) {
    503                 usb_mouse_free(&mouse_dev);
     436                usb_mouse_destroy(mouse_dev);
    504437                return rc;
    505438        }
     
    510443/*----------------------------------------------------------------------------*/
    511444
    512 bool usb_mouse_polling_callback(usb_hid_dev_t *hid_dev, void *data,
    513      uint8_t *buffer, size_t buffer_size)
    514 {
    515         usb_log_debug("usb_mouse_polling_callback()\n");
    516         usb_debug_str_buffer(buffer, buffer_size, 0);
    517        
     445bool usb_mouse_polling_callback(usb_hid_dev_t *hid_dev, void *data)
     446{
    518447        if (hid_dev == NULL || data == NULL) {
    519448                usb_log_error("Missing argument to the mouse polling callback."
     
    524453        usb_mouse_t *mouse_dev = (usb_mouse_t *)data;
    525454               
    526         return usb_mouse_process_report(hid_dev, mouse_dev, buffer,
    527                                         buffer_size);
     455        return usb_mouse_process_report(hid_dev, mouse_dev);
    528456}
    529457
     
    533461{
    534462        if (data != NULL) {
    535                 usb_mouse_free((usb_mouse_t **)&data);
     463                usb_mouse_destroy((usb_mouse_t *)data);
    536464        }
    537465}
Note: See TracChangeset for help on using the changeset viewer.