Subversion Repositories HelenOS

Rev

Rev 4581 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4581 Rev 4718
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 <io/console.h>
39
#include <io/console.h>
40
#include <io/keycode.h>
40
#include <io/keycode.h>
41
#include <kbd_ctl.h>
41
#include <kbd_ctl.h>
42
#include <gsp.h>
42
#include <gsp.h>
43
 
43
 
44
enum dec_state {
44
enum dec_state {
45
    ds_s,
45
    ds_s,
46
    ds_e
46
    ds_e
47
};
47
};
48
 
48
 
49
static enum dec_state ds;
49
static enum dec_state ds;
50
 
50
 
51
static int scanmap_simple[] = {
51
static int scanmap_simple[] = {
52
 
52
 
53
    [0x29] = KC_BACKTICK,
53
    [0x29] = KC_BACKTICK,
54
 
54
 
55
    [0x02] = KC_1,
55
    [0x02] = KC_1,
56
    [0x03] = KC_2,
56
    [0x03] = KC_2,
57
    [0x04] = KC_3,
57
    [0x04] = KC_3,
58
    [0x05] = KC_4,
58
    [0x05] = KC_4,
59
    [0x06] = KC_5,
59
    [0x06] = KC_5,
60
    [0x07] = KC_6,
60
    [0x07] = KC_6,
61
    [0x08] = KC_7,
61
    [0x08] = KC_7,
62
    [0x09] = KC_8,
62
    [0x09] = KC_8,
63
    [0x0a] = KC_9,
63
    [0x0a] = KC_9,
64
    [0x0b] = KC_0,
64
    [0x0b] = KC_0,
65
 
65
 
66
    [0x0c] = KC_MINUS,
66
    [0x0c] = KC_MINUS,
67
    [0x0d] = KC_EQUALS,
67
    [0x0d] = KC_EQUALS,
68
    [0x0e] = KC_BACKSPACE,
68
    [0x0e] = KC_BACKSPACE,
69
 
69
 
70
    [0x0f] = KC_TAB,
70
    [0x0f] = KC_TAB,
71
 
71
 
72
    [0x10] = KC_Q,
72
    [0x10] = KC_Q,
73
    [0x11] = KC_W,
73
    [0x11] = KC_W,
74
    [0x12] = KC_E,
74
    [0x12] = KC_E,
75
    [0x13] = KC_R,
75
    [0x13] = KC_R,
76
    [0x14] = KC_T,
76
    [0x14] = KC_T,
77
    [0x15] = KC_Y,
77
    [0x15] = KC_Y,
78
    [0x16] = KC_U,
78
    [0x16] = KC_U,
79
    [0x17] = KC_I,
79
    [0x17] = KC_I,
80
    [0x18] = KC_O,
80
    [0x18] = KC_O,
81
    [0x19] = KC_P,
81
    [0x19] = KC_P,
82
 
82
 
83
    [0x1a] = KC_LBRACKET,
83
    [0x1a] = KC_LBRACKET,
84
    [0x1b] = KC_RBRACKET,
84
    [0x1b] = KC_RBRACKET,
85
 
85
 
86
    [0x3a] = KC_CAPS_LOCK,
86
    [0x3a] = KC_CAPS_LOCK,
87
 
87
 
88
    [0x1e] = KC_A,
88
    [0x1e] = KC_A,
89
    [0x1f] = KC_S,
89
    [0x1f] = KC_S,
90
    [0x20] = KC_D,
90
    [0x20] = KC_D,
91
    [0x21] = KC_F,
91
    [0x21] = KC_F,
92
    [0x22] = KC_G,
92
    [0x22] = KC_G,
93
    [0x23] = KC_H,
93
    [0x23] = KC_H,
94
    [0x24] = KC_J,
94
    [0x24] = KC_J,
95
    [0x25] = KC_K,
95
    [0x25] = KC_K,
96
    [0x26] = KC_L,
96
    [0x26] = KC_L,
97
 
97
 
98
    [0x27] = KC_SEMICOLON,
98
    [0x27] = KC_SEMICOLON,
99
    [0x28] = KC_QUOTE,
99
    [0x28] = KC_QUOTE,
100
    [0x2b] = KC_BACKSLASH,
100
    [0x2b] = KC_BACKSLASH,
101
 
101
 
102
    [0x2a] = KC_LSHIFT,
102
    [0x2a] = KC_LSHIFT,
103
 
103
 
104
    [0x2c] = KC_Z,
104
    [0x2c] = KC_Z,
105
    [0x2d] = KC_X,
105
    [0x2d] = KC_X,
106
    [0x2e] = KC_C,
106
    [0x2e] = KC_C,
107
    [0x2f] = KC_V,
107
    [0x2f] = KC_V,
108
    [0x30] = KC_B,
108
    [0x30] = KC_B,
109
    [0x31] = KC_N,
109
    [0x31] = KC_N,
110
    [0x32] = KC_M,
110
    [0x32] = KC_M,
111
 
111
 
112
    [0x33] = KC_COMMA,
112
    [0x33] = KC_COMMA,
113
    [0x34] = KC_PERIOD,
113
    [0x34] = KC_PERIOD,
114
    [0x35] = KC_SLASH,
114
    [0x35] = KC_SLASH,
115
 
115
 
116
    [0x36] = KC_RSHIFT,
116
    [0x36] = KC_RSHIFT,
117
 
117
 
118
    [0x1d] = KC_LCTRL,
118
    [0x1d] = KC_LCTRL,
119
    [0x38] = KC_LALT,
119
    [0x38] = KC_LALT,
120
    [0x39] = KC_SPACE,
120
    [0x39] = KC_SPACE,
121
 
121
 
122
    [0x01] = KC_ESCAPE,
122
    [0x01] = KC_ESCAPE,
123
 
123
 
124
    [0x3b] = KC_F1,
124
    [0x3b] = KC_F1,
125
    [0x3c] = KC_F2,
125
    [0x3c] = KC_F2,
126
    [0x3d] = KC_F3,
126
    [0x3d] = KC_F3,
127
    [0x3e] = KC_F4,
127
    [0x3e] = KC_F4,
128
    [0x3f] = KC_F5,
128
    [0x3f] = KC_F5,
129
    [0x40] = KC_F6,
129
    [0x40] = KC_F6,
130
    [0x41] = KC_F7,
130
    [0x41] = KC_F7,
131
 
131
 
132
    [0x42] = KC_F8,
132
    [0x42] = KC_F8,
133
    [0x43] = KC_F9,
133
    [0x43] = KC_F9,
134
    [0x44] = KC_F10,
134
    [0x44] = KC_F10,
135
 
135
 
136
    [0x57] = KC_F11,
136
    [0x57] = KC_F11,
137
    [0x58] = KC_F12,
137
    [0x58] = KC_F12,
138
 
138
 
139
    [0x46] = KC_SCROLL_LOCK,
139
    [0x46] = KC_SCROLL_LOCK,
140
 
140
 
141
    [0x1c] = KC_ENTER,
141
    [0x1c] = KC_ENTER,
142
 
142
 
143
    [0x45] = KC_NUM_LOCK,
143
    [0x45] = KC_NUM_LOCK,
144
    [0x37] = KC_NTIMES,
144
    [0x37] = KC_NTIMES,
145
    [0x4a] = KC_NMINUS,
145
    [0x4a] = KC_NMINUS,
146
    [0x4e] = KC_NPLUS,
146
    [0x4e] = KC_NPLUS,
147
    [0x47] = KC_N7,
147
    [0x47] = KC_N7,
148
    [0x48] = KC_N8,
148
    [0x48] = KC_N8,
149
    [0x49] = KC_N9,
149
    [0x49] = KC_N9,
150
    [0x4b] = KC_N4,
150
    [0x4b] = KC_N4,
151
    [0x4c] = KC_N5,
151
    [0x4c] = KC_N5,
152
    [0x4d] = KC_N6,
152
    [0x4d] = KC_N6,
153
    [0x4f] = KC_N1,
153
    [0x4f] = KC_N1,
154
    [0x50] = KC_N2,
154
    [0x50] = KC_N2,
155
    [0x51] = KC_N3,
155
    [0x51] = KC_N3,
156
    [0x52] = KC_N0,
156
    [0x52] = KC_N0,
157
    [0x53] = KC_NPERIOD
157
    [0x53] = KC_NPERIOD
158
};
158
};
159
 
