Changeset 30710035 in mainline


Ignore:
Timestamp:
2011-04-29T13:14:16Z (14 years ago)
Author:
Lubos Slovak <lubos.slovak@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
31cfee16
Parents:
e67399e
Message:

Mouse driver uses HID parser.

  • Parsing of X and Y - works fine.
  • Parsing of buttons - does not work well, only one button (3) is parsed and even that is not parsed well (value always 0).
  • Remembering pressed buttons - separate reporting of key press and release.
  • Disabled Set Idle request (does not work in qemu).
Location:
uspace
Files:
3 edited

Legend:

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

    re67399e r30710035  
    3939#include <usb/classes/hid.h>
    4040#include <usb/classes/hidreq.h>
     41#include <usb/classes/hidut.h>
    4142#include <errno.h>
    4243#include <str_error.h>
     
    4546#include "mousedev.h"
    4647#include "../usbhid.h"
     48
     49#define NAME "mouse"
    4750
    4851/*----------------------------------------------------------------------------*/
     
    6265/** Default idle rate for mouses. */
    6366static const uint8_t IDLE_RATE = 0;
     67static const size_t USB_MOUSE_BUTTON_COUNT = 3;
    6468
    6569/*----------------------------------------------------------------------------*/
     
    170174/*----------------------------------------------------------------------------*/
    171175
    172 static bool usb_mouse_process_boot_report(usb_mouse_t *mouse_dev,
     176static bool usb_mouse_process_boot_report(usb_hid_dev_t *hid_dev,
    173177    uint8_t *buffer, size_t buffer_size)
    174178{
     179        usb_mouse_t *mouse_dev = (usb_mouse_t *)hid_dev->data;
     180       
    175181        usb_log_debug2("got buffer: %s.\n",
    176182            usb_debug_str_buffer(buffer, buffer_size, 0));
    177 
    178         uint8_t butt = buffer[0];
    179         char str_buttons[4] = {
    180                 butt & 1 ? '#' : '.',
    181                 butt & 2 ? '#' : '.',
    182                 butt & 4 ? '#' : '.',
    183                 0
    184         };
    185 
    186         int shift_x = ((int) buffer[1]) - 127;
    187         int shift_y = ((int) buffer[2]) - 127;
    188         int wheel = ((int) buffer[3]) - 127;
    189 
    190         if (buffer[1] == 0) {
    191                 shift_x = 0;
    192         }
    193         if (buffer[2] == 0) {
    194                 shift_y = 0;
    195         }
    196         if (buffer[3] == 0) {
    197                 wheel = 0;
    198         }
    199        
    200         if (mouse_dev->console_phone >= 0) {
    201                 usb_log_debug("Console phone: %d\n", mouse_dev->console_phone);
    202                 if ((shift_x != 0) || (shift_y != 0)) {
    203                         /* FIXME: guessed for QEMU */
     183       
     184        if (mouse_dev->console_phone < 0) {
     185                usb_log_error(NAME " No console phone.\n");
     186                return false;   // ??
     187        }
     188
     189        /*
     190         * parse the input report
     191         */
     192       
     193        usb_log_debug(NAME " Calling usb_hid_parse_report() with "
     194            "buffer %s\n", usb_debug_str_buffer(buffer, buffer_size, 0));
     195       
     196        uint8_t report_id;
     197       
     198        int rc = usb_hid_parse_report(hid_dev->report, buffer, buffer_size,
     199            &report_id);
     200       
     201        if (rc != EOK) {
     202                usb_log_warning(NAME "Error in usb_hid_parse_report(): %s\n",
     203                    str_error(rc));
     204                return true;
     205        }
     206       
     207        /*
     208         * X
     209         */
     210        int shift_x = 0;
     211       
     212        usb_hid_report_path_t *path = usb_hid_report_path();
     213        usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_GENERIC_DESKTOP,
     214            USB_HIDUT_USAGE_GENERIC_DESKTOP_X);
     215
     216        usb_hid_report_path_set_report_id(path, report_id);
     217
     218        usb_hid_report_field_t *field = usb_hid_report_get_sibling(
     219            hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END,
     220            USB_HID_REPORT_TYPE_INPUT);
     221
     222        if (field != NULL) {
     223                usb_log_debug(NAME " VALUE(%X) USAGE(%X)\n", field->value,
     224                    field->usage);
     225                shift_x = field->value;
     226        }
     227
     228        usb_hid_report_path_free(path);
     229       
     230        /*
     231         * Y
     232         */
     233        int shift_y = 0;
     234       
     235        path = usb_hid_report_path();
     236        usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_GENERIC_DESKTOP,
     237            USB_HIDUT_USAGE_GENERIC_DESKTOP_Y);
     238
     239        usb_hid_report_path_set_report_id(path, report_id);
     240
     241        field = usb_hid_report_get_sibling(
     242            hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END,
     243            USB_HID_REPORT_TYPE_INPUT);
     244
     245        if (field != NULL) {
     246                usb_log_debug(NAME " VALUE(%X) USAGE(%X)\n", field->value,
     247                    field->usage);
     248                shift_y = field->value;
     249        }
     250
     251        usb_hid_report_path_free(path);
     252       
     253        if ((shift_x != 0) || (shift_y != 0)) {
     254                async_req_2_0(mouse_dev->console_phone,
     255                    MEVENT_MOVE, shift_x, shift_y);
     256        }
     257       
     258        /*
     259         * Buttons
     260         */
     261        path = usb_hid_report_path();
     262        usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_BUTTON, 0);
     263        usb_hid_report_path_set_report_id(path, report_id);
     264       
     265        field = usb_hid_report_get_sibling(
     266            hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END
     267            | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,
     268            USB_HID_REPORT_TYPE_INPUT);
     269
     270        if (field != NULL) {
     271                usb_log_debug(NAME " VALUE(%X) USAGE(%X)\n", field->value,
     272                    field->usage);
     273               
     274                if (mouse_dev->buttons[field->usage - field->usage_minimum] == 0
     275                    && field->value != 0) {
    204276                        async_req_2_0(mouse_dev->console_phone,
    205                             MEVENT_MOVE,
    206                             - shift_x / 10,  - shift_y / 10);
    207                 } else {
    208                         usb_log_error("No move reported\n");
    209                 }
    210                 if (butt) {
    211                         /* FIXME: proper button clicking. */
    212                         async_req_2_0(mouse_dev->console_phone,
    213                             MEVENT_BUTTON, 1, 1);
    214                         async_req_2_0(mouse_dev->console_phone,
    215                             MEVENT_BUTTON, 1, 0);
    216                 }
    217         } else {
    218                 usb_log_error("No console phone in mouse!!\n");
    219         }
    220 
    221         usb_log_debug("buttons=%s  dX=%+3d  dY=%+3d  wheel=%+3d\n",
    222             str_buttons, shift_x, shift_y, wheel);
    223 
    224         /* Guess. */
    225         //async_usleep(1000);
    226         // no sleep right now
     277                            MEVENT_BUTTON, field->usage, 1);
     278                        mouse_dev->buttons[field->usage - field->usage_minimum]
     279                            = field->value;
     280                } else if (
     281                    mouse_dev->buttons[field->usage - field->usage_minimum] != 0
     282                    && field->value == 0) {
     283                       async_req_2_0(mouse_dev->console_phone,
     284                           MEVENT_BUTTON, field->usage, 0);
     285                       mouse_dev->buttons[field->usage - field->usage_minimum]
     286                           = field->value;
     287               }
     288               
     289                field = usb_hid_report_get_sibling(
     290                    hid_dev->report, field, path, USB_HID_PATH_COMPARE_END
     291                    | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,
     292                    USB_HID_REPORT_TYPE_INPUT);
     293        }
     294       
     295        usb_hid_report_path_free(path);
    227296
    228297        return true;
     
    248317        }
    249318       
     319//      usb_hid_report_path_t *path = usb_hid_report_path();
     320//      usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_BUTTON, 0);
     321       
     322//      usb_hid_report_path_set_report_id(path, 0);
     323       
     324//      mouse_dev->button_count = usb_hid_report_input_length(
     325//          hid_dev->report, path,
     326//          USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY);
     327//      usb_hid_report_path_free(path);
     328       
     329//      usb_log_debug("Size of the input report: %zu\n", kbd_dev->key_count);
     330       
     331        mouse_dev->buttons = (int32_t *)calloc(USB_MOUSE_BUTTON_COUNT,
     332            sizeof(int32_t));
     333       
     334        if (mouse_dev->buttons == NULL) {
     335                usb_log_fatal("No memory!\n");
     336                free(mouse_dev);
     337                return ENOMEM;
     338        }
     339       
    250340        // save the Mouse device structure into the HID device structure
    251341        hid_dev->data = mouse_dev;
     
    255345       
    256346        // TODO: how to know if the device supports the request???
    257         usbhid_req_set_idle(&hid_dev->usb_dev->ctrl_pipe,
    258             hid_dev->usb_dev->interface_no, IDLE_RATE);
     347//      usbhid_req_set_idle(&hid_dev->usb_dev->ctrl_pipe,
     348//          hid_dev->usb_dev->interface_no, IDLE_RATE);
    259349       
    260350        return EOK;
     
    280370                return false;
    281371        }
    282         usb_mouse_t *mouse_dev = (usb_mouse_t *)hid_dev->data;
    283        
    284         return usb_mouse_process_boot_report(mouse_dev, buffer, buffer_size);
     372       
     373        return usb_mouse_process_boot_report(hid_dev, buffer, buffer_size);
    285374}
    286375
  • uspace/drv/usbhid/mouse/mousedev.h

    re67399e r30710035  
    4949        /** IPC phone to console (consumer). */
    5050        int console_phone;
     51       
     52        int32_t *buttons;
    5153} usb_mouse_t;
    5254
  • uspace/lib/usb/include/usb/classes/hidut.h

    re67399e r30710035  
    5959        USB_HIDUT_USAGE_GENERIC_DESKTOP_GAMEPAD = 5,
    6060        USB_HIDUT_USAGE_GENERIC_DESKTOP_KEYBOARD = 6,
    61         USB_HIDUT_USAGE_GENERIC_DESKTOP_KEYPAD = 7
     61        USB_HIDUT_USAGE_GENERIC_DESKTOP_KEYPAD = 7,
     62        USB_HIDUT_USAGE_GENERIC_DESKTOP_X = 0x30,
     63        USB_HIDUT_USAGE_GENERIC_DESKTOP_Y = 0x31,
     64        USB_HIDUT_USAGE_GENERIC_DESKTOP_WHEEL = 0x38
    6265        /* USB_HIDUT_USAGE_GENERIC_DESKTOP_ = , */
    6366       
Note: See TracChangeset for help on using the changeset viewer.