Ignore:
Timestamp:
2018-02-28T16:37:50Z (6 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1b20da0
Parents:
f5e5f73 (diff), b2dca8de (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.
git-author:
Jakub Jermar <jakub@…> (2018-02-28 16:06:42)
git-committer:
Jakub Jermar <jakub@…> (2018-02-28 16:37:50)
Message:

Merge github.com:helenos-xhci-team/helenos

This commit merges support for USB 3 and generally refactors, fixes,
extends and cleans up the existing USB framework.

Notable additions and features:

  • new host controller driver has been implemented to control various xHC models (among others, NEC Renesas uPD720200)
  • isochronous data transfer mode
  • support for explicit USB device removal
  • USB tablet driver
File:
1 edited

Legend:

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

    rf5e5f73 rdf6ded8  
    11/*
    22 * Copyright (c) 2011 Lubos Slovak, Vojtech Horky
     3 * Copyright (c) 2018 Ondrej Hlavaty
    34 * All rights reserved.
    45 *
     
    118119
    119120        if (mouse_dev == NULL) {
    120                 usb_log_debug("%s: Missing parameters.\n", __FUNCTION__);
     121                usb_log_debug("%s: Missing parameters.", __FUNCTION__);
    121122                async_answer_0(icallid, EINVAL);
    122123                return;
    123124        }
    124125
    125         usb_log_debug("%s: fun->name: %s\n", __FUNCTION__, ddf_fun_get_name(fun));
    126         usb_log_debug("%s: mouse_sess: %p\n",
     126        usb_log_debug("%s: fun->name: %s", __FUNCTION__, ddf_fun_get_name(fun));
     127        usb_log_debug("%s: mouse_sess: %p",
    127128            __FUNCTION__, mouse_dev->mouse_sess);
    128129
     
    132133                if (mouse_dev->mouse_sess == NULL) {
    133134                        mouse_dev->mouse_sess = sess;
    134                         usb_log_debug("Console session to %s set ok (%p).\n",
     135                        usb_log_debug("Console session to %s set ok (%p).",
    135136                            ddf_fun_get_name(fun), sess);
    136137                        async_answer_0(icallid, EOK);
    137138                } else {
    138                         usb_log_error("Console session to %s already set.\n",
     139                        usb_log_error("Console session to %s already set.",
    139140                            ddf_fun_get_name(fun));
    140141                        async_answer_0(icallid, ELIMIT);
     
    142143                }
    143144        } else {
    144                 usb_log_debug("%s: Invalid function.\n", __FUNCTION__);
     145                usb_log_debug("%s: Invalid function.", __FUNCTION__);
    145146                async_answer_0(icallid, EINVAL);
    146147        }
    147148}
    148149
    149 static int get_mouse_axis_move_value(uint8_t rid, usb_hid_report_t *report,
     150static const usb_hid_report_field_t *get_mouse_axis_move_field(uint8_t rid, usb_hid_report_t *report,
    150151    int32_t usage)
    151152{
    152         int result = 0;
    153 
    154153        usb_hid_report_path_t *path = usb_hid_report_path();
    155154        usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_GENERIC_DESKTOP,
     
    158157        usb_hid_report_path_set_report_id(path, rid);
    159158
    160         usb_hid_report_field_t *field = usb_hid_report_get_sibling(
     159        const usb_hid_report_field_t *field = usb_hid_report_get_sibling(
    161160            report, NULL, path, USB_HID_PATH_COMPARE_END,
    162161            USB_HID_REPORT_TYPE_INPUT);
    163162
    164         if (field != NULL) {
    165                 result = field->value;
    166         }
    167 
    168163        usb_hid_report_path_free(path);
    169164
    170         return result;
    171 }
    172 
    173 static bool usb_mouse_process_report(usb_hid_dev_t *hid_dev,
     165        return field;
     166}
     167
     168static void usb_mouse_process_report(usb_hid_dev_t *hid_dev,
    174169    usb_mouse_t *mouse_dev)
    175170{
     
    177172
    178173        if (mouse_dev->mouse_sess == NULL) {
    179                 usb_log_warning(NAME " No console session.\n");
    180                 return true;
    181         }
    182 
    183         const int shift_x = get_mouse_axis_move_value(hid_dev->report_id,
    184             &hid_dev->report, USB_HIDUT_USAGE_GENERIC_DESKTOP_X);
    185         const int shift_y = get_mouse_axis_move_value(hid_dev->report_id,
    186             &hid_dev->report, USB_HIDUT_USAGE_GENERIC_DESKTOP_Y);
    187         const int wheel = get_mouse_axis_move_value(hid_dev->report_id,
    188             &hid_dev->report, USB_HIDUT_USAGE_GENERIC_DESKTOP_WHEEL);
    189 
    190         if (shift_x || shift_y || wheel) {
     174                usb_log_warning(NAME " No console session.");
     175                return;
     176        }
     177
     178        const usb_hid_report_field_t *move_x = get_mouse_axis_move_field(
     179            hid_dev->report_id, &hid_dev->report,
     180            USB_HIDUT_USAGE_GENERIC_DESKTOP_X);
     181        const usb_hid_report_field_t *move_y = get_mouse_axis_move_field(
     182            hid_dev->report_id, &hid_dev->report,
     183            USB_HIDUT_USAGE_GENERIC_DESKTOP_Y);
     184        const usb_hid_report_field_t *wheel= get_mouse_axis_move_field(
     185            hid_dev->report_id, &hid_dev->report,
     186            USB_HIDUT_USAGE_GENERIC_DESKTOP_WHEEL);
     187
     188        bool absolute_x = move_x && !USB_HID_ITEM_FLAG_RELATIVE(move_x->item_flags);
     189        bool absolute_y = move_y && !USB_HID_ITEM_FLAG_RELATIVE(move_y->item_flags);
     190
     191        /* Tablet shall always report both X and Y */
     192        if (absolute_x != absolute_y) {
     193                usb_log_error(NAME " cannot handle mix of absolute and relative mouse move.");
     194                return;
     195        }
     196
     197        int shift_x = move_x ? move_x->value : 0;
     198        int shift_y = move_y ? move_y->value : 0;
     199        int shift_z =  wheel ?  wheel->value : 0;
     200
     201        if (absolute_x && absolute_y) {
     202                async_exch_t *exch =
     203                    async_exchange_begin(mouse_dev->mouse_sess);
     204                if (exch != NULL) {
     205                        async_msg_4(exch, MOUSEEV_ABS_MOVE_EVENT,
     206                            shift_x, shift_y, move_x->logical_maximum, move_y->logical_maximum);
     207                        async_exchange_end(exch);
     208                }
     209
     210                // Even if we move the mouse absolutely, we need to resolve wheel
     211                shift_x = shift_y = 0;
     212        }
     213
     214
     215        if (shift_x || shift_y || shift_z) {
    191216                async_exch_t *exch =
    192217                    async_exchange_begin(mouse_dev->mouse_sess);
    193218                if (exch != NULL) {
    194219                        async_msg_3(exch, MOUSEEV_MOVE_EVENT,
    195                             shift_x, shift_y, wheel);
     220                            shift_x, shift_y, shift_z);
    196221                        async_exchange_end(exch);
    197222                }
     
    201226        usb_hid_report_path_t *path = usb_hid_report_path();
    202227        if (path == NULL) {
    203                 usb_log_warning("Failed to create USB HID report path.\n");
    204                 return true;
     228                usb_log_warning("Failed to create USB HID report path.");
     229                return;
    205230        }
    206231        errno_t ret =
     
    208233        if (ret != EOK) {
    209234                usb_hid_report_path_free(path);
    210                 usb_log_warning("Failed to add buttons to report path.\n");
    211                 return true;
     235                usb_log_warning("Failed to add buttons to report path.");
     236                return;
    212237        }
    213238        usb_hid_report_path_set_report_id(path, hid_dev->report_id);
     
    218243
    219244        while (field != NULL) {
    220                 usb_log_debug2(NAME " VALUE(%X) USAGE(%X)\n", field->value,
     245                usb_log_debug2(NAME " VALUE(%X) USAGE(%X)", field->value,
    221246                    field->usage);
    222247                assert(field->usage > field->usage_minimum);
     
    242267
    243268        usb_hid_report_path_free(path);
    244 
    245         return true;
    246269}
    247270
     
    309332
    310333        if (mouse_dev->buttons == NULL) {
    311                 usb_log_error(NAME ": out of memory, giving up on device!\n");
     334                usb_log_error(NAME ": out of memory, giving up on device!");
    312335                free(mouse_dev);
    313336                return ENOMEM;
     
    322345errno_t usb_mouse_init(usb_hid_dev_t *hid_dev, void **data)
    323346{
    324         usb_log_debug("Initializing HID/Mouse structure...\n");
     347        usb_log_debug("Initializing HID/Mouse structure...");
    325348
    326349        if (hid_dev == NULL) {
     
    331354
    332355        /* Create the exposed function. */
    333         usb_log_debug("Creating DDF function %s...\n", HID_MOUSE_FUN_NAME);
     356        usb_log_debug("Creating DDF function %s...", HID_MOUSE_FUN_NAME);
    334357        ddf_fun_t *fun = usb_device_ddf_fun_create(hid_dev->usb_dev,
    335358            fun_exposed, HID_MOUSE_FUN_NAME);
    336359        if (fun == NULL) {
    337                 usb_log_error("Could not create DDF function node `%s'.\n",
     360                usb_log_error("Could not create DDF function node `%s'.",
    338361                    HID_MOUSE_FUN_NAME);
    339362                return ENOMEM;
     
    342365        usb_mouse_t *mouse_dev = ddf_fun_data_alloc(fun, sizeof(usb_mouse_t));
    343366        if (mouse_dev == NULL) {
    344                 usb_log_error("Failed to alloc HID mouse device structure.\n");
     367                usb_log_error("Failed to alloc HID mouse device structure.");
    345368                ddf_fun_destroy(fun);
    346369                return ENOMEM;
     
    349372        errno_t ret = mouse_dev_init(mouse_dev, hid_dev);
    350373        if (ret != EOK) {
    351                 usb_log_error("Failed to init HID mouse device structure.\n");
     374                usb_log_error("Failed to init HID mouse device structure.");
    352375                return ret;
    353376        }
     
    357380        ret = ddf_fun_bind(fun);
    358381        if (ret != EOK) {
    359                 usb_log_error("Could not bind DDF function `%s': %s.\n",
     382                usb_log_error("Could not bind DDF function `%s': %s.",
    360383                    ddf_fun_get_name(fun), str_error(ret));
    361384                ddf_fun_destroy(fun);
     
    363386        }
    364387
    365         usb_log_debug("Adding DDF function `%s' to category %s...\n",
     388        usb_log_debug("Adding DDF function `%s' to category %s...",
    366389            ddf_fun_get_name(fun), HID_MOUSE_CATEGORY);
    367390        ret = ddf_fun_add_to_category(fun, HID_MOUSE_CATEGORY);
     
    390413
    391414        usb_mouse_t *mouse_dev = data;
    392 
    393         return usb_mouse_process_report(hid_dev, mouse_dev);
     415        usb_mouse_process_report(hid_dev, mouse_dev);
     416
     417        /* Continue polling until the device is about to be removed. */
     418        return true;
    394419}
    395420
     
    420445
    421446        if (rc != EOK) {
    422                 usb_log_error("Failed to parse boot report descriptor: %s\n",
     447                usb_log_error("Failed to parse boot report descriptor: %s",
    423448                    str_error(rc));
    424449                return rc;
Note: See TracChangeset for help on using the changeset viewer.