Subversion Repositories HelenOS

Rev

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

Rev 1843 Rev 1844
1
/*
1
/*
2
 * Copyright (C) 2006 Jakub Jermar
2
 * Copyright (C) 2006 Jakub Jermar
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 genarch
29
/** @addtogroup genarch
30
 * @{
30
 * @{
31
 */
31
 */
32
/**
32
/**
33
 * @file
33
 * @file
34
 * @brief   Key processing.
34
 * @brief   Key processing.
35
 */
35
 */
36
 
36
 
37
#include <genarch/kbd/key.h>
37
#include <genarch/kbd/key.h>
38
#include <genarch/kbd/scanc.h>
38
#include <genarch/kbd/scanc.h>
-
 
39
#ifdef CONFIG_I8042
39
#include <genarch/kbd/scanc_pc.h>
40
#include <genarch/kbd/scanc_pc.h>
-
 
41
#endif
-
 
42
#if (defined(CONFIG_Z8530) || defined(CONFIG_NS16550))
-
 
43
#include <genarch/kbd/scanc_sun.h>
-
 
44
#endif
40
#include <synch/spinlock.h>
45
#include <synch/spinlock.h>
41
#include <console/chardev.h>
46
#include <console/chardev.h>
42
#include <typedefs.h>
47
#include <typedefs.h>
43
#include <macros.h>
48
#include <macros.h>
44
 
49
 
45
#define PRESSED_SHIFT       (1<<0)
50
#define PRESSED_SHIFT       (1<<0)
46
#define PRESSED_CAPSLOCK    (1<<1)
51
#define PRESSED_CAPSLOCK    (1<<1)
47
#define LOCKED_CAPSLOCK     (1<<0)
52
#define LOCKED_CAPSLOCK     (1<<0)
48
 
53
 
49
#define ACTIVE_READ_BUFF_SIZE 16    /* Must be power of 2 */
54
#define ACTIVE_READ_BUFF_SIZE 16    /* Must be power of 2 */
50
 
55
 
51
static uint8_t active_read_buff[ACTIVE_READ_BUFF_SIZE];
56
static uint8_t active_read_buff[ACTIVE_READ_BUFF_SIZE];
52
 
57
 
53
SPINLOCK_INITIALIZE(keylock);       /**< keylock protects keyflags and lockflags. */
58
SPINLOCK_INITIALIZE(keylock);       /**< keylock protects keyflags and lockflags. */
54
static volatile int keyflags;       /**< Tracking of multiple keypresses. */
59
static volatile int keyflags;       /**< Tracking of multiple keypresses. */
55
static volatile int lockflags;      /**< Tracking of multiple keys lockings. */
60
static volatile int lockflags;      /**< Tracking of multiple keys lockings. */
56
 
61
 
57
/** Process release of key.
62
/** Process release of key.
58
 *
63
 *
59
 * @param sc Scancode of the key being released.
64
 * @param sc Scancode of the key being released.
60
 */
65
 */
61
void key_released(uint8_t sc)
66
void key_released(uint8_t sc)
62
{
67
{
63
    spinlock_lock(&keylock);
68
    spinlock_lock(&keylock);
64
    switch (sc) {
69
    switch (sc) {
65
        case SC_LSHIFT:
70
        case SC_LSHIFT:
66
        case SC_RSHIFT:
71
        case SC_RSHIFT:
67
        keyflags &= ~PRESSED_SHIFT;
72
        keyflags &= ~PRESSED_SHIFT;
68
        break;
73
        break;
69
        case SC_CAPSLOCK:
74
        case SC_CAPSLOCK:
70
        keyflags &= ~PRESSED_CAPSLOCK;
75
        keyflags &= ~PRESSED_CAPSLOCK;
71
        if (lockflags & LOCKED_CAPSLOCK)
76
        if (lockflags & LOCKED_CAPSLOCK)
72
            lockflags &= ~LOCKED_CAPSLOCK;
77
            lockflags &= ~LOCKED_CAPSLOCK;
73
        else
78
        else
74
            lockflags |= LOCKED_CAPSLOCK;
79
            lockflags |= LOCKED_CAPSLOCK;
75
        break;
80
        break;
76
        default:
81
        default:
77
        break;
82
        break;
78
    }
83
    }
79
    spinlock_unlock(&keylock);
84
    spinlock_unlock(&keylock);
80
}
85
}
81
 
