Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 3944 → Rev 4055

/branches/dd/uspace/srv/kbd/ctl/stty.c
0,0 → 1,329
/*
* Copyright (c) 2009 Jiri Svoboda
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
/** @addtogroup kbd_ctl
* @ingroup kbd
* @{
*/
/**
* @file
* @brief Serial TTY-like keyboard controller driver.
*/
 
#include <kbd.h>
#include <kbd/kbd.h>
#include <kbd/keycode.h>
#include <kbd_ctl.h>
 
static void parse_ds_start(int scancode);
static void parse_ds_e(int scancode);
static void parse_ds_e1(int scancode);
static void parse_ds_e2(int scancode);
static void parse_ds_e2a(int scancode);
static void parse_ds_e2b(int scancode);
 
static void parse_leaf(int scancode, int (*map)[2], size_t map_length);
 
enum dec_state {
ds_start,
ds_e,
ds_e1,
ds_e2,
ds_e2a,
ds_e2b
};
 
static int map_start[][2] = {
 
[0x60] = { 0, KC_BACKTICK },
 
[0x31] = { 0, KC_1 },
[0x32] = { 0, KC_2 },
[0x33] = { 0, KC_3 },
[0x34] = { 0, KC_4 },
[0x35] = { 0, KC_5 },
[0x36] = { 0, KC_6 },
[0x37] = { 0, KC_7 },
[0x38] = { 0, KC_8 },
[0x39] = { 0, KC_9 },
[0x30] = { 0, KC_0 },
 
[0x2d] = { 0, KC_MINUS },
[0x3d] = { 0, KC_EQUALS },
[0x08] = { 0, KC_BACKSPACE },
 
[0x0f] = { 0, KC_TAB },
 
[0x71] = { 0, KC_Q },
[0x77] = { 0, KC_W },
[0x65] = { 0, KC_E },
[0x72] = { 0, KC_R },
[0x74] = { 0, KC_T },
[0x79] = { 0, KC_Y },
[0x75] = { 0, KC_U },
[0x69] = { 0, KC_I },
[0x6f] = { 0, KC_O },
[0x70] = { 0, KC_P },
 
[0x5b] = { 0, KC_LBRACKET },
[0x5d] = { 0, KC_RBRACKET },
 
[0x61] = { 0, KC_A },
[0x73] = { 0, KC_S },
[0x64] = { 0, KC_D },
[0x66] = { 0, KC_F },
[0x67] = { 0, KC_G },
[0x68] = { 0, KC_H },
[0x6a] = { 0, KC_J },
[0x6b] = { 0, KC_K },
[0x6c] = { 0, KC_L },
 
[0x3b] = { 0, KC_SEMICOLON },
[0x27] = { 0, KC_QUOTE },
[0x5c] = { 0, KC_BACKSLASH },
 
[0x7a] = { 0, KC_Z },
[0x78] = { 0, KC_X },
[0x63] = { 0, KC_C },
[0x76] = { 0, KC_V },
[0x62] = { 0, KC_B },
[0x6e] = { 0, KC_N },
[0x6d] = { 0, KC_M },
 
[0x2c] = { 0, KC_COMMA },
[0x2e] = { 0, KC_PERIOD },
[0x2f] = { 0, KC_SLASH },
 
[0x20] = { 0, KC_SPACE },
 
[0x1b] = { 0, KC_ESCAPE },
 
[0x0a] = { 0, KC_ENTER },
[0x0d] = { 0, KC_ENTER },
 
/* with Shift pressed */
 
[0x7e] = { KM_LSHIFT, KC_BACKTICK },
 
[0x21] = { KM_LSHIFT, KC_1 },
[0x40] = { KM_LSHIFT, KC_2 },
[0x23] = { KM_LSHIFT, KC_3 },
[0x24] = { KM_LSHIFT, KC_4 },
[0x25] = { KM_LSHIFT, KC_5 },
[0x5e] = { KM_LSHIFT, KC_6 },
[0x26] = { KM_LSHIFT, KC_7 },
[0x2a] = { KM_LSHIFT, KC_8 },
[0x28] = { KM_LSHIFT, KC_9 },
[0x29] = { KM_LSHIFT, KC_0 },
 
[0x5f] = { KM_LSHIFT, KC_MINUS },
[0x2b] = { KM_LSHIFT, KC_EQUALS },
 
[0x51] = { KM_LSHIFT, KC_Q },
[0x57] = { KM_LSHIFT, KC_W },
[0x45] = { KM_LSHIFT, KC_E },
[0x52] = { KM_LSHIFT, KC_R },
[0x54] = { KM_LSHIFT, KC_T },
[0x59] = { KM_LSHIFT, KC_Y },
[0x55] = { KM_LSHIFT, KC_U },
[0x49] = { KM_LSHIFT, KC_I },
[0x4f] = { KM_LSHIFT, KC_O },
[0x50] = { KM_LSHIFT, KC_P },
 
[0x7b] = { KM_LSHIFT, KC_LBRACKET },
[0x7d] = { KM_LSHIFT, KC_RBRACKET },
 
[0x41] = { KM_LSHIFT, KC_A },
[0x53] = { KM_LSHIFT, KC_S },
[0x44] = { KM_LSHIFT, KC_D },
[0x46] = { KM_LSHIFT, KC_F },
[0x47] = { KM_LSHIFT, KC_G },
[0x48] = { KM_LSHIFT, KC_H },
[0x4a] = { KM_LSHIFT, KC_J },
[0x4b] = { KM_LSHIFT, KC_K },
[0x4c] = { KM_LSHIFT, KC_L },
 
[0x3a] = { KM_LSHIFT, KC_SEMICOLON },
[0x22] = { KM_LSHIFT, KC_QUOTE },
[0x7c] = { KM_LSHIFT, KC_BACKSLASH },
 
[0x5a] = { KM_LSHIFT, KC_Z },
[0x58] = { KM_LSHIFT, KC_X },
[0x43] = { KM_LSHIFT, KC_C },
[0x56] = { KM_LSHIFT, KC_V },
[0x42] = { KM_LSHIFT, KC_B },
[0x4e] = { KM_LSHIFT, KC_N },
[0x4d] = { KM_LSHIFT, KC_M },
 
[0x3c] = { KM_LSHIFT, KC_COMMA },
[0x3e] = { KM_LSHIFT, KC_PERIOD },
[0x3f] = { KM_LSHIFT, KC_SLASH }
};
 
