Subversion Repositories HelenOS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2337 kebrt 1
/*
2
 * Copyright (c) 2007 Michal Kebrt
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
 
29
/** @addtogroup kbdarm32 arm32
30
 * @brief   HelenOS arm32 arch dependent parts of uspace keyboard handler.
31
 * @ingroup  kbd
32
 * @{
33
 */
34
/** @file
35
 */
36
 
37
#include <arch/kbd.h>
38
#include <ipc/ipc.h>
39
#include <sysinfo.h>
40
#include <kbd.h>
41
#include <keys.h>
42
 
43
#define GXEMUL_KEY_F1  0x504f1bL
44
#define GXEMUL_KEY_F2  0x514f1bL
45
#define GXEMUL_KEY_F3  0x524f1bL
46
#define GXEMUL_KEY_F4  0x534f1bL
47
#define GXEMUL_KEY_F5  0x35315b1bL
48
#define GXEMUL_KEY_F6  0x37315b1bL
49
#define GXEMUL_KEY_F7  0x38315b1bL
50
#define GXEMUL_KEY_F8  0x39315b1bL
51
#define GXEMUL_KEY_F9  0x30325b1bL
52
#define GXEMUL_KEY_F10 0x31325b1bL
53
#define GXEMUL_KEY_F11 0x33325d1bL
54
#define GXEMUL_KEY_F12 0x34325b1bL 
55
 
56
#define FUNCTION_KEYS 0x100
57
 
58
irq_cmd_t gxemul_cmds[] = {
59
    {
60
        CMD_MEM_READ_1,
61
        (void *) 0,
62
        0,
63
        2
64
    }
65
};
66
 
67
irq_code_t gxemul_kbd = {
68
    1,
69
    gxemul_cmds
70
};
71
 
72
 
73
/*
74
// Please preserve this code (it can be used to determine scancodes)
75
int to_hex(int v)
76
{
77
        return "0123456789ABCDEF"[v];
78
}
79
*/
80
 
