Subversion Repositories HelenOS

Rev

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

Rev 4344 Rev 4346
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   GXEmul framebuffer-mode keyboard controller driver.
35
 * @brief   GXEmul framebuffer-mode 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
#include <gsp.h>
-
 
43
#include <stroke.h>
42
 
44
 
43
static void parse_ds_start(int scancode);
-
 
44
static void parse_ds_e(int scancode);
-
 
45
static void parse_ds_e1(int scancode);
-
 
46
static void parse_ds_e1a(int scancode);
-
 
47
static void parse_ds_e1b(int scancode);
-
 
48
static void parse_ds_e1c(int scancode);
-
 
49
 
-
 
50
static void parse_leaf(int scancode, int (*map)[2], size_t map_length);
-
 
51
 
-
 
52
enum dec_state {
45
/** Scancode parser */
53
    ds_start,
-
 
54
    ds_e,
-
 
55
    ds_e1,
-
 
56
    ds_e1a,
-
 
57
    ds_e1b,
-
 
58
    ds_e1c
-
 
59
};
-
 
60
 
-
 
61
static int map_start[][2] = {
46
static gsp_t sp;
62
 
47
 
63
    [0x60] = { 0, KC_BACKTICK },
48
/** Current parser state */
-
 
49
static int ds;
64
 
50
 
186
};
207
};
187
 
208
 
188
static int map_e1[][2] =
209
int kbd_ctl_init(void)
189
{
210
{
190
};
211
    ds = 0;
191
 
212
 
192
static int map_e1a[][2] =
-
 
193
{
-
 
194
    [0x50] = { 0, KC_F1 },
-
 
195
    [0x51] = { 0, KC_F2 },
-
 
196
    [0x52] = { 0, KC_F3 },
-
 
197
    [0x53] = { 0, KC_F4 },
-
 
198
};
-
 
199
 
-
 
200
static int map_e1b[][2] =
-
 
201
{
-
 
202
    [0x33] = { 0, KC_F5 },
-
 
203
    [0x37] = { 0, KC_F6 },
-
 
204
    [0x38] = { 0, KC_F7 },
-
 
205
    [0x39] = { 0, KC_F8 },
-
 
206
};
-
 
207
 
-
 
208
static int map_e1c[][2] =
-
 
209
{
-
 
210
    [0x38] = { 0, KC_F9 },
-
 
211
    [0x39] = { 0, KC_F10 },
-
 
212
    [0x33] = { 0, KC_F11 },
-
 
213
    [0x34] = { 0, KC_F12 },
-
 
214
};
-
 
215
 
-
 
216
static unsigned int mods_keys[][2] = {
-
 
217
    { KM_LSHIFT, KC_LSHIFT },
-
 
218
    { 0, 0 }
-
 
219
};
-
 
220
 
-
 
221
static enum dec_state ds = ds_start;
-
 
222
 
-
 
223
void kbd_ctl_parse_scancode(int scancode)
-
 
224
{
-
 
225
    switch (ds) {
213
    gsp_init(&sp);
226
    case ds_start:  parse_ds_start(scancode); break;
-
 
227
    case ds_e:  parse_ds_e(scancode); break;
214
    return gsp_insert_defs(&sp, seq_defs);
228
    case ds_e1: parse_ds_e1(scancode); break;
-
 
229
    case ds_e1a:    parse_ds_e1a(scancode); break;
-
 
230
    case ds_e1b:    parse_ds_e1b(scancode); break;
-
 
231
    case ds_e1c:    parse_ds_e1c(scancode); break;
-
 
232
    }
-
 
233
}
-
 
234
 
-
 
235
static void parse_ds_start(int scancode)
-
 
236
{
-
 
237
    if (scancode == 0x1b) {
-
 
238
        ds = ds_e;
-
 
239
        return;
-
 
240
    }
-
 
241
 
-
 
242
    parse_leaf(scancode, map_start, sizeof(map_start) / (2 * sizeof(int)));
-
 
243
}
215
}
244
 
216
 
245
static void parse_ds_e(int scancode)
-
 
246
{
-
 
247
    switch (scancode) {
-
 
248
    case 0x5b: ds = ds_e1; return;
-
 
249
    case 0x1b: ds = ds_start; break;
-
 
250
    default: ds = ds_start; return;
-
 
251
    }
-
 
252
 
-
 
253
    kbd_push_ev(KE_PRESS, KC_ESCAPE);
-
 
254
}
-
 
255
 
-
 
256
static void parse_ds_e1(int scancode)
-
 
257
{
-
 
258
    switch (scancode) {
-
 
259
    case 0x4f: ds = ds_e1a; return;
-
 
260
    case 0x31: ds = ds_e1b; return;
-
 
261
    case 0x32: ds = ds_e1c; return;
-
 
262
    default: ds = ds_start; break;
-
 
263
    }
-
 
264
 
-
 
265
    parse_leaf(scancode, map_e1, sizeof(map_e1) / (2 * sizeof(int)));
-
 
266
}
-
 
267
 
-
 
268
static void parse_ds_e1a(int scancode)
-
 
269
{
-
 
270
    parse_leaf(scancode, map_e1a, sizeof(map_e1a) / (2 * sizeof(int)));
-
 
271
}
-
 
272
 
-
 
273
static void parse_ds_e1b(int scancode)
-
 
274
{
-
 
275
    parse_leaf(scancode, map_e1b, sizeof(map_e1b) / (2 * sizeof(int)));
-
 
276
}
-
 
277
 
-
 
278
static void parse_ds_e1c(int scancode)
217
void kbd_ctl_parse_scancode(int scancode)
279
{
-
 
280
    parse_leaf(scancode, map_e1c, sizeof(map_e1c) / (2 * sizeof(int)));
-
 
281
}
-
 
282
 
-
 
283
static void parse_leaf(int scancode, int (*map)[2], size_t map_length)
-
 
284
{
218
{
285
    unsigned int key, mod;
219
    unsigned mods, key;
286
    int i;
-
 
287
 
-
 
288
    ds = ds_start;
-
 
289
 
-
 
290
    if (scancode < 0 || scancode >= map_length)
-
 
291
        return;
-
 
292
 
-
 
293
    mod = map[scancode][0];
-
 
294
    key = map[scancode][1];
-
 
295
 
-
 
296
    /* Simulate modifier pressing. */
-
 
297
    i = 0;
-
 
298
    while (mods_keys[i][0] != 0) {
-
 
299
        if (mod & mods_keys[i][0]) {
-
 
300
            kbd_push_ev(KE_PRESS, mods_keys[i][1]);
-
 
301
        }
-
 
302
        ++i;
-
 
303
    }
-
 
304
 
220
 
-
 
221
    ds = gsp_step(&sp, ds, scancode, &mods, &key);
305
    if (key != 0) {
222
    if (key != 0) {
306
        kbd_push_ev(KE_PRESS, key);
223
        stroke_sim(mods, key);
307
        kbd_push_ev(KE_RELEASE, key);
-
 
308
    }
-
 
309
 
-
 
310
    /* Simulate modifier releasing. */
-
 
311
    i = 0;
-
 
312
    while (mods_keys[i][0] != 0) {
-
 
313
        if (mod & mods_keys[i][0]) {
-
 
314
            kbd_push_ev(KE_RELEASE, mods_keys[i][1]);
-
 
315
        }
-
 
316
        ++i;
-
 
317
    }
224
    }
318
}
225
}
319
 
226
 
320
/**
227
/**
321
 * @}
228
 * @}
322
 */
229
 */
323
 
230