Subversion Repositories HelenOS

Rev

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   Serial TTY-like 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>
4061 svoboda 42
#include <gsp.h>
43
#include <stroke.h>
3923 svoboda 44
 
4061 svoboda 45
/** Scancode parser */
46
static gsp_t sp;
3923 svoboda 47
 
4061 svoboda 48
/** Current parser state */
49
static int ds;
3923 svoboda 50
 
4061 svoboda 51
#include <stdio.h>
3923 svoboda 52
 
4061 svoboda 53
int seq_defs[] = {
54
    /* Not shifted */
3923 svoboda 55
 
4061 svoboda 56
    0,  KC_BACKTICK,    0x60, GSP_END,
3923 svoboda 57
 
4061 svoboda 58
    0,  KC_1,       0x31, GSP_END,
59
    0,  KC_2,       0x32, GSP_END,
60
    0,  KC_3,       0x33, GSP_END,
61
    0,  KC_4,       0x34, GSP_END,
62
    0,  KC_5,       0x35, GSP_END,
63
    0,  KC_6,       0x36, GSP_END,
64
    0,  KC_7,       0x37, GSP_END,
65
    0,  KC_8,       0x38, GSP_END,
66
    0,  KC_9,       0x39, GSP_END,
67
    0,  KC_0,       0x30, GSP_END,
3923 svoboda 68
 
4061 svoboda 69
    0,  KC_MINUS,   0x2d, GSP_END,
70
    0,  KC_EQUALS,  0x3d, GSP_END,
71
    0,  KC_BACKSPACE,   0x08, GSP_END,
3923 svoboda 72
 
4061 svoboda 73
    0,  KC_TAB,     0x09, GSP_END,
3923 svoboda 74
 
4061 svoboda 75
    0,  KC_Q,       0x71, GSP_END,
76
    0,  KC_W,       0x77, GSP_END,
77
    0,  KC_E,       0x65, GSP_END,
78
    0,  KC_R,       0x72, GSP_END,
79
    0,  KC_T,       0x74, GSP_END,
80
    0,  KC_Y,       0x79, GSP_END,
81
    0,  KC_U,       0x75, GSP_END,
82
    0,  KC_I,       0x69, GSP_END,
83
    0,  KC_O,       0x6f, GSP_END,
84
    0,  KC_P,       0x70, GSP_END,
3923 svoboda 85
 
4061 svoboda 86
    0,  KC_LBRACKET,    0x5b, GSP_END,
87
    0,  KC_RBRACKET,    0x5d, GSP_END,
3923 svoboda 88
 
4061 svoboda 89
    0,  KC_A,       0x61, GSP_END,
90
    0,  KC_S,       0x73, GSP_END,
91
    0,  KC_D,       0x64, GSP_END,
92
    0,  KC_F,       0x66, GSP_END,
93
    0,  KC_G,       0x67, GSP_END,
94
    0,  KC_H,       0x68, GSP_END,
95
    0,  KC_J,       0x6a, GSP_END,
96
    0,  KC_K,       0x6b, GSP_END,
97
    0,  KC_L,       0x6c, GSP_END,
3923 svoboda 98
 
4061 svoboda 99
    0,  KC_SEMICOLON,   0x3b, GSP_END,
100
    0,  KC_QUOTE,   0x27, GSP_END,
101
    0,  KC_BACKSLASH,   0x5c, GSP_END,
3923 svoboda 102
 
4061 svoboda 103
    0,  KC_Z,       0x7a, GSP_END,
104
    0,  KC_X,       0x78, GSP_END,
105
    0,  KC_C,       0x63, GSP_END,
106
    0,  KC_V,       0x76, GSP_END,
107
    0,  KC_B,       0x62, GSP_END,
108
    0,  KC_N,       0x6e, GSP_END,
109
    0,  KC_M,       0x6d, GSP_END,
3923 svoboda 110
 
4061 svoboda 111
    0,  KC_COMMA,   0x2c, GSP_END,
112
    0,  KC_PERIOD,  0x2e, GSP_END,
113
    0,  KC_SLASH,   0x2f, GSP_END,
3923 svoboda 114
 
4061 svoboda 115
    /* Shifted */
3923 svoboda 116
 
4061 svoboda 117
    KM_SHIFT,   KC_BACKTICK,    0x7e, GSP_END,
3923 svoboda 118
 
4061 svoboda 119
    KM_SHIFT,   KC_1,       0x21, GSP_END,
120
    KM_SHIFT,   KC_2,       0x40, GSP_END,
121
    KM_SHIFT,   KC_3,       0x23, GSP_END,
122
    KM_SHIFT,   KC_4,       0x24, GSP_END,
123
    KM_SHIFT,   KC_5,       0x25, GSP_END,
124
    KM_SHIFT,   KC_6,       0x5e, GSP_END,
125
    KM_SHIFT,   KC_7,       0x26, GSP_END,
126
    KM_SHIFT,   KC_8,       0x2a, GSP_END,
127
    KM_SHIFT,   KC_9,       0x28, GSP_END,
128
    KM_SHIFT,   KC_0,       0x29, GSP_END,
3923 svoboda 129
 
4061 svoboda 130
    KM_SHIFT,   KC_MINUS,   0x5f, GSP_END,
131
    KM_SHIFT,   KC_EQUALS,  0x2b, GSP_END,
3923 svoboda 132
 
4061 svoboda 133
    KM_SHIFT,   KC_Q,       0x51, GSP_END,
134
    KM_SHIFT,   KC_W,       0x57, GSP_END,
135
    KM_SHIFT,   KC_E,       0x45, GSP_END,
136
    KM_SHIFT,   KC_R,       0x52, GSP_END,
137
    KM_SHIFT,   KC_T,       0x54, GSP_END,
138
    KM_SHIFT,   KC_Y,       0x59, GSP_END,
139
    KM_SHIFT,   KC_U,       0x55, GSP_END,
140
    KM_SHIFT,   KC_I,       0x49, GSP_END,
141
    KM_SHIFT,   KC_O,       0x4f, GSP_END,
142
    KM_SHIFT,   KC_P,       0x50, GSP_END,
3923 svoboda 143
 
4061 svoboda 144
    KM_SHIFT,   KC_LBRACKET,    0x7b, GSP_END,
145
    KM_SHIFT,   KC_RBRACKET,    0x7d, GSP_END,
3923 svoboda 146
 
4061 svoboda 147
    KM_SHIFT,   KC_A,       0x41, GSP_END,
148
    KM_SHIFT,   KC_S,       0x53, GSP_END,
149
    KM_SHIFT,   KC_D,       0x44, GSP_END,
150
    KM_SHIFT,   KC_F,       0x46, GSP_END,
151
    KM_SHIFT,   KC_G,       0x47, GSP_END,
152
    KM_SHIFT,   KC_H,       0x48, GSP_END,
153
    KM_SHIFT,   KC_J,       0x4a, GSP_END,
154
    KM_SHIFT,   KC_K,       0x4b, GSP_END,
155
    KM_SHIFT,   KC_L,       0x4c, GSP_END,
3944 svoboda 156
 
4061 svoboda 157
    KM_SHIFT,   KC_SEMICOLON,   0x3a, GSP_END,
158
    KM_SHIFT,   KC_QUOTE,   0x22, GSP_END,
159
    KM_SHIFT,   KC_BACKSLASH,   0x7c, GSP_END,
3944 svoboda 160
 
4061 svoboda 161
    KM_SHIFT,   KC_Z,       0x5a, GSP_END,
162
    KM_SHIFT,   KC_X,       0x58, GSP_END,
163
    KM_SHIFT,   KC_C,       0x43, GSP_END,
164
    KM_SHIFT,   KC_V,       0x56, GSP_END,
165
    KM_SHIFT,   KC_B,       0x42, GSP_END,
166
    KM_SHIFT,   KC_N,       0x4e, GSP_END,
167
    KM_SHIFT,   KC_M,       0x4d, GSP_END,
3944 svoboda 168
 
4061 svoboda 169
    KM_SHIFT,   KC_COMMA,   0x3c, GSP_END,
170
    KM_SHIFT,   KC_PERIOD,  0x3e, GSP_END,
171
    KM_SHIFT,   KC_SLASH,   0x3f, GSP_END,
3944 svoboda 172
 
4061 svoboda 173
    /* ... */
3944 svoboda 174
 
4061 svoboda 175
    0,  KC_SPACE,   0x20, GSP_END,
176
    0,  KC_ENTER,   0x0a, GSP_END,
177
    0,  KC_ENTER,   0x0d, GSP_END,
3944 svoboda 178
 
4061 svoboda 179
    0,  KC_ESCAPE,  0x1b, 0x1b, GSP_END,
3923 svoboda 180
 
4061 svoboda 181
    0,  KC_F1,      0x1b, 0x4f, 0x50, GSP_END,
182
    0,  KC_F2,      0x1b, 0x4f, 0x51, GSP_END,
183
    0,  KC_F3,      0x1b, 0x4f, 0x52, GSP_END,
184
    0,  KC_F4,      0x1b, 0x4f, 0x53, GSP_END,
185
    0,  KC_F5,      0x1b, 0x5b, 0x31, 0x35, 0x7e, GSP_END,
186
    0,  KC_F6,      0x1b, 0x5b, 0x31, 0x37, 0x7e, GSP_END,
187
    0,  KC_F7,      0x1b, 0x5b, 0x31, 0x38, 0x7e, GSP_END,
188
    0,  KC_F8,      0x1b, 0x5b, 0x31, 0x39, 0x7e, GSP_END,
189
    0,  KC_F9,      0x1b, 0x5b, 0x32, 0x30, 0x7e, GSP_END,
190
    0,  KC_F10,     0x1b, 0x5b, 0x32, 0x31, 0x7e, GSP_END,
191
    0,  KC_F11,     0x1b, 0x5b, 0x32, 0x33, 0x7e, GSP_END,
192
    0,  KC_F12,     0x1b, 0x5b, 0x32, 0x34, 0x7e, GSP_END,
3923 svoboda 193
 
4061 svoboda 194
    0,  KC_INSERT,  0x1b, 0x5b, 0x32, 0x7e, GSP_END,
195
    0,  KC_HOME,    0x1b, 0x5b, 0x48, GSP_END,
196
    0,  KC_PAGE_UP, 0x1b, 0x5b, 0x35, 0x7e, GSP_END,
197
    0,  KC_DELETE,  0x1b, 0x5b, 0x33, 0x7e, GSP_END,
198
    0,  KC_END,     0x1b, 0x5b, 0x46, GSP_END,
199
    0,  KC_PAGE_DOWN,   0x1b, 0x5b, 0x36, 0x7e, GSP_END,
3923 svoboda 200
 
4061 svoboda 201
    0,  KC_UP,      0x1b, 0x5b, 0x41, GSP_END,
202
    0,  KC_LEFT,    0x1b, 0x5b, 0x44, GSP_END,
203
    0,  KC_DOWN,    0x1b, 0x5b, 0x42, GSP_END,
204
    0,  KC_RIGHT,   0x1b, 0x5b, 0x43, GSP_END,
3923 svoboda 205
 
4061 svoboda 206
    0,  0
3923 svoboda 207
};
208
 
4061 svoboda 209
int kbd_ctl_init(void)
3923 svoboda 210
{
4061 svoboda 211
    ds = 0;
3923 svoboda 212
 
4061 svoboda 213
    gsp_init(&sp);
214
    return gsp_insert_defs(&sp, seq_defs);
3923 svoboda 215
}
216
 
4061 svoboda 217
void kbd_ctl_parse_scancode(int scancode)
3923 svoboda 218
{
4061 svoboda 219
    unsigned mods, key;
3923 svoboda 220
 
4061 svoboda 221
    ds = gsp_step(&sp, ds, scancode, &mods, &key);
3944 svoboda 222
    if (key != 0) {
4061 svoboda 223
        stroke_sim(mods, key);
3944 svoboda 224
    }
3923 svoboda 225
}
226
 
227
/**
228
 * @}
229
 */