81
static int gxemul_process_no_fb(keybuffer_t *keybuffer, int scan_code)
82
{
83
 
84
    static unsigned long buf = 0;
85
    static int count = 0;  
86
 
87
    /* Preserve for detecting scan codes.
88
    keybuffer_push(keybuffer, to_hex((scan_code>>4)&0xf));
89
    keybuffer_push(keybuffer, to_hex(scan_code&0xf));
90
    keybuffer_push(keybuffer, 'X');
91
    keybuffer_push(keybuffer, 'Y');
92
    return 1;
93
    */
94
 
95
    if (scan_code == '\r')
96
        scan_code = '\n';
97
 
98
    if(scan_code == 0x7e) {
99
        switch (buf) {
100
        case GXEMUL_KEY_F5:
101
            keybuffer_push(keybuffer,FUNCTION_KEYS | 5);
102
            buf = count = 0;
103
            return 1;
104
        case GXEMUL_KEY_F6:
105
            keybuffer_push(keybuffer,FUNCTION_KEYS | 6);
106
            buf = count = 0;
107
            return 1;
108
        case GXEMUL_KEY_F7:
109
            keybuffer_push(keybuffer,FUNCTION_KEYS | 7);
110
            buf = count = 0;
111
            return 1;
112
        case GXEMUL_KEY_F8:
113
            keybuffer_push(keybuffer,FUNCTION_KEYS | 8);
114
            buf = count = 0;
115
            return 1;
116
        case GXEMUL_KEY_F9:
117
            keybuffer_push(keybuffer,FUNCTION_KEYS | 9);
118
            buf = count = 0;
119
            return 1;
120
        case GXEMUL_KEY_F10:
121
            keybuffer_push(keybuffer,FUNCTION_KEYS | 10);
122
            buf = count = 0;
123
            return 1;
124
        case GXEMUL_KEY_F11:
125
            keybuffer_push(keybuffer,FUNCTION_KEYS | 11);
126
            buf = count = 0;
127
            return 1;
128
        case GXEMUL_KEY_F12:
129
            keybuffer_push(keybuffer,FUNCTION_KEYS | 12);
130
            buf = count = 0;
131
            return 1;
132
        default:
133
            keybuffer_push(keybuffer, buf & 0xff);
134
            keybuffer_push(keybuffer, (buf >> 8) &0xff);
135
            keybuffer_push(keybuffer, (buf >> 16) &0xff);
136
            keybuffer_push(keybuffer, (buf >> 24) &0xff);
137
            keybuffer_push(keybuffer, scan_code);
138
            buf = count = 0;
139
            return 1;
140
        }
141
    }
142
 
143
    buf |= ((unsigned long) scan_code)<<(8*(count++));
144
 
145
    if((buf & 0xff) != (GXEMUL_KEY_F1 & 0xff)) {
146
        keybuffer_push(keybuffer, buf);
147
        buf = count = 0;
148
        return 1;
149
    }
150
 
151
    if (count <= 1)
152
        return 1;
153
 
154
    if ((buf & 0xffff) != (GXEMUL_KEY_F1 & 0xffff)
155
        && (buf & 0xffff) != (GXEMUL_KEY_F5 & 0xffff) ) {
156
 
157
        keybuffer_push(keybuffer, buf & 0xff);
158
        keybuffer_push(keybuffer, (buf >> 8) &0xff);
159
        buf = count = 0;
160
        return 1;
161
    }
162
 
163
    if (count <= 2)
164
        return 1;
165
 
166
    switch (buf) {
167
    case GXEMUL_KEY_F1:
168
        keybuffer_push(keybuffer,FUNCTION_KEYS | 1);
169
        buf = count = 0;
170
        return 1;
171
    case GXEMUL_KEY_F2:
172
        keybuffer_push(keybuffer,FUNCTION_KEYS | 2);
173
        buf = count = 0;
174
        return 1;
175
    case GXEMUL_KEY_F3:
176
        keybuffer_push(keybuffer,FUNCTION_KEYS | 3);
177
        buf = count = 0;
178
        return 1;
179
    case GXEMUL_KEY_F4:
180
        keybuffer_push(keybuffer,FUNCTION_KEYS | 4);
181
        buf = count = 0;
182
        return 1;
183
    }
184
 
185
 
186
    if((buf & 0xffffff) != (GXEMUL_KEY_F5 & 0xffffff)
187
        && (buf & 0xffffff) != (GXEMUL_KEY_F9 & 0xffffff)) {
188
 
189
        keybuffer_push(keybuffer, buf & 0xff);
190
        keybuffer_push(keybuffer, (buf >> 8) & 0xff);
191
        keybuffer_push(keybuffer, (buf >> 16) & 0xff);
192
        buf=count=0;
193
        return 1;
194
    }
195
 
196
    if (count <= 3)
197
        return 1;
198
 
199
    switch (buf) {
200
    case GXEMUL_KEY_F5:
201
    case GXEMUL_KEY_F6:
202
    case GXEMUL_KEY_F7:
203
    case GXEMUL_KEY_F8:
204
    case GXEMUL_KEY_F9:
205
    case GXEMUL_KEY_F10:
206
    case GXEMUL_KEY_F11:
207
    case GXEMUL_KEY_F12:
208
        return 1;
209
    default:
210
        keybuffer_push(keybuffer, buf & 0xff);
211
        keybuffer_push(keybuffer, (buf >> 8) &0xff);
212
        keybuffer_push(keybuffer, (buf >> 16) &0xff);
213
        keybuffer_push(keybuffer, (buf >> 24) &0xff);
214
        buf = count = 0;
215
        return 1;
216
    }
217
    return 1;
218
}
219
 
220
 
221
int kbd_arch_init(void)
222
{
223
    gxemul_cmds[0].addr = (void *) sysinfo_value("kbd.address.virtual");
224
    ipc_register_irq(sysinfo_value("kbd.inr"), sysinfo_value("kbd.devno"), 0, &gxemul_kbd);
225
    return 0;
226
}
227
 
228
 
229
int kbd_arch_process(keybuffer_t *keybuffer, ipc_call_t *call)
230
{
231
    int scan_code = IPC_GET_ARG2(*call);
232
    static int esc_count=0;
233
 
234
    if (scan_code == 0x1b) {
235
        esc_count++;
236
        if (esc_count == 3) {
237
            __SYSCALL0(SYS_DEBUG_ENABLE_CONSOLE);
238
        }
239
    } else {
240
        esc_count = 0;
241
    }
242
 
243
    return gxemul_process_no_fb(keybuffer, scan_code);
244
}
245
 
246
/** @}
247
 */