static int map_e1[][2] =
{
[0x50] = { 0, KC_F1 },
[0x51] = { 0, KC_F2 },
[0x52] = { 0, KC_F3 },
[0x53] = { 0, KC_F4 },
};
 
static int map_e2[][2] =
{
[0x41] = { 0, KC_UP },
[0x42] = { 0, KC_DOWN },
[0x44] = { 0, KC_LEFT },
[0x43] = { 0, KC_RIGHT },
};
 
static int map_e2a[][2] =
{
[0x35] = { 0, KC_F5 },
[0x37] = { 0, KC_F6 },
[0x38] = { 0, KC_F7 },
[0x39] = { 0, KC_F8 },
};
 
static int map_e2b[][2] =
{
[0x30] = { 0, KC_F9 },
[0x31] = { 0, KC_F10 },
[0x32] = { 0, KC_F11 },
[0x33] = { 0, KC_F12 },
};
 
static unsigned int mods_keys[][2] = {
{ KM_LSHIFT, KC_LSHIFT },
{ 0, 0 }
};
 
static enum dec_state ds;
 
void kbd_ctl_parse_scancode(int scancode)
{
switch (ds) {
case ds_start: parse_ds_start(scancode); break;
case ds_e: parse_ds_e(scancode); break;
case ds_e1: parse_ds_e1(scancode); break;
case ds_e2: parse_ds_e2(scancode); break;
case ds_e2a: parse_ds_e2a(scancode); break;
case ds_e2b: parse_ds_e2b(scancode); break;
}
}
 
