Subversion Repositories HelenOS

Rev

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

Rev 3923 Rev 3924
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
29
/** @addtogroup kbd_ctl
30
 * @brief   GXEmul framebuffer-mode keyboard controller driver.
30
 * @ingroup kbd
31
 * @{
31
 * @{
32
 */
32
 */
-
 
33
/**
-
 
34
 * @file
-
 
35
 * @brief   GXEmul framebuffer-mode keyboard controller driver.
-
 
36
 */
33
 
37
 
34
#include <kbd.h>
38
#include <kbd.h>
35
#include <kbd/kbd.h>
39
#include <kbd/kbd.h>
36
#include <kbd/keycode.h>
40
#include <kbd/keycode.h>
37
#include <kbd_ctl.h>
41
#include <kbd_ctl.h>
38
 
42
 
39
static void parse_ds_start(int scancode);
43
static void parse_ds_start(int scancode);
40
static void parse_ds_e(int scancode);
44
static void parse_ds_e(int scancode);
41
static void parse_ds_e1(int scancode);
45
static void parse_ds_e1(int scancode);
42
static void parse_ds_e1a(int scancode);
46
static void parse_ds_e1a(int scancode);
43
static void parse_ds_e1b(int scancode);
47
static void parse_ds_e1b(int scancode);
44
static void parse_ds_e1c(int scancode);
48
static void parse_ds_e1c(int scancode);
45
 
49
 
46
static void parse_leaf(int scancode, int *map, size_t map_length);
50
static void parse_leaf(int scancode, int *map, size_t map_length);
47
 
51
 
48
enum dec_state {
52
enum dec_state {
49
    ds_start,
53
    ds_start,
50
    ds_e,
54
    ds_e,
51
    ds_e1,
55
    ds_e1,
52
    ds_e1a,
56
    ds_e1a,
53
    ds_e1b,
57
    ds_e1b,
54
    ds_e1c
58
    ds_e1c
55
};
59
};
56
 
60
 
