Changeset 7ab7c7f6 in mainline for uspace/drv


Ignore:
Timestamp:
2011-05-07T13:39:03Z (14 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
62265ce, 6fb003e
Parents:
5d07f54 (diff), bc02b83 (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:

Development branch changes

Location:
uspace/drv
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/usbhid/generic/hiddev.c

    r5d07f54 r7ab7c7f6  
    3939#include <errno.h>
    4040#include <str_error.h>
     41#include <bool.h>
    4142
    4243#include <usbhid_iface.h>
     
    6465    size_t size, size_t *act_size, unsigned int flags);
    6566
     67static int usb_generic_hid_client_connected(ddf_fun_t *fun);
     68
    6669/*----------------------------------------------------------------------------*/
    6770
     
    7275
    7376static ddf_dev_ops_t usb_generic_hid_ops = {
    74         .interfaces[USBHID_DEV_IFACE] = &usb_generic_iface
     77        .interfaces[USBHID_DEV_IFACE] = &usb_generic_iface,
     78        .open = usb_generic_hid_client_connected
    7579};
    7680
     
    104108       
    105109        /*! @todo This should probably be atomic. */
    106         memcpy(buffer, hid_dev->input_report, hid_dev->input_report_size);
    107         *act_size = hid_dev->input_report_size;
     110        if (usb_hid_report_ready()) {
     111                memcpy(buffer, hid_dev->input_report,
     112                    hid_dev->input_report_size);
     113                *act_size = hid_dev->input_report_size;
     114                usb_hid_report_received();
     115        }
    108116       
    109117        // clear the buffer so that it will not be received twice
    110         memset(hid_dev->input_report, 0, hid_dev->input_report_size);
     118        //memset(hid_dev->input_report, 0, hid_dev->input_report_size);
    111119       
     120        // note that we already received this report
     121//      report_received = true;
     122       
     123        return EOK;
     124}
     125
     126/*----------------------------------------------------------------------------*/
     127
     128static int usb_generic_hid_client_connected(ddf_fun_t *fun)
     129{
     130        usb_hid_report_received();
    112131        return EOK;
    113132}
  • uspace/drv/usbhid/kbd/kbddev.c

    r5d07f54 r7ab7c7f6  
    255255       
    256256        if (hid_dev == NULL || hid_dev->data == NULL) {
     257                usb_log_debug("default_connection_handler: "
     258                    "Missing parameter.\n");
    257259                async_answer_0(icallid, EINVAL);
    258260                return;
     
    267269
    268270                if (kbd_dev->console_phone != -1) {
     271                        usb_log_debug("default_connection_handler: "
     272                            "console phone already set\n");
    269273                        async_answer_0(icallid, ELIMIT);
    270274                        return;
     
    272276
    273277                kbd_dev->console_phone = callback;
     278               
     279                usb_log_debug("default_connection_handler: OK\n");
    274280                async_answer_0(icallid, EOK);
    275281                return;
    276282        }
    277283       
     284        usb_log_debug("default_connection_handler: Wrong function.\n");
    278285        async_answer_0(icallid, EINVAL);
    279286}
     
    555562                        usb_log_debug2("Key pressed: %d (keycode: %d)\n", key,
    556563                            kbd_dev->keys[i]);
    557                         usb_kbd_push_ev(hid_dev, kbd_dev, KEY_PRESS, key);
    558564                        if (!usb_kbd_is_lock(key)) {
    559565                                usb_kbd_repeat_start(kbd_dev, key);
    560566                        }
     567                        usb_kbd_push_ev(hid_dev, kbd_dev, KEY_PRESS, key);
    561568                } else {
    562569                        // found, nothing happens
  • uspace/drv/usbhid/mouse/mousedev.c

    r5d07f54 r7ab7c7f6  
    4343#include <str_error.h>
    4444#include <ipc/mouse.h>
     45#include <io/console.h>
     46
     47#include <ipc/kbd.h>
     48#include <io/keycode.h>
    4549
    4650#include "mousedev.h"
     
    6165
    6266const char *HID_MOUSE_FUN_NAME = "mouse";
     67const char *HID_MOUSE_WHEEL_FUN_NAME = "mouse-wheel";
    6368const char *HID_MOUSE_CLASS_NAME = "mouse";
     69const char *HID_MOUSE_WHEEL_CLASS_NAME = "keyboard";
    6470
    6571/** Default idle rate for mouses. */
     
    119125       
    120126        if (hid_dev == NULL || hid_dev->data == NULL) {
     127                usb_log_debug("default_connection_handler: Missing "
     128                    "parameters.\n");
    121129                async_answer_0(icallid, EINVAL);
    122130                return;
     
    127135        usb_mouse_t *mouse_dev = (usb_mouse_t *)hid_dev->data;
    128136       
     137        int *phone = (str_cmp(fun->name, HID_MOUSE_FUN_NAME) == 0)
     138                     ? &mouse_dev->mouse_phone : &mouse_dev->wheel_phone;
     139       
    129140        if (method == IPC_M_CONNECT_TO_ME) {
    130141                int callback = IPC_GET_ARG5(*icall);
    131142
    132                 if (mouse_dev->console_phone != -1) {
     143                if (*phone != -1) {
     144                        usb_log_debug("default_connection_handler: Console "
     145                            "phone to mouse already set.\n");
    133146                        async_answer_0(icallid, ELIMIT);
     147                        //async_answer_0(icallid, EOK);
    134148                        return;
    135149                }
    136150
    137                 mouse_dev->console_phone = callback;
     151                *phone = callback;
    138152                usb_log_debug("Console phone to mouse set ok (%d).\n", callback);
    139153                async_answer_0(icallid, EOK);
     
    141155        }
    142156
     157        usb_log_debug("default_connection_handler: Invalid function.\n");
    143158        async_answer_0(icallid, EINVAL);
    144159}
     
    152167                return NULL;
    153168        }
    154         mouse->console_phone = -1;
     169        mouse->mouse_phone = -1;
     170        mouse->wheel_phone = -1;
    155171       
    156172        return mouse;
     
    164180       
    165181        // hangup phone to the console
    166         if ((*mouse_dev)->console_phone >= 0) {
    167                 async_hangup((*mouse_dev)->console_phone);
     182        if ((*mouse_dev)->mouse_phone >= 0) {
     183                async_hangup((*mouse_dev)->mouse_phone);
     184        }
     185       
     186        if ((*mouse_dev)->wheel_phone >= 0) {
     187                async_hangup((*mouse_dev)->wheel_phone);
    168188        }
    169189       
     
    174194/*----------------------------------------------------------------------------*/
    175195
    176 static bool usb_mouse_process_boot_report(usb_hid_dev_t *hid_dev,
    177     uint8_t *buffer, size_t buffer_size)
     196static void usb_mouse_send_wheel(const usb_mouse_t *mouse_dev, int wheel)
     197{
     198        console_event_t ev;
     199       
     200        ev.type = KEY_PRESS;
     201        ev.key = (wheel > 0) ? KC_UP : (wheel < 0) ? KC_DOWN : 0;
     202        ev.mods = 0;
     203        ev.c = 0;
     204
     205        if (mouse_dev->wheel_phone < 0) {
     206                usb_log_warning(
     207                    "Connection to console not ready, key discarded.\n");
     208                return;
     209        }
     210       
     211        int count = (wheel < 0) ? -wheel : wheel;
     212        int i;
     213       
     214        for (i = 0; i < count * 3; ++i) {
     215                usb_log_debug2("Sending key %d to the console\n", ev.key);
     216                async_msg_4(mouse_dev->wheel_phone, KBD_EVENT, ev.type,
     217                    ev.key, ev.mods, ev.c);
     218                // send key release right away
     219                async_msg_4(mouse_dev->wheel_phone, KBD_EVENT, KEY_RELEASE,
     220                    ev.key, ev.mods, ev.c);
     221        }
     222}
     223
     224/*----------------------------------------------------------------------------*/
     225
     226static bool usb_mouse_process_report(usb_hid_dev_t *hid_dev, uint8_t *buffer,
     227    size_t buffer_size)
    178228{
    179229        usb_mouse_t *mouse_dev = (usb_mouse_t *)hid_dev->data;
     
    182232            usb_debug_str_buffer(buffer, buffer_size, 0));
    183233       
    184         if (mouse_dev->console_phone < 0) {
     234        if (mouse_dev->mouse_phone < 0) {
    185235                usb_log_error(NAME " No console phone.\n");
    186236                return false;   // ??
     
    252302       
    253303        if ((shift_x != 0) || (shift_y != 0)) {
    254                 async_req_2_0(mouse_dev->console_phone,
     304                async_req_2_0(mouse_dev->mouse_phone,
    255305                    MEVENT_MOVE, shift_x, shift_y);
    256306        }
     307       
     308        /*
     309         * Wheel
     310         */
     311        int wheel = 0;
     312       
     313        path = usb_hid_report_path();
     314        usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_GENERIC_DESKTOP,
     315            USB_HIDUT_USAGE_GENERIC_DESKTOP_WHEEL);
     316
     317        usb_hid_report_path_set_report_id(path, report_id);
     318       
     319        field = usb_hid_report_get_sibling(
     320            hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END,
     321            USB_HID_REPORT_TYPE_INPUT);
     322
     323        if (field != NULL) {
     324                usb_log_debug(NAME " VALUE(%X) USAGE(%X)\n", field->value,
     325                    field->usage);
     326                wheel = field->value;
     327        }
     328
     329        usb_hid_report_path_free(path);
     330       
     331        // send arrow up for positive direction and arrow down for negative
     332        // direction; three arrows for difference of 1
     333        usb_mouse_send_wheel(mouse_dev, wheel);
     334       
    257335       
    258336        /*
     
    274352                if (mouse_dev->buttons[field->usage - field->usage_minimum] == 0
    275353                    && field->value != 0) {
    276                         async_req_2_0(mouse_dev->console_phone,
     354                        async_req_2_0(mouse_dev->mouse_phone,
    277355                            MEVENT_BUTTON, field->usage, 1);
    278356                        mouse_dev->buttons[field->usage - field->usage_minimum]
     
    281359                    mouse_dev->buttons[field->usage - field->usage_minimum] != 0
    282360                    && field->value == 0) {
    283                        async_req_2_0(mouse_dev->console_phone,
     361                       async_req_2_0(mouse_dev->mouse_phone,
    284362                           MEVENT_BUTTON, field->usage, 0);
    285363                       mouse_dev->buttons[field->usage - field->usage_minimum]
     
    337415        }
    338416       
     417        /*
     418         * Special function for acting as keyboard (wheel)
     419         */
     420        usb_log_debug("Creating DDF function %s...\n",
     421                      HID_MOUSE_WHEEL_FUN_NAME);
     422        fun = ddf_fun_create(hid_dev->usb_dev->ddf_dev, fun_exposed,
     423            HID_MOUSE_WHEEL_FUN_NAME);
     424        if (fun == NULL) {
     425                usb_log_error("Could not create DDF function node.\n");
     426                return ENOMEM;
     427        }
     428       
     429        /*
     430         * Store the initialized HID device and HID ops
     431         * to the DDF function.
     432         */
     433        fun->ops = &hid_dev->ops;
     434        fun->driver_data = hid_dev;   // TODO: maybe change to hid_dev->data
     435
     436        rc = ddf_fun_bind(fun);
     437        if (rc != EOK) {
     438                usb_log_error("Could not bind DDF function: %s.\n",
     439                    str_error(rc));
     440                ddf_fun_destroy(fun);
     441                return rc;
     442        }
     443       
     444        usb_log_debug("Adding DDF function to class %s...\n",
     445            HID_MOUSE_WHEEL_CLASS_NAME);
     446        rc = ddf_fun_add_to_class(fun, HID_MOUSE_WHEEL_CLASS_NAME);
     447        if (rc != EOK) {
     448                usb_log_error(
     449                    "Could not add DDF function to class %s: %s.\n",
     450                    HID_MOUSE_WHEEL_CLASS_NAME, str_error(rc));
     451                ddf_fun_destroy(fun);
     452                return rc;
     453        }
     454       
    339455        return EOK;
    340456}
     
    407523        }
    408524       
    409         return usb_mouse_process_boot_report(hid_dev, buffer, buffer_size);
     525        return usb_mouse_process_report(hid_dev, buffer, buffer_size);
    410526}
    411527
  • uspace/drv/usbhid/mouse/mousedev.h

    r5d07f54 r7ab7c7f6  
    4848        //suseconds_t poll_interval_us;
    4949        /** IPC phone to console (consumer). */
    50         int console_phone;
     50        int mouse_phone;
     51        int wheel_phone;
    5152       
    5253        int32_t *buttons;
  • uspace/drv/usbhid/subdrivers.c

    r5d07f54 r7ab7c7f6  
    3636#include "subdrivers.h"
    3737#include "usb/classes/hidut.h"
     38#include "usb/classes/hidpath.h"
    3839
    3940#include "lgtch-ultrax/lgtch-ultrax.h"
     41#include "mouse/mousedev.h"
    4042
    4143static usb_hid_subdriver_usage_t path_kbd[] = {
    4244        {USB_HIDUT_PAGE_KEYBOARD, 0},
     45        {0, 0}
     46};
     47
     48static usb_hid_subdriver_usage_t path_mouse2[] = {
     49        {USB_HIDUT_PAGE_GENERIC_DESKTOP, USB_HIDUT_USAGE_GENERIC_DESKTOP_X},
    4350        {0, 0}
    4451};
     
    7986                }
    8087        },
     88        {
     89                path_mouse2,
     90                -1,
     91                USB_HID_PATH_COMPARE_END
     92                | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,
     93                -1,
     94                -1,
     95                {
     96                        .init = usb_mouse_init,
     97                        .deinit = usb_mouse_deinit,
     98                        .poll = usb_mouse_polling_callback,
     99                        .poll_end = NULL
     100                }
     101        },
    81102        {NULL, -1, 0, -1, -1, {NULL, NULL, NULL, NULL}}
    82103};
  • uspace/drv/usbhid/usbhid.c

    r5d07f54 r7ab7c7f6  
    6363static const int USB_HID_MAX_SUBDRIVERS = 10;
    6464
     65static fibril_local bool report_received;
     66
    6567/*----------------------------------------------------------------------------*/
    6668
     
    412414        }
    413415       
    414         // TODO: remove the mouse hack
    415         if (hid_dev->poll_pipe_index == USB_HID_MOUSE_POLL_EP_NO ||
    416             fallback) {
     416        if (fallback) {
    417417                // fall back to boot protocol
    418418                switch (hid_dev->poll_pipe_index) {
     
    509509                                free(input_old);
    510510                        }
     511                        usb_hid_new_report();
    511512                }
    512513        }
     
    589590/*----------------------------------------------------------------------------*/
    590591
     592void usb_hid_new_report(void)
     593{
     594        report_received = false;
     595}
     596
     597/*----------------------------------------------------------------------------*/
     598
     599void usb_hid_report_received(void)
     600{
     601        report_received = true;
     602}
     603
     604/*----------------------------------------------------------------------------*/
     605
     606bool usb_hid_report_ready(void)
     607{
     608        return !report_received;
     609}
     610
     611/*----------------------------------------------------------------------------*/
     612
    591613void usb_hid_free(usb_hid_dev_t **hid_dev)
    592614{
  • uspace/drv/usbhid/usbhid.h

    r5d07f54 r7ab7c7f6  
    4444#include <usb/devdrv.h>
    4545#include <usb/classes/hid.h>
     46#include <bool.h>
    4647
    4748struct usb_hid_dev;
     
    128129//const char *usb_hid_get_class_name(const usb_hid_dev_t *hid_dev);
    129130
     131void usb_hid_new_report(void);
     132
     133void usb_hid_report_received(void);
     134
     135bool usb_hid_report_ready(void);
     136
    130137void usb_hid_free(usb_hid_dev_t **hid_dev);
    131138
  • uspace/drv/vhc/transfer.c

    r5d07f54 r7ab7c7f6  
    135135                if (transfer->direction == USB_DIRECTION_IN) {
    136136                        rc = usbvirt_ipc_send_control_read(phone,
    137                             transfer->endpoint,
    138137                            transfer->setup_buffer, transfer->setup_buffer_size,
    139138                            transfer->data_buffer, transfer->data_buffer_size,
     
    142141                        assert(transfer->direction == USB_DIRECTION_OUT);
    143142                        rc = usbvirt_ipc_send_control_write(phone,
    144                             transfer->endpoint,
    145143                            transfer->setup_buffer, transfer->setup_buffer_size,
    146144                            transfer->data_buffer, transfer->data_buffer_size);
Note: See TracChangeset for help on using the changeset viewer.