static void parse_ds_start(int scancode)
{
if (scancode == 0x1b) {
ds = ds_e;
return;
}
 
parse_leaf(scancode, map_start, sizeof(map_start) / (2 * sizeof(int)));
}
 
static void parse_ds_e(int scancode)
{
if (scancode < 0 || scancode >= 0x80) return;
 
switch (scancode) {
case 0x4f: ds = ds_e1; return;
case 0x5b: ds = ds_e2; return;
case 0x1b: ds = ds_start; break;
default: ds = ds_start; return;
}
 
kbd_push_ev(KE_PRESS, KC_ESCAPE);
}
 
static void parse_ds_e1(int scancode)
{
parse_leaf(scancode, map_e1, sizeof(map_e1) / (2 * sizeof(int)));
}
 
static void parse_ds_e2(int scancode)
{
switch (scancode) {
case 0x31: ds = ds_e2a; break;
case 0x32: ds = ds_e2b; break;
default: ds = ds_start; break;
}
 
parse_leaf(scancode, map_e2, sizeof(map_e2) / (2 * sizeof(int)));
}
 
static void parse_ds_e2a(int scancode)
{
parse_leaf(scancode, map_e2a, sizeof(map_e2a) / (2 * sizeof(int)));
}
 
static void parse_ds_e2b(int scancode)
{
parse_leaf(scancode, map_e2b, sizeof(map_e2b) / (2 * sizeof(int)));
}
 
static void parse_leaf(int scancode, int (*map)[2], size_t map_length)
{
unsigned int key, mod;
int i;
 
ds = ds_start;
 
if (scancode < 0 || scancode >= map_length)
return;
 
mod = map[scancode][0];
key = map[scancode][1];
 
/* Simulate modifier pressing. */
i = 0;
while (mods_keys[i][0] != 0) {
if (mod & mods_keys[i][0]) {
kbd_push_ev(KE_PRESS, mods_keys[i][1]);
}
++i;
}
 
if (key != 0) {
kbd_push_ev(KE_PRESS, key);
kbd_push_ev(KE_RELEASE, key);
}
 
/* Simulate modifier releasing. */
i = 0;
while (mods_keys[i][0] != 0) {
if (mod & mods_keys[i][0]) {
kbd_push_ev(KE_RELEASE, mods_keys[i][1]);
}
++i;
}
}
 
 
/**
* @}
*/
/branches/dd/uspace/srv/kbd/ctl/gxe_fb.c
0,0 → 1,322
/*
* Copyright (c) 2009 Jiri Svoboda
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
/** @addtogroup kbd_ctl
* @ingroup kbd
* @{
*/
/**
* @file
* @brief GXEmul framebuffer-mode keyboard controller driver.
*/
 
#include <kbd.h>
#include <kbd/kbd.h>
#include <kbd/keycode.h>
#include <kbd_ctl.h>
 
static void parse_ds_start(int scancode);
static void parse_ds_e(int scancode);
static void parse_ds_e1(int scancode);
static void parse_ds_e1a(int scancode);
static void parse_ds_e1b(int scancode);
static void parse_ds_e1c(int scancode);
 
static void parse_leaf(int scancode, int (*map)[2], size_t map_length);
 
enum dec_state {
ds_start,
ds_e,
ds_e1,
ds_e1a,
ds_e1b,
ds_e1c
};
 