57
static int map_start[] = {
61
static int map_start[] = {
58
 
62
 
59
    [0x60] = KC_BACKTICK,
63
    [0x60] = KC_BACKTICK,
60
 
64
 
61
    [0x31] = KC_1,
65
    [0x31] = KC_1,
62
    [0x32] = KC_2,
66
    [0x32] = KC_2,
63
    [0x33] = KC_3,
67
    [0x33] = KC_3,
64
    [0x34] = KC_4,
68
    [0x34] = KC_4,
65
    [0x35] = KC_5,
69
    [0x35] = KC_5,
66
    [0x36] = KC_6,
70
    [0x36] = KC_6,
67
    [0x37] = KC_7,
71
    [0x37] = KC_7,
68
    [0x38] = KC_8,
72
    [0x38] = KC_8,
69
    [0x39] = KC_9,
73
    [0x39] = KC_9,
70
    [0x30] = KC_0,
74
    [0x30] = KC_0,
71
 
75
 
72
    [0x2d] = KC_MINUS,
76
    [0x2d] = KC_MINUS,
73
    [0x3d] = KC_EQUALS,
77
    [0x3d] = KC_EQUALS,
74
    [0x08] = KC_BACKSPACE,
78
    [0x08] = KC_BACKSPACE,
75
 
79
 
76
    [0x0f] = KC_TAB,
80
    [0x0f] = KC_TAB,
77
 
81
 
78
    [0x71] = KC_Q,
82
    [0x71] = KC_Q,
79
    [0x77] = KC_W,
83
    [0x77] = KC_W,
80
    [0x65] = KC_E,
84
    [0x65] = KC_E,
81
    [0x72] = KC_R,
85
    [0x72] = KC_R,
82
    [0x74] = KC_T,
86
    [0x74] = KC_T,
83
    [0x79] = KC_Y,
87
    [0x79] = KC_Y,
84
    [0x75] = KC_U,
88
    [0x75] = KC_U,
85
    [0x69] = KC_I,
89
    [0x69] = KC_I,
86
    [0x6f] = KC_O,
90
    [0x6f] = KC_O,
87
    [0x70] = KC_P,
91
    [0x70] = KC_P,
88
 
92
 
89
    [0x5b] = KC_LBRACKET,
93
    [0x5b] = KC_LBRACKET,
90
    [0x5d] = KC_RBRACKET,
94
    [0x5d] = KC_RBRACKET,
91
 
95
 
92
//  [0x3a] = KC_CAPS_LOCK,
96
//  [0x3a] = KC_CAPS_LOCK,
93
 
97
 
94
    [0x61] = KC_A,
98
    [0x61] = KC_A,
95
    [0x73] = KC_S,
99
    [0x73] = KC_S,
96
    [0x64] = KC_D,
100
    [0x64] = KC_D,
97
    [0x66] = KC_F,
101
    [0x66] = KC_F,
98
    [0x67] = KC_G,
102
    [0x67] = KC_G,
99
    [0x68] = KC_H,
103
    [0x68] = KC_H,
100
    [0x6a] = KC_J,
104
    [0x6a] = KC_J,
101
    [0x6b] = KC_K,
105
    [0x6b] = KC_K,
102
    [0x6c] = KC_L,
106
    [0x6c] = KC_L,
103
 
107
 
104
    [0x3b] = KC_SEMICOLON,
108
    [0x3b] = KC_SEMICOLON,
105
    [0x27] = KC_QUOTE,
109
    [0x27] = KC_QUOTE,
106
    [0x5c] = KC_BACKSLASH,
110
    [0x5c] = KC_BACKSLASH,
107
 
111
 
108
//  [0x2a] = KC_LSHIFT,
112
//  [0x2a] = KC_LSHIFT,
109
 
113
 
110
    [0x7a] = KC_Z,
114
    [0x7a] = KC_Z,
111
    [0x78] = KC_X,
115
    [0x78] = KC_X,
112
    [0x63] = KC_C,
116
    [0x63] = KC_C,
113
    [0x76] = KC_V,
117
    [0x76] = KC_V,
114
    [0x62] = KC_B,
118
    [0x62] = KC_B,
115
    [0x6e] = KC_N,
119
    [0x6e] = KC_N,
116
    [0x6d] = KC_M,
120
    [0x6d] = KC_M,
117
 
121
 
118
    [0x2c] = KC_COMMA,
122
    [0x2c] = KC_COMMA,
119
    [0x2e] = KC_PERIOD,
123
    [0x2e] = KC_PERIOD,
120
    [0x2f] = KC_SLASH,
124
    [0x2f] = KC_SLASH,
121
 
125
 
122
//  [0x36] = KC_RSHIFT,
126
//  [0x36] = KC_RSHIFT,
123
 
127
 
124
//  [0x1d] = KC_LCTRL,
128
//  [0x1d] = KC_LCTRL,
125
//  [0x38] = KC_LALT,
129
//  [0x38] = KC_LALT,
126
    [0x20] = KC_SPACE,
130
    [0x20] = KC_SPACE,
127
 
131
 
128
    [0x1b] = KC_ESCAPE,
132
    [0x1b] = KC_ESCAPE,
129
 
133
 
130
    [0x0a] = KC_ENTER,
134
    [0x0a] = KC_ENTER,
131
    [0x0d] = KC_ENTER
135
    [0x0d] = KC_ENTER
132
 
136
 
133
/*
137
/*
134
    [0x1] = KC_PRNSCR,
138
    [0x1] = KC_PRNSCR,
135
    [0x1] = KC_SCROLL_LOCK,
139
    [0x1] = KC_SCROLL_LOCK,
136
    [0x1] = KC_PAUSE,
140
    [0x1] = KC_PAUSE,
137
*/
141
*/
138
};
142
};
139
 
143
 
140
static int map_e1[] =
144
static int map_e1[] =
141
{
145
{
142
};
146
};
143
 
147
 
144
static int map_e1a[] =
148
static int map_e1a[] =
145
{
149
{
146
    [0x50] = KC_F1,
150
    [0x50] = KC_F1,
147
    [0x51] = KC_F2,
151
    [0x51] = KC_F2,
148
    [0x52] = KC_F3,
152
    [0x52] = KC_F3,
149
    [0x53] = KC_F4,
153
    [0x53] = KC_F4,
150
};
154
};
151
 
155
 
152
static int map_e1b[] =
156
static int map_e1b[] =
153
{
157
{
154
    [0x33] = KC_F5,
158
    [0x33] = KC_F5,
155
    [0x37] = KC_F6,
159
    [0x37] = KC_F6,
156
    [0x38] = KC_F7,
160
    [0x38] = KC_F7,
157
    [0x39] = KC_F8,
161
    [0x39] = KC_F8,
158
};
162
};
159
 
163
 
160
static int map_e1c[] =
164
static int map_e1c[] =
161
{
165
{
162
    [0x38] = KC_F9,
166
    [0x38] = KC_F9,
163
    [0x39] = KC_F10,
167
    [0x39] = KC_F10,
164
    [0x33] = KC_F11,
168
    [0x33] = KC_F11,
165
    [0x34] = KC_F12,
169
    [0x34] = KC_F12,
166
};
170
};
167
 
171
 
168
 
172
 
169
static enum dec_state ds = ds_start;
173
static enum dec_state ds = ds_start;
170
 
174
 
