Subversion Repositories HelenOS

Rev

Rev 3933 | Rev 3944 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3923 svoboda 1
/*
2
 * Copyright (c) 2009 Jiri Svoboda
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 *
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
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
15
 *   derived from this software without specific prior written permission.
16
 *
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
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
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
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
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
28
 
3924 svoboda 29
/** @addtogroup kbd_ctl
30
 * @ingroup kbd
31
 * @{
32
 */
33
/**
34
 * @file
3923 svoboda 35
 * @brief   GXEmul framebuffer-mode keyboard controller driver.
3924 svoboda 36
 */
3923 svoboda 37
 
38
#include <kbd.h>
39
#include <kbd/kbd.h>
40
#include <kbd/keycode.h>
41
#include <kbd_ctl.h>
42
 
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, size_t map_length);
51
 
52
enum dec_state {
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[] = {
62
 
63
    [0x60] = KC_BACKTICK,
64
 
65
    [0x31] = KC_1,
66
    [0x32] = KC_2,
67
    [0x33] = KC_3,
68
    [0x34] = KC_4,
69
    [0x35] = KC_5,
70
    [0x36] = KC_6,
71
    [0x37] = KC_7,
72
    [0x38] = KC_8,
73
    [0x39] = KC_9,
74
    [0x30] = KC_0,
75
 
76
    [0x2d] = KC_MINUS,
77
    [0x3d] = KC_EQUALS,
78
    [0x08] = KC_BACKSPACE,
79
 
80
    [0x0f] = KC_TAB,
81
 
82
    [0x71] = KC_Q,
83
    [0x77] = KC_W,
84
    [0x65] = KC_E,
85
    [0x72] = KC_R,
86
    [0x74] = KC_T,
87
    [0x79] = KC_Y,
88
    [0x75] = KC_U,
89
    [0x69] = KC_I,
90
    [0x6f] = KC_O,
91
    [0x70] = KC_P,
92
 
93
    [0x5b] = KC_LBRACKET,
94
    [0x5d] = KC_RBRACKET,
95
 
96
//  [0x3a] = KC_CAPS_LOCK,
97
 
98
    [0x61] = KC_A,
99
    [0x73] = KC_S,
100
    [0x64] = KC_D,
101
    [0x66] = KC_F,
102
    [0x67] = KC_G,
103
    [0x68] = KC_H,
104
    [0x6a] = KC_J,
105
    [0x6b] = KC_K,
106
    [0x6c] = KC_L,
107
 
108
    [0x3b] = KC_SEMICOLON,
109
    [0x27] = KC_QUOTE,
110
    [0x5c] = KC_BACKSLASH,
111
 
112
//  [0x2a] = KC_LSHIFT,
113
 
114
    [0x7a] = KC_Z,
115
    [0x78] = KC_X,
116
    [0x63] = KC_C,
117
    [0x76] = KC_V,
118
    [0x62] = KC_B,
119
    [0x6e] = KC_N,
120
    [0x6d] = KC_M,
121
 
122
    [0x2c] = KC_COMMA,
123
    [0x2e] = KC_PERIOD,
124
    [0x2f] = KC_SLASH,
125
 
126
//  [0x36] = KC_RSHIFT,
127
 
128
//  [0x1d] = KC_LCTRL,
129
//  [0x38] = KC_LALT,
130
    [0x20] = KC_SPACE,
131
 
132
    [0x1b] = KC_ESCAPE,
133
 
134
    [0x0a] = KC_ENTER,
135
    [0x0d] = KC_ENTER
136
 
137
/*
138
    [0x1] = KC_PRNSCR,
139
    [0x1] = KC_SCROLL_LOCK,
140
    [0x1] = KC_PAUSE,
141
*/
142
};
143
 
144
static int map_e1[] =
145
{
146
};
147
 
148
static int map_e1a[] =
149
{
150
    [0x50] = KC_F1,
151
    [0x51] = KC_F2,
152
    [0x52] = KC_F3,
153
    [0x53] = KC_F4,
154
};
155
 
156
static int map_e1b[] =
157
{
158
    [0x33] = KC_F5,
159
    [0x37] = KC_F6,
160
    [0x38] = KC_F7,
161
    [0x39] = KC_F8,
162
};
163
 
164
static int map_e1c[] =
165
{
166
    [0x38] = KC_F9,
167
    [0x39] = KC_F10,
168
    [0x33] = KC_F11,
169
    [0x34] = KC_F12,
170
};
171
 
172
 
173
static enum dec_state ds = ds_start;
174
 
175
void kbd_ctl_parse_scancode(int scancode)
176
{
177
    switch (ds) {
178
    case ds_start:  parse_ds_start(scancode); break;
179
    case ds_e:  parse_ds_e(scancode); break;
180
    case ds_e1: parse_ds_e1(scancode); break;
181
    case ds_e1a:    parse_ds_e1a(scancode); break;
182
    case ds_e1b:    parse_ds_e1b(scancode); break;
183
    case ds_e1c:    parse_ds_e1c(scancode); break;
184
    }
185
}
186
 
187
static void parse_ds_start(int scancode)
188
{
189
    if (scancode == 0x1b) {
190
        ds = ds_e;
191
        return;
192
    }
193
 
194
    parse_leaf(scancode, map_start, sizeof(map_start) / sizeof(int));
195
}
196
 
197
static void parse_ds_e(int scancode)
198
{
199
    switch (scancode) {
200
    case 0x5b: ds = ds_e1; return;
201
    case 0x1b: ds = ds_start; break;
202
    default: ds = ds_start; return;
203
    }
204
 
3933 svoboda 205
    kbd_push_ev(KE_PRESS, KC_ESCAPE);
3923 svoboda 206
}
207
 
208
static void parse_ds_e1(int scancode)
209
{
210
    switch (scancode) {
211
    case 0x4f: ds = ds_e1a; return;
212
    case 0x31: ds = ds_e1b; return;
213
    case 0x32: ds = ds_e1c; return;
214
    default: ds = ds_start; break;
215
    }
216
 
217
    parse_leaf(scancode, map_e1, sizeof(map_e1) / sizeof(int));
218
}
219
 
220
static void parse_ds_e1a(int scancode)
221
{
222
    parse_leaf(scancode, map_e1a, sizeof(map_e1a) / sizeof(int));
223
}
224
 
225
static void parse_ds_e1b(int scancode)
226
{
227
    parse_leaf(scancode, map_e1b, sizeof(map_e1b) / sizeof(int));
228
}
229
 
230
static void parse_ds_e1c(int scancode)
231
{
232
    parse_leaf(scancode, map_e1c, sizeof(map_e1c) / sizeof(int));
233
}
234
 
235
static void parse_leaf(int scancode, int *map, size_t map_length)
236
{
237
    unsigned int key;
238
 
239
    ds = ds_start;
240
 
241
    if (scancode < 0 || scancode >= map_length)
242
        return;
243
 
244
    key = map[scancode];
245
    if (key != 0)
3939 decky 246
        kbd_push_ev(KE_PRESS, key);
3923 svoboda 247
}
248
 
249
 
250
/**
251
 * @}
252
 */