static int map_start[][2] = {
 
[0x60] = { 0, KC_BACKTICK },
 
[0x31] = { 0, KC_1 },
[0x32] = { 0, KC_2 },
[0x33] = { 0, KC_3 },
[0x34] = { 0, KC_4 },
[0x35] = { 0, KC_5 },
[0x36] = { 0, KC_6 },
[0x37] = { 0, KC_7 },
[0x38] = { 0, KC_8 },
[0x39] = { 0, KC_9 },
[0x30] = { 0, KC_0 },
 
[0x2d] = { 0, KC_MINUS },
[0x3d] = { 0, KC_EQUALS },
[0x08] = { 0, KC_BACKSPACE },
 
[0x0f] = { 0, KC_TAB },
 
[0x71] = { 0, KC_Q },
[0x77] = { 0, KC_W },
[0x65] = { 0, KC_E },
[0x72] = { 0, KC_R },
[0x74] = { 0, KC_T },
[0x79] = { 0, KC_Y },
[0x75] = { 0, KC_U },
[0x69] = { 0, KC_I },
[0x6f] = { 0, KC_O },
[0x70] = { 0, KC_P },
 
[0x5b] = { 0, KC_LBRACKET },
[0x5d] = { 0, KC_RBRACKET },
 
[0x61] = { 0, KC_A },
[0x73] = { 0, KC_S },
[0x64] = { 0, KC_D },
[0x66] = { 0, KC_F },
[0x67] = { 0, KC_G },
[0x68] = { 0, KC_H },
[0x6a] = { 0, KC_J },
[0x6b] = { 0, KC_K },
[0x6c] = { 0, KC_L },
 
[0x3b] = { 0, KC_SEMICOLON },
[0x27] = { 0, KC_QUOTE },
[0x5c] = { 0, KC_BACKSLASH },
 
[0x7a] = { 0, KC_Z },
[0x78] = { 0, KC_X },
[0x63] = { 0, KC_C },
[0x76] = { 0, KC_V },
[0x62] = { 0, KC_B },
[0x6e] = { 0, KC_N },
[0x6d] = { 0, KC_M },
 
[0x2c] = { 0, KC_COMMA },
[0x2e] = { 0, KC_PERIOD },
[0x2f] = { 0, KC_SLASH },
 
[0x20] = { 0, KC_SPACE },
 
[0x1b] = { 0, KC_ESCAPE },
 
[0x0a] = { 0, KC_ENTER },
[0x0d] = { 0, KC_ENTER },
 
/* with Shift pressed */
 
[0x7e] = { KM_LSHIFT, KC_BACKTICK },
 
[0x21] = { KM_LSHIFT, KC_1 },
[0x40] = { KM_LSHIFT, KC_2 },
[0x23] = { KM_LSHIFT, KC_3 },
[0x24] = { KM_LSHIFT, KC_4 },
[0x25] = { KM_LSHIFT, KC_5 },
[0x5e] = { KM_LSHIFT, KC_6 },
[0x26] = { KM_LSHIFT, KC_7 },
[0x2a] = { KM_LSHIFT, KC_8 },
[0x28] = { KM_LSHIFT, KC_9 },
[0x29] = { KM_LSHIFT, KC_0 },
 
[0x5f] = { KM_LSHIFT, KC_MINUS },
[0x2b] = { KM_LSHIFT, KC_EQUALS },
 
[0x51] = { KM_LSHIFT, KC_Q },
[0x57] = { KM_LSHIFT, KC_W },
[0x45] = { KM_LSHIFT, KC_E },
[0x52] = { KM_LSHIFT, KC_R },
[0x54] = { KM_LSHIFT, KC_T },
[0x59] = { KM_LSHIFT, KC_Y },
[0x55] = { KM_LSHIFT, KC_U },
[0x49] = { KM_LSHIFT, KC_I },
[0x4f] = { KM_LSHIFT, KC_O },
[0x50] = { KM_LSHIFT, KC_P },
 
[0x7b] = { KM_LSHIFT, KC_LBRACKET },
[0x7d] = { KM_LSHIFT, KC_RBRACKET },
 
[0x41] = { KM_LSHIFT, KC_A },
[0x53] = { KM_LSHIFT, KC_S },
[0x44] = { KM_LSHIFT, KC_D },
[0x46] = { KM_LSHIFT, KC_F },
[0x47] = { KM_LSHIFT, KC_G },
[0x48] = { KM_LSHIFT, KC_H },
[0x4a] = { KM_LSHIFT, KC_J },
[0x4b] = { KM_LSHIFT, KC_K },
[0x4c] = { KM_LSHIFT, KC_L },
 
[0x3a] = { KM_LSHIFT, KC_SEMICOLON },
[0x22] = { KM_LSHIFT, KC_QUOTE },
[0x7c] = { KM_LSHIFT, KC_BACKSLASH },
 
[0x5a] = { KM_LSHIFT, KC_Z },
[0x58] = { KM_LSHIFT, KC_X },
[0x43] = { KM_LSHIFT, KC_C },
[0x56] = { KM_LSHIFT, KC_V },
[0x42] = { KM_LSHIFT, KC_B },
[0x4e] = { KM_LSHIFT, KC_N },
[0x4d] = { KM_LSHIFT, KC_M },
 
[0x3c] = { KM_LSHIFT, KC_COMMA },
[0x3e] = { KM_LSHIFT, KC_PERIOD },
[0x3f] = { KM_LSHIFT, KC_SLASH }
};
 
