Subversion Repositories HelenOS

Rev

Rev 4343 | Rev 4346 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4343 Rev 4344
1
/*
1
/*
2
 * Copyright (c) 2009 Jiri Svoboda
2
 * Copyright (c) 2009 Jiri Svoboda
3
 * All rights reserved.
3
 * All rights reserved.
4
 *
4
 *
5
 * Redistribution and use in source and binary forms, with or without
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
6
 * modification, are permitted provided that the following conditions
7
 * are met:
7
 * are met:
8
 *
8
 *
9
 * - Redistributions of source code must retain the above copyright
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
12
 *   notice, this list of conditions and the following disclaimer in the
13
 *   documentation and/or other materials provided with the distribution.
13
 *   documentation and/or other materials provided with the distribution.
14
 * - The name of the author may not be used to endorse or promote products
14
 * - The name of the author may not be used to endorse or promote products
15
 *   derived from this software without specific prior written permission.
15
 *   derived from this software without specific prior written permission.
16
 *
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
27
 */
28
 
28
 
29
/** @addtogroup kbd_ctl
29
/** @addtogroup kbd_ctl
30
 * @ingroup kbd
30
 * @ingroup kbd
31
 * @{
31
 * @{
32
 */
32
 */
33
/**
33
/**
34
 * @file
34
 * @file
35
 * @brief   PC keyboard controller driver.
35
 * @brief   PC keyboard controller driver.
36
 */
36
 */
37
 
37
 
38
#include <kbd.h>
38
#include <kbd.h>
39
#include <kbd/kbd.h>
39
#include <kbd/kbd.h>
40
#include <kbd/keycode.h>
40
#include <kbd/keycode.h>
41
#include <kbd_ctl.h>
41
#include <kbd_ctl.h>
42
 
42
 
43
static int scanmap_simple[];
-
 
44
 
-
 
45
void kbd_ctl_parse_scancode(int scancode)
-
 
46
{
-
 
47
    kbd_ev_type_t type;
-
 
48
    unsigned int key;
43
enum dec_state {
49
 
-
 
50
    if (scancode < 0 || scancode >= 0x100)
-
 
51
        return;
44
    ds_s,
52
 
-
 
53
    if (scancode & 0x80) {
-
 
54
        scancode &= ~0x80;
-
 
55
        type = KE_RELEASE;
-
 
56
    } else {
45
    ds_e
57
        type = KE_PRESS;
-
 
58
    }
46
};
59
 
47
 
60
    key = scanmap_simple[scancode];
-
 
61
    if (key != 0)
-
 
62
        kbd_push_ev(type, key, 0);
48
static enum dec_state ds = ds_s;
63
}
-
 
64
 
49
 