159
 
160
static int scanmap_e0[] = {
160
static int scanmap_e0[] = {
161
    [0x38] = KC_RALT,
161
    [0x38] = KC_RALT,
162
    [0x1d] = KC_RSHIFT,
162
    [0x1d] = KC_RSHIFT,
163
 
163
 
164
    [0x37] = KC_PRTSCR,
164
    [0x37] = KC_PRTSCR,
165
 
165
 
166
    [0x52] = KC_INSERT,
166
    [0x52] = KC_INSERT,
167
    [0x47] = KC_HOME,
167
    [0x47] = KC_HOME,
168
    [0x49] = KC_PAGE_UP,
168
    [0x49] = KC_PAGE_UP,
169
 
169
 
170
    [0x53] = KC_DELETE,
170
    [0x53] = KC_DELETE,
171
    [0x4f] = KC_END,
171
    [0x4f] = KC_END,
172
    [0x51] = KC_PAGE_DOWN,
172
    [0x51] = KC_PAGE_DOWN,
173
 
173
 
174
    [0x48] = KC_UP,
174
    [0x48] = KC_UP,
175
    [0x4b] = KC_LEFT,
175
    [0x4b] = KC_LEFT,
176
    [0x50] = KC_DOWN,
176
    [0x50] = KC_DOWN,
177
    [0x4d] = KC_RIGHT,
177
    [0x4d] = KC_RIGHT,
178
 
178
 
179
    [0x35] = KC_NSLASH,
179
    [0x35] = KC_NSLASH,
180
    [0x1c] = KC_NENTER
180
    [0x1c] = KC_NENTER
181
};
181
};
182
 