static int map_e1[][2] =
{
};
 
static int map_e1a[][2] =
{
[0x50] = { 0, KC_F1 },
[0x51] = { 0, KC_F2 },
[0x52] = { 0, KC_F3 },
[0x53] = { 0, KC_F4 },
};
 
static int map_e1b[][2] =
{
[0x33] = { 0, KC_F5 },
[0x37] = { 0, KC_F6 },
[0x38] = { 0, KC_F7 },
[0x39] = { 0, KC_F8 },
};
 
static int map_e1c[][2] =
{
[0x38] = { 0, KC_F9 },
[0x39] = { 0, KC_F10 },
[0x33] = { 0, KC_F11 },
[0x34] = { 0, KC_F12 },
};
 
static unsigned int mods_keys[][2] = {
{ KM_LSHIFT, KC_LSHIFT },
{ 0, 0 }
};
 
static enum dec_state ds = ds_start;
 
void kbd_ctl_parse_scancode(int scancode)
{
switch (ds) {
case ds_start: parse_ds_start(scancode); break;
case ds_e: parse_ds_e(scancode); break;
case ds_e1: parse_ds_e1(scancode); break;
case ds_e1a: parse_ds_e1a(scancode); break;
case ds_e1b: parse_ds_e1b(scancode); break;
case ds_e1c: parse_ds_e1c(scancode); break;
}
}
 
static void parse_ds_start(int scancode)
{
if (scancode == 0x1b) {
ds = ds_e;
return;
}
 
parse_leaf(scancode, map_start, sizeof(map_start) / (2 * sizeof(int)));
}
 
static void parse_ds_e(int scancode)
{
switch (scancode) {
case 0x5b: ds = ds_e1; return;
case 0x1b: ds = ds_start; break;
default: ds = ds_start; return;
}
 
kbd_push_ev(KE_PRESS, KC_ESCAPE);
}
 
static void parse_ds_e1(int scancode)
{
switch (scancode) {
case 0x4f: ds = ds_e1a; return;
case 0x31: ds = ds_e1b; return;
case 0x32: ds = ds_e1c; return;
default: ds = ds_start; break;
}
 
parse_leaf(scancode, map_e1, sizeof(map_e1) / (2 * sizeof(int)));
}
 
static void parse_ds_e1a(int scancode)
{
parse_leaf(scancode, map_e1a, sizeof(map_e1a) / (2 * sizeof(int)));
}
 
static void parse_ds_e1b(int scancode)
{
parse_leaf(scancode, map_e1b, sizeof(map_e1b) / (2 * sizeof(int)));
}
 
static void parse_ds_e1c(int scancode)
{
parse_leaf(scancode, map_e1c, sizeof(map_e1c) / (2 * sizeof(int)));
}
 
