Changeset d900699 in mainline for uspace/drv/usbhid/kbd/kbddev.c


Ignore:
Timestamp:
2011-06-17T16:48:53Z (14 years ago)
Author:
Petr Koupy <petr.koupy@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f3a605be
Parents:
df8110d3 (diff), 98caf49 (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 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/usbhid/kbd/kbddev.c

    rdf8110d3 rd900699  
    4040
    4141#include <io/keycode.h>
    42 #include <ipc/kbd.h>
     42#include <io/console.h>
     43#include <ipc/kbdev.h>
    4344#include <async.h>
    4445#include <async_obsolete.h>
     
    6364#include "kbddev.h"
    6465
    65 #include "layout.h"
    6666#include "conv.h"
    6767#include "kbdrepeat.h"
     
    7373
    7474/*----------------------------------------------------------------------------*/
    75 /** Default modifiers when the keyboard is initialized. */
     75
    7676static const unsigned DEFAULT_ACTIVE_MODS = KM_NUM_LOCK;
    7777
     
    101101const char *HID_KBD_FUN_NAME = "keyboard";
    102102const char *HID_KBD_CLASS_NAME = "keyboard";
     103
     104static void usb_kbd_set_led(usb_hid_dev_t *hid_dev, usb_kbd_t *kbd_dev);
    103105
    104106/*----------------------------------------------------------------------------*/
     
    154156
    155157/*----------------------------------------------------------------------------*/
    156 /* Keyboard layouts                                                           */
    157 /*----------------------------------------------------------------------------*/
    158 
    159 #define NUM_LAYOUTS 3
    160 
    161 /** Keyboard layout map. */
    162 static layout_op_t *layout[NUM_LAYOUTS] = {
    163         &us_qwerty_op,
    164         &us_dvorak_op,
    165         &cz_op
    166 };
    167 
    168 static int active_layout = 0;
    169 
    170 /*----------------------------------------------------------------------------*/
    171158/* IPC method handler                                                         */
    172159/*----------------------------------------------------------------------------*/
     
    174161static void default_connection_handler(ddf_fun_t *, ipc_callid_t, ipc_call_t *);
    175162
    176 /** 
     163/**
    177164 * Default handler for IPC methods not handled by DDF.
    178165 *
     
    189176{
    190177        sysarg_t method = IPC_GET_IMETHOD(*icall);
     178        int callback;
    191179       
    192180        usb_kbd_t *kbd_dev = (usb_kbd_t *)fun->driver_data;
     
    198186        }
    199187
    200         if (method == IPC_M_CONNECT_TO_ME) {
    201                 int callback = IPC_GET_ARG5(*icall);
     188        switch (method) {
     189        case IPC_M_CONNECT_TO_ME:
     190                callback = IPC_GET_ARG5(*icall);
    202191
    203192                if (kbd_dev->console_phone != -1) {
     
    212201                usb_log_debug("default_connection_handler: OK\n");
    213202                async_answer_0(icallid, EOK);
    214                 return;
    215         }
    216        
    217         usb_log_debug("default_connection_handler: Wrong function.\n");
    218         async_answer_0(icallid, EINVAL);
     203                break;
     204        case KBDEV_SET_IND:
     205                kbd_dev->mods = IPC_GET_ARG1(*icall);
     206                usb_kbd_set_led(kbd_dev->hid_dev, kbd_dev);
     207                async_answer_0(icallid, EOK);
     208                break;
     209        default:
     210                usb_log_debug("default_connection_handler: Wrong function.\n");
     211                async_answer_0(icallid, EINVAL);
     212                break;
     213        }
    219214}
    220215
     
    225220 * Handles turning of LED lights on and off.
    226221 *
    227  * In case of USB keyboards, the LEDs are handled in the driver, not in the
    228  * device. When there should be a change (lock key was pressed), the driver
    229  * uses a Set_Report request sent to the device to set the state of the LEDs.
     222 * As with most other keyboards, the LED indicators in USB keyboards are
     223 * driven by software. When state of some modifier changes, the input server
     224 * will call us and tell us to update the LED state and what the new state
     225 * should be.
    230226 *
    231227 * This functions sets the LED lights according to current settings of modifiers
     
    249245            USB_HID_REPORT_TYPE_OUTPUT);
    250246       
    251         while (field != NULL) {         
     247        while (field != NULL) {
    252248               
    253249                if ((field->usage == USB_HID_LED_NUM_LOCK)
     
    292288
    293289/*----------------------------------------------------------------------------*/
    294 /**
    295  * Processes key events.
    296  *
    297  * @note This function was copied from AT keyboard driver and modified to suit
    298  *       USB keyboard.
    299  *
    300  * @note Lock keys are not sent to the console, as they are completely handled
    301  *       in the driver. It may, however, be required later that the driver
    302  *       sends also these keys to application (otherwise it cannot use those
    303  *       keys at all).
    304  *
     290/** Send key event.
     291 *
    305292 * @param kbd_dev Keyboard device structure.
    306  * @param type Type of the event (press / release). Recognized values: 
     293 * @param type Type of the event (press / release). Recognized values:
    307294 *             KEY_PRESS, KEY_RELEASE
    308  * @param key Key code of the key according to HID Usage Tables.
     295 * @param key Key code
    309296 */
    310297void usb_kbd_push_ev(usb_hid_dev_t *hid_dev, usb_kbd_t *kbd_dev, int type,
    311298    unsigned int key)
    312299{
    313         kbd_event_t ev;
    314         unsigned mod_mask;
    315 
    316         /*
    317          * These parts are copy-pasted from the AT keyboard driver.
    318          *
    319          * They definitely require some refactoring, but will keep it for later
    320          * when the console and keyboard system is changed in HelenOS.
    321          */
    322         switch (key) {
    323         case KC_LCTRL: mod_mask = KM_LCTRL; break;
    324         case KC_RCTRL: mod_mask = KM_RCTRL; break;
    325         case KC_LSHIFT: mod_mask = KM_LSHIFT; break;
    326         case KC_RSHIFT: mod_mask = KM_RSHIFT; break;
    327         case KC_LALT: mod_mask = KM_LALT; break;
    328         case KC_RALT: mod_mask = KM_RALT; break;
    329         default: mod_mask = 0; break;
    330         }
    331 
    332         if (mod_mask != 0) {
    333                 if (type == KEY_PRESS)
    334                         kbd_dev->mods = kbd_dev->mods | mod_mask;
    335                 else
    336                         kbd_dev->mods = kbd_dev->mods & ~mod_mask;
    337         }
    338 
    339         switch (key) {
    340         case KC_CAPS_LOCK: mod_mask = KM_CAPS_LOCK; break;
    341         case KC_NUM_LOCK: mod_mask = KM_NUM_LOCK; break;
    342         case KC_SCROLL_LOCK: mod_mask = KM_SCROLL_LOCK; break;
    343         default: mod_mask = 0; break;
    344         }
    345 
    346         if (mod_mask != 0) {
    347                 if (type == KEY_PRESS) {
    348                         /*
    349                          * Only change lock state on transition from released
    350                          * to pressed. This prevents autorepeat from messing
    351                          * up the lock state.
    352                          */
    353                         unsigned int locks_old = kbd_dev->lock_keys;
    354                        
    355                         kbd_dev->mods =
    356                             kbd_dev->mods ^ (mod_mask & ~kbd_dev->lock_keys);
    357                         kbd_dev->lock_keys = kbd_dev->lock_keys | mod_mask;
    358 
    359                         /* Update keyboard lock indicator lights. */
    360                         if (kbd_dev->lock_keys != locks_old
    361                             && hid_dev != NULL) { // ugly hack
    362                                 usb_kbd_set_led(hid_dev, kbd_dev);
    363                         }
    364                 } else {
    365                         kbd_dev->lock_keys = kbd_dev->lock_keys & ~mod_mask;
    366                 }
    367         }
    368 
    369         if (key == KC_CAPS_LOCK || key == KC_NUM_LOCK || key == KC_SCROLL_LOCK) {
    370                 // do not send anything to the console, this is our business
    371                 return;
    372         }
    373        
    374         if (type == KEY_PRESS && (kbd_dev->mods & KM_LCTRL) && key == KC_F1) {
    375                 active_layout = 0;
    376                 layout[active_layout]->reset();
    377                 return;
    378         }
    379 
    380         if (type == KEY_PRESS && (kbd_dev->mods & KM_LCTRL) && key == KC_F2) {
    381                 active_layout = 1;
    382                 layout[active_layout]->reset();
    383                 return;
    384         }
    385 
    386         if (type == KEY_PRESS && (kbd_dev->mods & KM_LCTRL) && key == KC_F3) {
    387                 active_layout = 2;
    388                 layout[active_layout]->reset();
    389                 return;
    390         }
    391        
    392         ev.type = type;
    393         ev.key = key;
    394         ev.mods = kbd_dev->mods;
    395 
    396         ev.c = layout[active_layout]->parse_ev(&ev);
    397 
    398         usb_log_debug2("Sending key %d to the console\n", ev.key);
     300        usb_log_debug2("Sending kbdev event %d/%d to the console\n", type, key);
    399301        if (kbd_dev->console_phone < 0) {
    400302                usb_log_warning(
     
    403305        }
    404306       
    405         async_obsolete_msg_4(kbd_dev->console_phone, KBD_EVENT, ev.type, ev.key,
    406             ev.mods, ev.c);
     307        async_obsolete_msg_2(kbd_dev->console_phone, KBDEV_EVENT, type, key);
    407308}
    408309
     
    716617                return ENOMEM;  // TODO: some other code??
    717618        }
     619
     620        /* Store link to HID device */
     621        kbd_dev->hid_dev = hid_dev;
    718622       
    719623        /*
     
    787691        /*
    788692         * Modifiers and locks
    789          */     
     693         */
    790694        kbd_dev->modifiers = 0;
    791695        kbd_dev->mods = DEFAULT_ACTIVE_MODS;
     
    794698        /*
    795699         * Autorepeat
    796          */     
     700         */
    797701        kbd_dev->repeat.key_new = 0;
    798702        kbd_dev->repeat.key_repeated = 0;
Note: See TracChangeset for help on using the changeset viewer.