86
 
82
/** Process keypress.
87
/** Process keypress.
83
 *
88
 *
84
 * @param sc Scancode of the key being pressed.
89
 * @param sc Scancode of the key being pressed.
85
 */
90
 */
86
void key_pressed(uint8_t sc)
91
void key_pressed(uint8_t sc)
87
{
92
{
88
    char *map = sc_primary_map;
93
    char *map = sc_primary_map;
89
    char ascii = sc_primary_map[sc];
94
    char ascii = sc_primary_map[sc];
90
    bool shift, capslock;
95
    bool shift, capslock;
91
    bool letter = false;
96
    bool letter = false;
92
 
97
 
93
    spinlock_lock(&keylock);
98
    spinlock_lock(&keylock);
94
    switch (sc) {
99
    switch (sc) {
95
    case SC_LSHIFT:
100
    case SC_LSHIFT:
96
    case SC_RSHIFT:
101
    case SC_RSHIFT:
97
            keyflags |= PRESSED_SHIFT;
102
            keyflags |= PRESSED_SHIFT;
98
        break;
103
        break;
99
    case SC_CAPSLOCK:
104
    case SC_CAPSLOCK:
100
        keyflags |= PRESSED_CAPSLOCK;
105
        keyflags |= PRESSED_CAPSLOCK;
101
        break;
106
        break;
102
    case SC_SPEC_ESCAPE:
107
    case SC_SPEC_ESCAPE:
103
        break;
108
        break;
104
    case SC_LEFTARR:
109
    case SC_LEFTARR:
105
        chardev_push_character(&kbrd, 0x1b);
110
        chardev_push_character(&kbrd, 0x1b);
106
        chardev_push_character(&kbrd, 0x5b);
111
        chardev_push_character(&kbrd, 0x5b);
107
        chardev_push_character(&kbrd, 0x44);
112
        chardev_push_character(&kbrd, 0x44);
108
        break;
113
        break;
109
    case SC_RIGHTARR:
114
    case SC_RIGHTARR:
110
        chardev_push_character(&kbrd, 0x1b);
115
        chardev_push_character(&kbrd, 0x1b);
111
        chardev_push_character(&kbrd, 0x5b);
116
        chardev_push_character(&kbrd, 0x5b);
112
        chardev_push_character(&kbrd, 0x43);
117
        chardev_push_character(&kbrd, 0x43);
113
        break;
118
        break;
114
    case SC_UPARR:
119
    case SC_UPARR:
115
        chardev_push_character(&kbrd, 0x1b);
120
        chardev_push_character(&kbrd, 0x1b);
116
        chardev_push_character(&kbrd, 0x5b);
121
        chardev_push_character(&kbrd, 0x5b);
117
        chardev_push_character(&kbrd, 0x41);
122
        chardev_push_character(&kbrd, 0x41);
118
        break;
123
        break;
119
    case SC_DOWNARR:
124
    case SC_DOWNARR:
120
        chardev_push_character(&kbrd, 0x1b);
125
        chardev_push_character(&kbrd, 0x1b);
121
        chardev_push_character(&kbrd, 0x5b);
126
        chardev_push_character(&kbrd, 0x5b);
122
        chardev_push_character(&kbrd, 0x42);
127
        chardev_push_character(&kbrd, 0x42);
123
        break;
128
        break;
124
    case SC_HOME:
129
    case SC_HOME:
125
        chardev_push_character(&kbrd, 0x1b);
130
        chardev_push_character(&kbrd, 0x1b);
126
        chardev_push_character(&kbrd, 0x4f);
131
        chardev_push_character(&kbrd, 0x4f);
127
        chardev_push_character(&kbrd, 0x48);
132
        chardev_push_character(&kbrd, 0x48);
128
        break;
133
        break;
129
    case SC_END:
134
    case SC_END:
130
        chardev_push_character(&kbrd, 0x1b);
135
        chardev_push_character(&kbrd, 0x1b);
131
        chardev_push_character(&kbrd, 0x4f);
136
        chardev_push_character(&kbrd, 0x4f);
132
        chardev_push_character(&kbrd, 0x46);
137
        chardev_push_character(&kbrd, 0x46);
133
        break;
138
        break;
134
    case SC_DELETE:
139
    case SC_DELETE:
135
        chardev_push_character(&kbrd, 0x1b);
140
        chardev_push_character(&kbrd, 0x1b);
136
        chardev_push_character(&kbrd, 0x5b);
141
        chardev_push_character(&kbrd, 0x5b);
137
        chardev_push_character(&kbrd, 0x33);
142
        chardev_push_character(&kbrd, 0x33);
138
        chardev_push_character(&kbrd, 0x7e);
143
        chardev_push_character(&kbrd, 0x7e);
139
        break;
144
        break;
140
    default:
145
    default:
141
            letter = is_lower(ascii);
146
            letter = is_lower(ascii);
142
        capslock = (keyflags & PRESSED_CAPSLOCK) || (lockflags & LOCKED_CAPSLOCK);
147
        capslock = (keyflags & PRESSED_CAPSLOCK) || (lockflags & LOCKED_CAPSLOCK);
143
        shift = keyflags & PRESSED_SHIFT;
148
        shift = keyflags & PRESSED_SHIFT;
144
        if (letter && capslock)
149
        if (letter && capslock)
145
            shift = !shift;
150
            shift = !shift;
146
        if (shift)
151
        if (shift)
147
            map = sc_secondary_map;
152
            map = sc_secondary_map;
148
        chardev_push_character(&kbrd, map[sc]);
153
        chardev_push_character(&kbrd, map[sc]);
149
        break;
154
        break;
150
    }
155
    }
151
    spinlock_unlock(&keylock);
156
    spinlock_unlock(&keylock);
152
}
157
}
153
 