static void parse_leaf(int scancode, int (*map)[2], size_t map_length)
{
unsigned int key, mod;
int i;
 
ds = ds_start;
 
if (scancode < 0 || scancode >= map_length)
return;
 
mod = map[scancode][0];
key = map[scancode][1];
 
/* Simulate modifier pressing. */
i = 0;
while (mods_keys[i][0] != 0) {
if (mod & mods_keys[i][0]) {
kbd_push_ev(KE_PRESS, mods_keys[i][1]);
}
++i;
}
 
if (key != 0) {
kbd_push_ev(KE_PRESS, key);
kbd_push_ev(KE_RELEASE, key);
}
 
/* Simulate modifier releasing. */
i = 0;
while (mods_keys[i][0] != 0) {
if (mod & mods_keys[i][0]) {
kbd_push_ev(KE_RELEASE, mods_keys[i][1]);
}
++i;
}
}
 
/**
* @}
*/
/branches/dd/uspace/srv/kbd/ctl/pc.c
0,0 → 1,225
/*
* Copyright (c) 2009 Jiri Svoboda
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
/** @addtogroup kbd_ctl
* @ingroup kbd
* @{
*/
/**
* @file
* @brief PC keyboard controller driver.
*/
 
#include <kbd.h>
#include <kbd/kbd.h>
#include <kbd/keycode.h>
#include <kbd_ctl.h>
 
enum dec_state {
ds_s,
ds_e
};
 
static enum dec_state ds = ds_s;
 
static int scanmap_simple[] = {
 
[0x29] = KC_BACKTICK,
 
[0x02] = KC_1,
[0x03] = KC_2,
[0x04] = KC_3,
[0x05] = KC_4,
[0x06] = KC_5,
[0x07] = KC_6,
[0x08] = KC_7,
[0x09] = KC_8,
[0x0a] = KC_9,
[0x0b] = KC_0,
 
[0x0c] = KC_MINUS,
[0x0d] = KC_EQUALS,
[0x0e] = KC_BACKSPACE,
 
[0x0f] = KC_TAB,
 
[0x10] = KC_Q,
[0x11] = KC_W,
[0x12] = KC_E,
[0x13] = KC_R,
[0x14] = KC_T,
[0x15] = KC_Y,
[0x16] = KC_U,
[0x17] = KC_I,
[0x18] = KC_O,
[0x19] = KC_P,
 
[0x1a] = KC_LBRACKET,
[0x1b] = KC_RBRACKET,
 
[0x3a] = KC_CAPS_LOCK,
 
[0x1e] = KC_A,
[0x1f] = KC_S,
[0x20] = KC_D,
[0x21] = KC_F,
[0x22] = KC_G,
[0x23] = KC_H,
[0x24] = KC_J,
[0x25] = KC_K,
[0x26] = KC_L,
 
[0x27] = KC_SEMICOLON,
[0x28] = KC_QUOTE,
[0x2b] = KC_BACKSLASH,
 
[0x2a] = KC_LSHIFT,
 
[0x2c] = KC_Z,
[0x2d] = KC_X,
[0x2e] = KC_C,
[0x2f] = KC_V,
[0x30] = KC_B,
[0x31] = KC_N,
[0x32] = KC_M,
 
[0x33] = KC_COMMA,
[0x34] = KC_PERIOD,
[0x35] = KC_SLASH,
 
[0x36] = KC_RSHIFT,
 
[0x1d] = KC_LCTRL,
[0x38] = KC_LALT,
[0x39] = KC_SPACE,
 
[0x01] = KC_ESCAPE,
 
[0x3b] = KC_F1,
[0x3c] = KC_F2,
[0x3d] = KC_F3,
[0x3e] = KC_F4,
[0x3f] = KC_F5,
[0x40] = KC_F6,
[0x41] = KC_F7,
 
[0x42] = KC_F8,
[0x43] = KC_F9,
[0x44] = KC_F10,
 
[0x57] = KC_F11,
[0x58] = KC_F12,
 
[0x46] = KC_SCROLL_LOCK,
 
[0x1c] = KC_ENTER,
 
[0x45] = KC_NUM_LOCK,
[0x37] = KC_NTIMES,
[0x4a] = KC_NMINUS,
[0x4e] = KC_NPLUS,
[0x47] = KC_N7,
[0x48] = KC_N8,
[0x49] = KC_N9,
[0x4b] = KC_N4,
[0x4c] = KC_N5,
[0x4d] = KC_N6,
[0x4f] = KC_N1,
[0x50] = KC_N2,
[0x51] = KC_N3,
[0x52] = KC_N0,
[0x53] = KC_NPERIOD
};
 
