Changeset ba551ba7 in mainline


Ignore:
Timestamp:
2011-12-26T09:57:35Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7cb0cb4
Parents:
65ceb4b
Message:

xtkbd: Implement scancode parsing.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/char/xtkbd/xtkbd.c

    r65ceb4b rba551ba7  
    3737#include <device/char_dev.h>
    3838#include <ddf/log.h>
     39#include <io/keycode.h>
     40#include <io/console.h>
    3941#include <ipc/kbdev.h>
    4042#include <abi/ipc/methods.h>
    4143
    4244#include "xtkbd.h"
    43 
     45static const int scanmap_simple[] = {
     46
     47        [0x29] = KC_BACKTICK,
     48
     49        [0x02] = KC_1,
     50        [0x03] = KC_2,
     51        [0x04] = KC_3,
     52        [0x05] = KC_4,
     53        [0x06] = KC_5,
     54        [0x07] = KC_6,
     55        [0x08] = KC_7,
     56        [0x09] = KC_8,
     57        [0x0a] = KC_9,
     58        [0x0b] = KC_0,
     59
     60        [0x0c] = KC_MINUS,
     61        [0x0d] = KC_EQUALS,
     62        [0x0e] = KC_BACKSPACE,
     63
     64        [0x0f] = KC_TAB,
     65
     66        [0x10] = KC_Q,
     67        [0x11] = KC_W,
     68        [0x12] = KC_E,
     69        [0x13] = KC_R,
     70        [0x14] = KC_T,
     71        [0x15] = KC_Y,
     72        [0x16] = KC_U,
     73        [0x17] = KC_I,
     74        [0x18] = KC_O,
     75        [0x19] = KC_P,
     76
     77        [0x1a] = KC_LBRACKET,
     78        [0x1b] = KC_RBRACKET,
     79
     80        [0x3a] = KC_CAPS_LOCK,
     81
     82        [0x1e] = KC_A,
     83        [0x1f] = KC_S,
     84        [0x20] = KC_D,
     85        [0x21] = KC_F,
     86        [0x22] = KC_G,
     87        [0x23] = KC_H,
     88        [0x24] = KC_J,
     89        [0x25] = KC_K,
     90        [0x26] = KC_L,
     91
     92        [0x27] = KC_SEMICOLON,
     93        [0x28] = KC_QUOTE,
     94        [0x2b] = KC_BACKSLASH,
     95
     96        [0x2a] = KC_LSHIFT,
     97
     98        [0x2c] = KC_Z,
     99        [0x2d] = KC_X,
     100        [0x2e] = KC_C,
     101        [0x2f] = KC_V,
     102        [0x30] = KC_B,
     103        [0x31] = KC_N,
     104        [0x32] = KC_M,
     105
     106        [0x33] = KC_COMMA,
     107        [0x34] = KC_PERIOD,
     108        [0x35] = KC_SLASH,
     109
     110        [0x36] = KC_RSHIFT,
     111
     112        [0x1d] = KC_LCTRL,
     113        [0x38] = KC_LALT,
     114        [0x39] = KC_SPACE,
     115
     116        [0x01] = KC_ESCAPE,
     117
     118        [0x3b] = KC_F1,
     119        [0x3c] = KC_F2,
     120        [0x3d] = KC_F3,
     121        [0x3e] = KC_F4,
     122        [0x3f] = KC_F5,
     123        [0x40] = KC_F6,
     124        [0x41] = KC_F7,
     125
     126        [0x42] = KC_F8,
     127        [0x43] = KC_F9,
     128        [0x44] = KC_F10,
     129
     130        [0x57] = KC_F11,
     131        [0x58] = KC_F12,
     132
     133        [0x46] = KC_SCROLL_LOCK,
     134
     135        [0x1c] = KC_ENTER,
     136
     137        [0x45] = KC_NUM_LOCK,
     138        [0x37] = KC_NTIMES,
     139        [0x4a] = KC_NMINUS,
     140        [0x4e] = KC_NPLUS,
     141        [0x47] = KC_N7,
     142        [0x48] = KC_N8,
     143        [0x49] = KC_N9,
     144        [0x4b] = KC_N4,
     145        [0x4c] = KC_N5,
     146        [0x4d] = KC_N6,
     147        [0x4f] = KC_N1,
     148        [0x50] = KC_N2,
     149        [0x51] = KC_N3,
     150        [0x52] = KC_N0,
     151        [0x53] = KC_NPERIOD
     152};
     153/*----------------------------------------------------------------------------*/
     154static const int scanmap_e0[] = {
     155        [0x38] = KC_RALT,
     156        [0x1d] = KC_RSHIFT,
     157
     158        [0x37] = KC_PRTSCR,
     159
     160        [0x52] = KC_INSERT,
     161        [0x47] = KC_HOME,
     162        [0x49] = KC_PAGE_UP,
     163
     164        [0x53] = KC_DELETE,
     165        [0x4f] = KC_END,
     166        [0x51] = KC_PAGE_DOWN,
     167
     168        [0x48] = KC_UP,
     169        [0x4b] = KC_LEFT,
     170        [0x50] = KC_DOWN,
     171        [0x4d] = KC_RIGHT,
     172
     173        [0x35] = KC_NSLASH,
     174        [0x1c] = KC_NENTER
     175};
     176/*----------------------------------------------------------------------------*/
    44177static int polling(void *);
    45178static void default_connection_handler(ddf_fun_t *fun,
    46179    ipc_callid_t icallid, ipc_call_t *icall);
    47 
     180/*----------------------------------------------------------------------------*/
    48181static ddf_dev_ops_t kbd_ops = {
    49182        .default_handler = default_connection_handler
    50183};
    51 
     184/*----------------------------------------------------------------------------*/
    52185int xt_kbd_init(xt_kbd_t *kbd, ddf_dev_t *dev)
    53186{
     
    104237        assert(kbd->parent_sess);
    105238        while (1) {
     239                const int *map = scanmap_simple;
     240                size_t map_size = sizeof(scanmap_simple) / sizeof(int);
     241
    106242                uint8_t code = 0;
    107243                ssize_t size = char_dev_read(kbd->parent_sess, &code, 1);
    108                 ddf_msg(LVL_DEBUG, "Got scancode: %hhx, size: %zd", code, size);
     244
     245                if (code == 0xe0) {
     246                        map = scanmap_e0;
     247                        map_size = sizeof(scanmap_e0) / sizeof(int);
     248                        size = char_dev_read(kbd->parent_sess, &code, 1);
     249                }
     250
     251
     252                kbd_event_type_t type;
     253                if (code & 0x80) {
     254                        code &= ~0x80;
     255                        type = KEY_RELEASE;
     256                } else {
     257                        type = KEY_PRESS;
     258                }
     259
     260                if ((size_t) code >= map_size) {
     261                        ddf_msg(LVL_WARN,
     262                            "Unknown scancode: %hhx, size: %zd", code, size);
     263                        continue;
     264                }
     265
     266                const unsigned key = map[code];
     267                if (key != 0) {
     268                        async_exch_t *exch =
     269                            async_exchange_begin(kbd->input_sess);
     270                        if (!exch) {
     271                                ddf_msg(LVL_ERROR,
     272                                    "Failed to create input exchange.");
     273                                continue;
     274                        }
     275                        async_msg_4(exch, KBDEV_EVENT, type, key, 0, 0);
     276                        async_exchange_end(exch);
     277                }
    109278        }
    110279}
Note: See TracChangeset for help on using the changeset viewer.