171
void kbd_ctl_parse_scancode(int scancode)
175
void kbd_ctl_parse_scancode(int scancode)
172
{
176
{
173
    switch (ds) {
177
    switch (ds) {
174
    case ds_start:  parse_ds_start(scancode); break;
178
    case ds_start:  parse_ds_start(scancode); break;
175
    case ds_e:  parse_ds_e(scancode); break;
179
    case ds_e:  parse_ds_e(scancode); break;
176
    case ds_e1: parse_ds_e1(scancode); break;
180
    case ds_e1: parse_ds_e1(scancode); break;
177
    case ds_e1a:    parse_ds_e1a(scancode); break;
181
    case ds_e1a:    parse_ds_e1a(scancode); break;
178
    case ds_e1b:    parse_ds_e1b(scancode); break;
182
    case ds_e1b:    parse_ds_e1b(scancode); break;
179
    case ds_e1c:    parse_ds_e1c(scancode); break;
183
    case ds_e1c:    parse_ds_e1c(scancode); break;
180
    }
184
    }
181
}
185
}
182
 
186
 
183
static void parse_ds_start(int scancode)
187
static void parse_ds_start(int scancode)
184
{
188
{
185
    if (scancode == 0x1b) {
189
    if (scancode == 0x1b) {
186
        ds = ds_e;
190
        ds = ds_e;
187
        return;
191
        return;
188
    }
192
    }
189
 
193
 
190
    parse_leaf(scancode, map_start, sizeof(map_start) / sizeof(int));
194
    parse_leaf(scancode, map_start, sizeof(map_start) / sizeof(int));
191
}
195
}
192
 
196
 
193
static void parse_ds_e(int scancode)
197
static void parse_ds_e(int scancode)
194
{
198
{
195
    switch (scancode) {
199
    switch (scancode) {
196
    case 0x5b: ds = ds_e1; return;
200
    case 0x5b: ds = ds_e1; return;
197
    case 0x1b: ds = ds_start; break;
201
    case 0x1b: ds = ds_start; break;
198
    default: ds = ds_start; return;
202
    default: ds = ds_start; return;
199
    }
203
    }
200
 
204
 
201
    kbd_push_ev(KE_PRESS, KC_ESCAPE, 0);
205
    kbd_push_ev(KE_PRESS, KC_ESCAPE, 0);
202
}
206
}
203
 
207
 
204
static void parse_ds_e1(int scancode)
208
static void parse_ds_e1(int scancode)
205
{
209
{
206
    switch (scancode) {
210
    switch (scancode) {
207
    case 0x4f: ds = ds_e1a; return;
211
    case 0x4f: ds = ds_e1a; return;
208
    case 0x31: ds = ds_e1b; return;
212
    case 0x31: ds = ds_e1b; return;
209
    case 0x32: ds = ds_e1c; return;
213
    case 0x32: ds = ds_e1c; return;
210
    default: ds = ds_start; break;
214
    default: ds = ds_start; break;
211
    }
215
    }
212
 
216
 
213
    parse_leaf(scancode, map_e1, sizeof(map_e1) / sizeof(int));
217
    parse_leaf(scancode, map_e1, sizeof(map_e1) / sizeof(int));
214
}
218
}
215
 
219
 
216
static void parse_ds_e1a(int scancode)
220
static void parse_ds_e1a(int scancode)
217
{
221
{
218
    parse_leaf(scancode, map_e1a, sizeof(map_e1a) / sizeof(int));
222
    parse_leaf(scancode, map_e1a, sizeof(map_e1a) / sizeof(int));
219
}
223
}
220
 
224
 
221
static void parse_ds_e1b(int scancode)
225
static void parse_ds_e1b(int scancode)
222
{
226
{
223
    parse_leaf(scancode, map_e1b, sizeof(map_e1b) / sizeof(int));
227
    parse_leaf(scancode, map_e1b, sizeof(map_e1b) / sizeof(int));
224
}
228
}
225
 
229
 
226
static void parse_ds_e1c(int scancode)
230
static void parse_ds_e1c(int scancode)
227
{
231
{
228
    parse_leaf(scancode, map_e1c, sizeof(map_e1c) / sizeof(int));
232
    parse_leaf(scancode, map_e1c, sizeof(map_e1c) / sizeof(int));
229
}
233
}
230
 
234
 
231
static void parse_leaf(int scancode, int *map, size_t map_length)
235
static void parse_leaf(int scancode, int *map, size_t map_length)
232
{
236
{
233
    unsigned int key;
237
    unsigned int key;
234
 
238
 
235
    ds = ds_start;
239
    ds = ds_start;
236
 
240
 
237
    if (scancode < 0 || scancode >= map_length)
241
    if (scancode < 0 || scancode >= map_length)
238
        return;
242
        return;
239
 
243
 
240
    key = map[scancode];
244
    key = map[scancode];
241
    if (key != 0)
245
    if (key != 0)
242
        kbd_push_ev(KE_PRESS, key, 0);
246
        kbd_push_ev(KE_PRESS, key, 0);
243
}
247
}
244
 
248
 
245
 
249
 
246
/**
250
/**
247
 * @}
251
 * @}
248
 */
252
 */
249
 
253