static int scanmap_e0[] = {
[0x38] = KC_RALT,
[0x1d] = KC_RSHIFT,
 
[0x37] = KC_PRTSCR,
 
[0x52] = KC_INSERT,
[0x47] = KC_HOME,
[0x49] = KC_PAGE_UP,
 
[0x53] = KC_DELETE,
[0x4f] = KC_END,
[0x51] = KC_PAGE_DOWN,
 
[0x48] = KC_UP,
[0x4b] = KC_LEFT,
[0x50] = KC_DOWN,
[0x4d] = KC_RIGHT,
 
[0x35] = KC_NSLASH,
[0x1c] = KC_NENTER
};
 
 
void kbd_ctl_parse_scancode(int scancode)
{
kbd_ev_type_t type;
unsigned int key;
int *map;
size_t map_length;
 
if (scancode == 0xe0) {
ds = ds_e;
return;
}
 
switch (ds) {
case ds_s:
map = scanmap_simple;
map_length = sizeof(scanmap_simple) / sizeof(int);
break;
case ds_e:
map = scanmap_e0;
map_length = sizeof(scanmap_e0) / sizeof(int);
break;
}
 
ds = ds_s;
 
if (scancode & 0x80) {
scancode &= ~0x80;
type = KE_RELEASE;
} else {
type = KE_PRESS;
}
 
if (scancode < 0 || scancode >= map_length)
return;
 
key = map[scancode];
if (key != 0)
kbd_push_ev(type, key);
}
 
/**
* @}
*/
/branches/dd/uspace/srv/kbd/ctl/sun.c
0,0 → 1,204
/*
* Copyright (c) 2006 Jakub Jermar
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
/** @addtogroup kbd_ctl
* @ingroup kbd
* @{
*/
/**
* @file
* @brief Sun keyboard controller driver.
*/
 
#include <kbd.h>
#include <kbd/kbd.h>
#include <kbd/keycode.h>
#include <kbd_ctl.h>
 
#define KBD_KEY_RELEASE 0x80
#define KBD_ALL_KEYS_UP 0x7f
 
static int scanmap_simple[];
 
void kbd_ctl_parse_scancode(int scancode)
{
kbd_ev_type_t type;
unsigned int key;
 
if (scancode < 0 || scancode >= 0x100)
return;
 
if (scancode == KBD_ALL_KEYS_UP)
return;
 
if (scancode & KBD_KEY_RELEASE) {
scancode &= ~KBD_KEY_RELEASE;
type = KE_RELEASE;
} else {
type = KE_PRESS;
}
 
key = scanmap_simple[scancode];
if (key != 0)
kbd_push_ev(type, key);
}
 