65
static int scanmap_simple[128] = {
50
static int scanmap_simple[] = {
66
 
51
 
67
    [0x29] = KC_BACKTICK,
52
    [0x29] = KC_BACKTICK,
68
 
53
 
69
    [0x02] = KC_1,
54
    [0x02] = KC_1,
70
    [0x03] = KC_2,
55
    [0x03] = KC_2,
71
    [0x04] = KC_3,
56
    [0x04] = KC_3,
72
    [0x05] = KC_4,
57
    [0x05] = KC_4,
73
    [0x06] = KC_5,
58
    [0x06] = KC_5,
74
    [0x07] = KC_6,
59
    [0x07] = KC_6,
75
    [0x08] = KC_7,
60
    [0x08] = KC_7,
76
    [0x09] = KC_8,
61
    [0x09] = KC_8,
77
    [0x0a] = KC_9,
62
    [0x0a] = KC_9,
78
    [0x0b] = KC_0,
63
    [0x0b] = KC_0,
79
 
64
 
80
    [0x0c] = KC_MINUS,
65
    [0x0c] = KC_MINUS,
81
    [0x0d] = KC_EQUALS,
66
    [0x0d] = KC_EQUALS,
82
    [0x0e] = KC_BACKSPACE,
67
    [0x0e] = KC_BACKSPACE,
83
 
68
 
84
    [0x0f] = KC_TAB,
69
    [0x0f] = KC_TAB,
85
 
70
 
86
    [0x10] = KC_Q,
71
    [0x10] = KC_Q,
87
    [0x11] = KC_W,
72
    [0x11] = KC_W,
88
    [0x12] = KC_E,
73
    [0x12] = KC_E,
89
    [0x13] = KC_R,
74
    [0x13] = KC_R,
90
    [0x14] = KC_T,
75
    [0x14] = KC_T,
91
    [0x15] = KC_Y,
76
    [0x15] = KC_Y,
92
    [0x16] = KC_U,
77
    [0x16] = KC_U,
93
    [0x17] = KC_I,
78
    [0x17] = KC_I,
94
    [0x18] = KC_O,
79
    [0x18] = KC_O,
95
    [0x19] = KC_P,
80
    [0x19] = KC_P,
96
 
81
 
97
    [0x1a] = KC_LBRACKET,
82
    [0x1a] = KC_LBRACKET,
98
    [0x1b] = KC_RBRACKET,
83
    [0x1b] = KC_RBRACKET,
99
 
84
 
100
    [0x3a] = KC_CAPS_LOCK,
85
    [0x3a] = KC_CAPS_LOCK,
101
 
86
 
102
    [0x1e] = KC_A,
87
    [0x1e] = KC_A,
103
    [0x1f] = KC_S,
88
    [0x1f] = KC_S,
104
    [0x20] = KC_D,
89
    [0x20] = KC_D,
105
    [0x21] = KC_F,
90
    [0x21] = KC_F,
106
    [0x22] = KC_G,
91
    [0x22] = KC_G,
107
    [0x23] = KC_H,
92
    [0x23] = KC_H,
108
    [0x24] = KC_J,
93
    [0x24] = KC_J,
109
    [0x25] = KC_K,
94
    [0x25] = KC_K,
110
    [0x26] = KC_L,
95
    [0x26] = KC_L,
111
 
96
 
112
    [0x27] = KC_SEMICOLON,
97
    [0x27] = KC_SEMICOLON,
113
    [0x28] = KC_QUOTE,
98
    [0x28] = KC_QUOTE,
114
    [0x2b] = KC_BACKSLASH,
99
    [0x2b] = KC_BACKSLASH,
115
 
100
 
116
    [0x2a] = KC_LSHIFT,
101
    [0x2a] = KC_LSHIFT,
117
 
102
 
118
    [0x2c] = KC_Z,
103
    [0x2c] = KC_Z,
119
    [0x2d] = KC_X,
104
    [0x2d] = KC_X,
120
    [0x2e] = KC_C,
105
    [0x2e] = KC_C,
121
    [0x2f] = KC_V,
106
    [0x2f] = KC_V,
122
    [0x30] = KC_B,
107
    [0x30] = KC_B,
123
    [0x31] = KC_N,
108
    [0x31] = KC_N,
124
    [0x32] = KC_M,
109
    [0x32] = KC_M,
125
 
110
 
126
    [0x33] = KC_COMMA,
111
    [0x33] = KC_COMMA,
127
    [0x34] = KC_PERIOD,
112
    [0x34] = KC_PERIOD,
128
    [0x35] = KC_SLASH,
113
    [0x35] = KC_SLASH,
129
 
114
 
130
    [0x36] = KC_RSHIFT,
115
    [0x36] = KC_RSHIFT,
131
 
116
 
132
    [0x1d] = KC_LCTRL,
117
    [0x1d] = KC_LCTRL,
133
    [0x38] = KC_LALT,
118
    [0x38] = KC_LALT,
134
    [0x39] = KC_SPACE,
119
    [0x39] = KC_SPACE,
135
 
120
 
136
    [0x01] = KC_ESCAPE,
121
    [0x01] = KC_ESCAPE,
137
 
122
 
138
    [0x3b] = KC_F1,
123
    [0x3b] = KC_F1,
139
    [0x3c] = KC_F2,
124
    [0x3c] = KC_F2,
140
    [0x3d] = KC_F3,
125
    [0x3d] = KC_F3,
141
    [0x3e] = KC_F4,
126
    [0x3e] = KC_F4,
142
    [0x3f] = KC_F5,
127
    [0x3f] = KC_F5,
143
    [0x40] = KC_F6,
128
    [0x40] = KC_F6,
144
    [0x41] = KC_F7,
129
    [0x41] = KC_F7,
145
 
130
 
146
    [0x42] = KC_F8,
131
    [0x42] = KC_F8,
147
    [0x43] = KC_F9,
132
    [0x43] = KC_F9,
148
    [0x44] = KC_F10,
133
    [0x44] = KC_F10,
149
 
134
 
150
    [0x57] = KC_F11,
135
    [0x57] = KC_F11,
151
    [0x58] = KC_F12,
136
    [0x58] = KC_F12,
152
 
137
 
-
 
138
    [0x46] = KC_SCROLL_LOCK,
-
 
139
 
153
    [0x1c] = KC_ENTER
140
    [0x1c] = KC_ENTER,
154
 
141
 
-
 
142
    [0x45] = KC_NUM_LOCK,
-
 
143
    [0x37] = KC_NTIMES,
-
 
144
    [0x4a] = KC_NMINUS,
-
 
145
    [0x4e] = KC_NPLUS,
-
 
146
    [0x47] = KC_N7,
-
 
147
    [0x48] = KC_N8,
-
 
148
    [0x49] = KC_N9,
155
/*
149
    [0x4b] = KC_N4,
156
    [0x1] = KC_PRNSCR,
150
    [0x4c] = KC_N5,
-
 
151
    [0x4d] = KC_N6,
-
 
152
    [0x4f] = KC_N1,
157
    [0x1] = KC_SCROLL_LOCK,
153
    [0x50] = KC_N2,
158
    [0x1] = KC_PAUSE,
154
    [0x51] = KC_N3,
159
*/
155
    [0x52] = KC_N0,
-
 
156
    [0x53] = KC_NPERIOD
160
};
157
};
161
 