158
 
154
uint8_t active_read_buff_read(void)
159
uint8_t active_read_buff_read(void)
155
{
160
{
156
    static int i=0;
161
    static int i=0;
157
    i &= (ACTIVE_READ_BUFF_SIZE-1);
162
    i &= (ACTIVE_READ_BUFF_SIZE-1);
158
    if(!active_read_buff[i]) {
163
    if(!active_read_buff[i]) {
159
        return 0;
164
        return 0;
160
    }
165
    }
161
    return active_read_buff[i++];
166
    return active_read_buff[i++];
162
}
167
}
163
 
168
 
164
void active_read_buff_write(uint8_t ch)
169
void active_read_buff_write(uint8_t ch)
165
{
170
{
166
    static int i=0;
171
    static int i=0;
167
    active_read_buff[i] = ch;
172
    active_read_buff[i] = ch;
168
    i++;
173
    i++;
169
    i &= (ACTIVE_READ_BUFF_SIZE-1);
174
    i &= (ACTIVE_READ_BUFF_SIZE-1);
170
    active_read_buff[i]=0;
175
    active_read_buff[i]=0;
171
}
176
}
172
 
177
 
173
 
178
 
174
void active_read_key_pressed(uint8_t sc)
179
void active_read_key_pressed(uint8_t sc)
175
{
180
{
176
    char *map = sc_primary_map;
181
    char *map = sc_primary_map;
177
    char ascii = sc_primary_map[sc];
182
    char ascii = sc_primary_map[sc];
178
    bool shift, capslock;
183
    bool shift, capslock;
179
    bool letter = false;
184
    bool letter = false;
180
 
185
 
181
    /*spinlock_lock(&keylock);*/
186
    /*spinlock_lock(&keylock);*/
182
    switch (sc) {
187
    switch (sc) {
183
    case SC_LSHIFT:
188
    case SC_LSHIFT:
184
    case SC_RSHIFT:
189
    case SC_RSHIFT:
185
            keyflags |= PRESSED_SHIFT;
190
            keyflags |= PRESSED_SHIFT;
186
        break;
191
        break;
187
    case SC_CAPSLOCK:
192
    case SC_CAPSLOCK:
188
        keyflags |= PRESSED_CAPSLOCK;
193
        keyflags |= PRESSED_CAPSLOCK;
189
        break;
194
        break;
190
    case SC_SPEC_ESCAPE:
195
    case SC_SPEC_ESCAPE:
191
        break;
196
        break;
192
    case SC_LEFTARR:
197
    case SC_LEFTARR:
193
        active_read_buff_write(0x1b);
198
        active_read_buff_write(0x1b);
194
        active_read_buff_write(0x5b);
199
        active_read_buff_write(0x5b);
195
        active_read_buff_write(0x44);
200
        active_read_buff_write(0x44);
196
        break;
201
        break;
197
    case SC_RIGHTARR:
202
    case SC_RIGHTARR:
198
        active_read_buff_write(0x1b);
203
        active_read_buff_write(0x1b);
199
        active_read_buff_write(0x5b);
204
        active_read_buff_write(0x5b);
200
        active_read_buff_write(0x43);
205
        active_read_buff_write(0x43);
201
        break;
206
        break;
202
    case SC_UPARR:
207
    case SC_UPARR:
203
        active_read_buff_write(0x1b);
208
        active_read_buff_write(0x1b);
204
        active_read_buff_write(0x5b);
209
        active_read_buff_write(0x5b);
205
        active_read_buff_write(0x41);
210
        active_read_buff_write(0x41);
206
        break;
211
        break;
207
    case SC_DOWNARR:
212
    case SC_DOWNARR:
208
        active_read_buff_write(0x1b);
213
        active_read_buff_write(0x1b);
209
        active_read_buff_write(0x5b);
214
        active_read_buff_write(0x5b);
210
        active_read_buff_write(0x42);
215
        active_read_buff_write(0x42);
211
        break;
216
        break;
212
    case SC_HOME:
217
    case SC_HOME:
213
        active_read_buff_write(0x1b);
218
        active_read_buff_write(0x1b);
214
        active_read_buff_write(0x4f);
219
        active_read_buff_write(0x4f);
215
        active_read_buff_write(0x48);
220
        active_read_buff_write(0x48);
216
        break;
221
        break;
217
    case SC_END:
222
    case SC_END:
218
        active_read_buff_write(0x1b);
223
        active_read_buff_write(0x1b);
219
        active_read_buff_write(0x4f);
224
        active_read_buff_write(0x4f);
220
        active_read_buff_write(0x46);
225
        active_read_buff_write(0x46);
221
        break;
226
        break;
222
    case SC_DELETE:
227
    case SC_DELETE:
223
        active_read_buff_write(0x1b);
228
        active_read_buff_write(0x1b);
224
        active_read_buff_write(0x5b);
229
        active_read_buff_write(0x5b);
225
        active_read_buff_write(0x33);
230
        active_read_buff_write(0x33);
226
        active_read_buff_write(0x7e);
231
        active_read_buff_write(0x7e);
227
        break;
232
        break;
228
    default:
233
    default:
229
            letter = is_lower(ascii);
234
            letter = is_lower(ascii);
230
        capslock = (keyflags & PRESSED_CAPSLOCK) || (lockflags & LOCKED_CAPSLOCK);
235
        capslock = (keyflags & PRESSED_CAPSLOCK) || (lockflags & LOCKED_CAPSLOCK);
231
        shift = keyflags & PRESSED_SHIFT;
236
        shift = keyflags & PRESSED_SHIFT;
232
        if (letter && capslock)
237
        if (letter && capslock)
233
            shift = !shift;
238
            shift = !shift;
234
        if (shift)
239
        if (shift)
235
            map = sc_secondary_map;
240
            map = sc_secondary_map;
236
        active_read_buff_write(map[sc]);
241
        active_read_buff_write(map[sc]);
237
        break;
242
        break;
238
    }
243
    }
239
    /*spinlock_unlock(&keylock);*/
244
    /*spinlock_unlock(&keylock);*/
240
 
245
 
241
}
246
}
242
 
247
 
243
/** @}
248
/** @}
244
 */
249
 */
245
 
250