182
 
183
int kbd_ctl_init(void)
183
int kbd_ctl_init(void)
184
{
184
{
185
    ds = ds_s;
185
    ds = ds_s;
186
    return 0;
186
    return 0;
187
}
187
}
188
 
188
 
189
void kbd_ctl_parse_scancode(int scancode)
189
void kbd_ctl_parse_scancode(int scancode)
190
{
190
{
191
    console_ev_type_t type;
191
    console_ev_type_t type;
192
    unsigned int key;
192
    unsigned int key;
193
    int *map;
193
    int *map;
194
    size_t map_length;
194
    size_t map_length;
195
 
195
 
196
    if (scancode == 0xe0) {
196
    if (scancode == 0xe0) {
197
        ds = ds_e;
197
        ds = ds_e;
198
        return;
198
        return;
199
    }
199
    }
200
 
200
 
201
    switch (ds) {
201
    switch (ds) {
202
    case ds_s:
202
    case ds_s:
203
        map = scanmap_simple;
203
        map = scanmap_simple;
204
        map_length = sizeof(scanmap_simple) / sizeof(int);
204
        map_length = sizeof(scanmap_simple) / sizeof(int);
205
        break;
205
        break;
206
    case ds_e:
206
    case ds_e:
207
        map = scanmap_e0;
207
        map = scanmap_e0;
208
        map_length = sizeof(scanmap_e0) / sizeof(int);
208
        map_length = sizeof(scanmap_e0) / sizeof(int);
209
        break;
209
        break;
-
 
210
    default:
-
 
211
        map = NULL;
-
 
212
        map_length = 0;
210
    }
213
    }
211
 
214
 
212
    ds = ds_s;
215
    ds = ds_s;
213
 
216
 
214
    if (scancode & 0x80) {
217
    if (scancode & 0x80) {
215
        scancode &= ~0x80;
218
        scancode &= ~0x80;
216
        type = KEY_RELEASE;
219
        type = KEY_RELEASE;
217
    } else {
220
    } else {
218
        type = KEY_PRESS;
221
        type = KEY_PRESS;
219
    }
222
    }
220
 
223
 
221
    if (scancode < 0 || scancode >= map_length)
224
    if ((scancode < 0) || ((size_t) scancode >= map_length))
222
        return;
225
        return;
223
 
226
 
224
    key = map[scancode];
227
    key = map[scancode];
225
    if (key != 0)
228
    if (key != 0)
226
        kbd_push_ev(type, key);
229
        kbd_push_ev(type, key);
227
}
230
}
228
 
231
 
229
/**
232
/**
230
 * @}
233
 * @}
231
 */
234
 */
232
 
235