158
 
-
 
159
static int scanmap_e0[] = {
-
 
160
    [0x38] = KC_RALT,
-
 
161
    [0x1d] = KC_RSHIFT,
-
 
162
 
-
 
163
    [0x37] = KC_PRTSCR,
-
 
164
 
-
 
165
    [0x52] = KC_INSERT,
-
 
166
    [0x47] = KC_HOME,
-
 
167
    [0x49] = KC_PAGE_UP,
-
 
168
 
-
 
169
    [0x53] = KC_DELETE,
-
 
170
    [0x4f] = KC_END,
-
 
171
    [0x51] = KC_PAGE_DOWN,
-
 
172
 
-
 
173
    [0x48] = KC_UP,
-
 
174
    [0x4b] = KC_LEFT,
-
 
175
    [0x50] = KC_DOWN,
-
 
176
    [0x4d] = KC_RIGHT,
-
 
177
 
-
 
178
    [0x35] = KC_NSLASH,
-
 
179
    [0x1c] = KC_NENTER
-
 
180
};
-
 
181
 
-
 
182
 
-
 
183
void kbd_ctl_parse_scancode(int scancode)
-
 
184
{
-
 
185
    kbd_ev_type_t type;
-
 
186
    unsigned int key;
-
 
187
    int *map;
-
 
188
    size_t map_length;
-
 
189
 
-
 
190
    if (scancode == 0xe0) {
-
 
191
        ds = ds_e;
-
 
192
        return;
-
 
193
    }
-
 
194
 
-
 
195
    switch (ds) {
-
 
196
    case ds_s:
-
 
197
        map = scanmap_simple;
-
 
198
        map_length = sizeof(scanmap_simple) / sizeof(int);
-
 
199
        break;
-
 
200
    case ds_e:
-
 
201
        map = scanmap_e0;
-
 
202
        map_length = sizeof(scanmap_e0) / sizeof(int);
-
 
203
        break;
-
 
204
    }
-
 
205
 
-
 
206
    ds = ds_s;
-
 
207
 
-
 
208
    if (scancode & 0x80) {
-
 
209
        scancode &= ~0x80;
-
 
210
        type = KE_RELEASE;
-
 
211
    } else {
-
 
212
        type = KE_PRESS;
-
 
213
    }
-
 
214
 
-
 
215
    if (scancode < 0 || scancode >= map_length)
-
 
216
        return;
-
 
217
 
-
 
218
    key = map[scancode];
-
 
219
    if (key != 0)
-
 
220
        kbd_push_ev(type, key);
-
 
221
}
-
 
222
 
162
/**
223
/**
163
 * @}
224
 * @}
164
 */
225
 */
165
 
226