/** Primary meaning of scancodes. */
static int scanmap_simple[] = {
[0x00] = 0,
[0x01] = 0,
[0x02] = 0,
[0x03] = 0,
[0x04] = 0,
[0x05] = KC_F1,
[0x06] = KC_F2,
[0x07] = KC_F10,
[0x08] = KC_F3,
[0x09] = KC_F11,
[0x0a] = KC_F4,
[0x0b] = KC_F12,
[0x0c] = KC_F5,
[0x0d] = KC_RALT,
[0x0e] = KC_F6,
[0x0f] = 0,
[0x10] = KC_F7,
[0x11] = KC_F8,
[0x12] = KC_F9,
[0x13] = KC_LALT,
[0x14] = KC_UP,
[0x15] = KC_PAUSE,
[0x16] = 0,
[0x17] = KC_SCROLL_LOCK,
[0x18] = KC_LEFT,
[0x19] = 0,
[0x1a] = 0,
[0x1b] = KC_DOWN,
[0x1c] = KC_RIGHT,
[0x1d] = KC_ESCAPE,
[0x1e] = KC_1,
[0x1f] = KC_2,
[0x20] = KC_3,
[0x21] = KC_4,
[0x22] = KC_5,
[0x23] = KC_6,
[0x24] = KC_7,
[0x25] = KC_8,
[0x26] = KC_9,
[0x27] = KC_0,
[0x28] = KC_MINUS,
[0x29] = KC_EQUALS,
[0x2a] = KC_BACKTICK,
[0x2b] = KC_BACKSPACE,
[0x2c] = KC_INSERT,
[0x2d] = 0,
[0x2e] = KC_NSLASH,
[0x2f] = KC_NTIMES,
[0x30] = 0,
[0x31] = 0,
[0x32] = KC_NPERIOD,
[0x33] = 0,
[0x34] = KC_HOME,
[0x35] = KC_TAB,
[0x36] = KC_Q,
[0x37] = KC_W,
[0x38] = KC_E,
[0x39] = KC_R,
[0x3a] = KC_T,
[0x3b] = KC_Y,
[0x3c] = KC_U,
[0x3d] = KC_I,
[0x3e] = KC_O,
[0x3f] = KC_P,
[0x40] = KC_LBRACKET,
[0x41] = KC_RBRACKET,
[0x42] = KC_DELETE,
[0x43] = 0,
[0x44] = KC_N7,
[0x45] = KC_N8,
[0x46] = KC_N9,
[0x47] = KC_NMINUS,
[0x48] = 0,
[0x49] = 0,
[0x4a] = KC_END,
[0x4b] = 0,
[0x4c] = KC_LCTRL,
[0x4d] = KC_A,
[0x4e] = KC_S,
[0x4f] = KC_D,
[0x50] = KC_F,
[0x51] = KC_G,
[0x52] = KC_H,
[0x53] = KC_J,
[0x54] = KC_K,
[0x55] = KC_L,
[0x56] = KC_SEMICOLON,
[0x57] = KC_QUOTE,
[0x58] = KC_BACKSLASH,
[0x59] = KC_ENTER,
[0x5a] = KC_NENTER,
[0x5b] = KC_N4,
[0x5c] = KC_N5,
[0x5d] = KC_N6,
[0x5e] = KC_N0,
[0x5f] = 0,
[0x60] = KC_PAGE_UP,
[0x61] = 0,
[0x62] = KC_NUM_LOCK,
[0x63] = KC_LSHIFT,
[0x64] = KC_Z,
[0x65] = KC_X,
[0x66] = KC_C,
[0x67] = KC_V,
[0x68] = KC_B,
[0x69] = KC_N,
[0x6a] = KC_M,
[0x6b] = KC_COMMA,
[0x6c] = KC_PERIOD,
[0x6d] = KC_SLASH,
[0x6e] = KC_RSHIFT,
[0x6f] = 0,
[0x70] = KC_N1,
[0x71] = KC_N2,
[0x72] = KC_N3,
[0x73] = 0,
[0x74] = 0,
[0x75] = 0,
[0x76] = 0,
[0x77] = KC_CAPS_LOCK,
[0x78] = 0,
[0x79] = KC_SPACE,
[0x7a] = 0,
[0x7b] = KC_PAGE_DOWN,
[0x7c] = 0,
[0x7d] = KC_NPLUS,
[0x7e] = 0,
[0x7f] = 0
};
 
/** @}
*/