Subversion Repositories HelenOS

Rev

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

Rev 1841 Rev 1842
1
/*
1
/*
2
 * Copyright (C) 2001-2004 Jakub Jermar
2
 * Copyright (C) 2001-2004 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   i8042 processor driver.
34
 * @brief   Zilog 8530 serial port / keyboard driver.
35
 *
35
 *
-
 
36
 * Note that this file is derived from the i8042.c.
36
 * It takes care of low-level keyboard functions.
37
 * The i8042 driver could be persuaded to control
-
 
38
 * the z8530 at least in the polling mode.
-
 
39
 * As a result, this file may contain inaccurate
-
 
40
 * and z8530-irrelevant constants, code and comments.
-
 
41
 * Still it miraculously works.
37
 */
42
 */
38
 
43
 
39
#include <genarch/i8042/i8042.h>
44
#include <genarch/kbd/z8530.h>
-
 
45
#include <genarch/kbd/scanc.h>
-
 
46
#include <genarch/kbd/scanc_sun.h>
40
#include <arch/drivers/i8042.h>
47
#include <arch/drivers/z8530.h>
41
#include <arch/interrupt.h>
48
#include <arch/interrupt.h>
42
#include <cpu.h>
49
#include <cpu.h>
43
#include <arch/asm.h>
50
#include <arch/asm.h>
44
#include <arch.h>
51
#include <arch.h>
45
#include <synch/spinlock.h>
52
#include <synch/spinlock.h>
46
#include <typedefs.h>
53
#include <typedefs.h>
47
#include <console/chardev.h>
54
#include <console/chardev.h>
48
#include <console/console.h>
55
#include <console/console.h>
49
#include <macros.h>
56
#include <macros.h>
50
#include <interrupt.h>
57
#include <interrupt.h>
51
 
58
 
52
/* Keyboard commands. */
59
/* Keyboard commands. */
53
#define KBD_ENABLE  0xf4
60
#define KBD_ENABLE  0xf4
54
#define KBD_DISABLE 0xf5
61
#define KBD_DISABLE 0xf5
55
#define KBD_ACK     0xfa
62
#define KBD_ACK     0xfa
56
 
63
 
57
/*
64
/*
58
 * 60  Write 8042 Command Byte: next data byte written to port 60h is
65
 * 60  Write 8042 Command Byte: next data byte written to port 60h is
59
 *     placed in 8042 command register. Format:
66
 *     placed in 8042 command register. Format:
60
 *
67
 *
61
 *    |7|6|5|4|3|2|1|0|8042 Command Byte
68
 *    |7|6|5|4|3|2|1|0|8042 Command Byte
62
 *     | | | | | | | `---- 1=enable output register full interrupt
69
 *     | | | | | | | `---- 1=enable output register full interrupt
63
 *     | | | | | | `----- should be 0
70
 *     | | | | | | `----- should be 0
64
 *     | | | | | `------ 1=set status register system, 0=clear
71
 *     | | | | | `------ 1=set status register system, 0=clear
65
 *     | | | | `------- 1=override keyboard inhibit, 0=allow inhibit
72
 *     | | | | `------- 1=override keyboard inhibit, 0=allow inhibit
66
 *     | | | `-------- disable keyboard I/O by driving clock line low
73
 *     | | | `-------- disable keyboard I/O by driving clock line low
67
 *     | | `--------- disable auxiliary device, drives clock line low
74
 *     | | `--------- disable auxiliary device, drives clock line low
68
 *     | `---------- IBM scancode translation 0=AT, 1=PC/XT
75
 *     | `---------- IBM scancode translation 0=AT, 1=PC/XT
69
 *     `----------- reserved, should be 0
76
 *     `----------- reserved, should be 0
70
 */
77
 */
71
 
78
 
72
#define i8042_SET_COMMAND   0x60
79
#define z8530_SET_COMMAND   0x60
73
#define i8042_COMMAND       0x69
80
#define z8530_COMMAND       0x69
74
 
81
 
75
#define i8042_BUFFER_FULL_MASK  0x01
82
#define z8530_BUFFER_FULL_MASK  0x01
76
#define i8042_WAIT_MASK     0x02
83
#define z8530_WAIT_MASK     0x02
77
#define i8042_MOUSE_DATA        0x20
84
#define z8530_MOUSE_DATA        0x20
78
 
85
 
79
#define KEY_RELEASE 0x80
86
#define KEY_RELEASE 0x80
80
 
87
 
81
/**
88
/*
82
 * These codes read from i8042 data register are silently ignored.
89
 * These codes read from z8530 data register are silently ignored.
83
 */
90
 */
84
#define IGNORE_CODE 0x7f
91
#define IGNORE_CODE 0x7f        /* all keys up */
85
 
92
 
86
static void key_released(uint8_t sc);
93
static void key_released(uint8_t sc);
87
static void key_pressed(uint8_t sc);
94
static void key_pressed(uint8_t sc);
88
static char key_read(chardev_t *d);
95
static char key_read(chardev_t *d);
89
 
96
 
90
#define PRESSED_SHIFT       (1<<0)
97
#define PRESSED_SHIFT       (1<<0)
91
#define PRESSED_CAPSLOCK    (1<<1)
98
#define PRESSED_CAPSLOCK    (1<<1)
92
#define LOCKED_CAPSLOCK     (1<<0)
99
#define LOCKED_CAPSLOCK     (1<<0)
93
 
100
 
94
#define ACTIVE_READ_BUFF_SIZE 16    /* Must be power of 2 */
101
#define ACTIVE_READ_BUFF_SIZE 16    /* Must be power of 2 */
95
 
102
 
96
static uint8_t active_read_buff[ACTIVE_READ_BUFF_SIZE];
103
static uint8_t active_read_buff[ACTIVE_READ_BUFF_SIZE];
97
 
104
 
98
SPINLOCK_INITIALIZE(keylock);       /**< keylock protects keyflags and lockflags. */
105
SPINLOCK_INITIALIZE(keylock);       /**< keylock protects keyflags and lockflags. */
99
static volatile int keyflags;       /**< Tracking of multiple keypresses. */
106
static volatile int keyflags;       /**< Tracking of multiple keypresses. */
100
static volatile int lockflags;      /**< Tracking of multiple keys lockings. */
107
static volatile int lockflags;      /**< Tracking of multiple keys lockings. */
101
 
108
 
102
static void i8042_suspend(chardev_t *);
109
static void z8530_suspend(chardev_t *);
103
static void i8042_resume(chardev_t *);
110
static void z8530_resume(chardev_t *);
104
 
111
 
105
static chardev_t kbrd;
112
static chardev_t kbrd;
106
static chardev_operations_t ops = {
113
static chardev_operations_t ops = {
107
    .suspend = i8042_suspend,
114
    .suspend = z8530_suspend,
108
    .resume = i8042_resume,
115
    .resume = z8530_resume,
109
    .read = key_read
116
    .read = key_read
110
};
117
};
111
 
118
 
112
static void i8042_interrupt(int n, istate_t *istate);
119
static void z8530_interrupt(int n, istate_t *istate);
113
static void i8042_wait(void);
120
static void z8530_wait(void);
114
 
121
 
115
static iroutine oldvector;
122
static iroutine oldvector;
116
/** Initialize keyboard and service interrupts using kernel routine */
123
/** Initialize keyboard and service interrupts using kernel routine */
117
void i8042_grab(void)
124
void z8530_grab(void)
118
{
125
{
119
    oldvector = exc_register(VECTOR_KBD, "i8042_interrupt", (iroutine) i8042_interrupt);
126
    oldvector = exc_register(VECTOR_KBD, "z8530_interrupt", (iroutine) z8530_interrupt);
120
    i8042_wait();
127
    z8530_wait();
121
    i8042_command_write(i8042_SET_COMMAND);
128
    z8530_command_write(z8530_SET_COMMAND);
122
    i8042_wait();
129
    z8530_wait();
123
    i8042_data_write(i8042_COMMAND);
130
    z8530_data_write(z8530_COMMAND);
124
    i8042_wait();
131
    z8530_wait();
125
}
132
}
126
/** Resume the former interrupt vector */
133
/** Resume the former interrupt vector */
127
void i8042_release(void)
134
void z8530_release(void)
128
{
135
{
129
    if (oldvector)
136
    if (oldvector)
130
        exc_register(VECTOR_KBD, "user_interrupt", oldvector);
137
        exc_register(VECTOR_KBD, "user_interrupt", oldvector);
131
}
138
}
132
 
139
 
133
/** Initialize i8042. */
140
/** Initialize z8530. */
134
void i8042_init(void)
141
void z8530_init(void)
135
{
142
{
136
    int i;
143
    int i;
137
 
144
 
138
    i8042_grab();
145
    z8530_grab();
139
        /* Prevent user from accidentaly releasing calling i8042_resume
146
        /* Prevent user from accidentaly releasing calling z8530_resume
140
     * and disabling keyboard
147
     * and disabling keyboard
141
     */
148
     */
142
    oldvector = NULL;
149
    oldvector = NULL;
143
 
150
 
144
    trap_virtual_enable_irqs(1<<IRQ_KBD);
151
    trap_virtual_enable_irqs(1<<IRQ_KBD);
145
    chardev_initialize("i8042_kbd", &kbrd, &ops);
152
    chardev_initialize("z8530_kbd", &kbrd, &ops);
146
    stdin = &kbrd;
153
    stdin = &kbrd;
147
 
154
 
148
    /*
155
    /*
149
     * Clear input buffer.
156
     * Clear input buffer.
150
     * Number of iterations is limited to prevent infinite looping.
157
     * Number of iterations is limited to prevent infinite looping.
151
     */
158
     */
152
    for (i = 0; (i8042_status_read() & i8042_BUFFER_FULL_MASK) && i < 100; i++) {
159
    for (i = 0; (z8530_status_read() & z8530_BUFFER_FULL_MASK) && i < 100; i++) {
153
        i8042_data_read();
160
        z8530_data_read();
154
    }  
161
    }  
155
}
162
}
156
 
163
 
157
/** Process i8042 interrupt.
164
/** Process z8530 interrupt.
158
 *
165
 *
159
 * @param n Interrupt vector.
166
 * @param n Interrupt vector.
160
 * @param istate Interrupted state.
167
 * @param istate Interrupted state.
161
 */
168
 */
162
void i8042_interrupt(int n, istate_t *istate)
169
void z8530_interrupt(int n, istate_t *istate)
163
{
170
{
164
    uint8_t x;
171
    uint8_t x;
165
    uint8_t status;
172
    uint8_t status;
166
 
173
 
167
    while (((status=i8042_status_read()) & i8042_BUFFER_FULL_MASK)) {
174
    while (((status=z8530_status_read()) & z8530_BUFFER_FULL_MASK)) {
168
        x = i8042_data_read();
175
        x = z8530_data_read();
169
 
176
 
170
        if ((status & i8042_MOUSE_DATA))
177
        if ((status & z8530_MOUSE_DATA))
171
            continue;
178
            continue;
172
 
179
 
173
        if (x & KEY_RELEASE)
180
        if (x & KEY_RELEASE)
174
            key_released(x ^ KEY_RELEASE);
181
            key_released(x ^ KEY_RELEASE);
175
        else
182
        else
176
            key_pressed(x);
183
            key_pressed(x);
177
    }
184
    }
178
    trap_virtual_eoi();
185
    trap_virtual_eoi();
179
}
186
}
180
 
187
 
181
/** Wait until the controller reads its data. */
188
/** Wait until the controller reads its data. */
182
void i8042_wait(void) {
189
void z8530_wait(void) {
183
    while (i8042_status_read() & i8042_WAIT_MASK) {
190
    while (z8530_status_read() & z8530_WAIT_MASK) {
184
        /* wait */
191
        /* wait */
185
    }
192
    }
186
}
193
}
187
 
194
 
188
/** Process release of key.
195
/** Process release of key.
189
 *
196
 *
190
 * @param sc Scancode of the key being released.
197
 * @param sc Scancode of the key being released.
191
 */
198
 */
192
void key_released(uint8_t sc)
199
void key_released(uint8_t sc)
193
{
200
{
194
    spinlock_lock(&keylock);
201
    spinlock_lock(&keylock);
195
    switch (sc) {
202
    switch (sc) {
196
        case SC_LSHIFT:
203
        case SC_LSHIFT:
197
        case SC_RSHIFT:
204
        case SC_RSHIFT:
198
        keyflags &= ~PRESSED_SHIFT;
205
        keyflags &= ~PRESSED_SHIFT;
199
        break;
206
        break;
200
        case SC_CAPSLOCK:
207
        case SC_CAPSLOCK:
201
        keyflags &= ~PRESSED_CAPSLOCK;
208
        keyflags &= ~PRESSED_CAPSLOCK;
202
        if (lockflags & LOCKED_CAPSLOCK)
209
        if (lockflags & LOCKED_CAPSLOCK)
203
            lockflags &= ~LOCKED_CAPSLOCK;
210
            lockflags &= ~LOCKED_CAPSLOCK;
204
        else
211
        else
205
            lockflags |= LOCKED_CAPSLOCK;
212
            lockflags |= LOCKED_CAPSLOCK;
206
        break;
213
        break;
207
        default:
214
        default:
208
        break;
215
        break;
209
    }
216
    }
210
    spinlock_unlock(&keylock);
217
    spinlock_unlock(&keylock);
211
}
218
}
212
 
219
 
213
/** Process keypress.
220
/** Process keypress.
214
 *
221
 *
215
 * @param sc Scancode of the key being pressed.
222
 * @param sc Scancode of the key being pressed.
216
 */
223
 */
217
void key_pressed(uint8_t sc)
224
void key_pressed(uint8_t sc)
218
{
225
{
219
    char *map = sc_primary_map;
226
    char *map = sc_primary_map;
220
    char ascii = sc_primary_map[sc];
227
    char ascii = sc_primary_map[sc];
221
    bool shift, capslock;
228
    bool shift, capslock;
222
    bool letter = false;
229
    bool letter = false;
223
 
230
 
224
    spinlock_lock(&keylock);
231
    spinlock_lock(&keylock);
225
    switch (sc) {
232
    switch (sc) {
226
    case SC_LSHIFT:
233
    case SC_LSHIFT:
227
    case SC_RSHIFT:
234
    case SC_RSHIFT:
228
            keyflags |= PRESSED_SHIFT;
235
            keyflags |= PRESSED_SHIFT;
229
        break;
236
        break;
230
    case SC_CAPSLOCK:
237
    case SC_CAPSLOCK:
231
        keyflags |= PRESSED_CAPSLOCK;
238
        keyflags |= PRESSED_CAPSLOCK;
232
        break;
239
        break;
233
    case SC_SPEC_ESCAPE:
240
    case SC_SPEC_ESCAPE:
234
        break;
241
        break;
235
    case SC_LEFTARR:
242
    case SC_LEFTARR:
236
        chardev_push_character(&kbrd, 0x1b);
243
        chardev_push_character(&kbrd, 0x1b);
237
        chardev_push_character(&kbrd, 0x5b);
244
        chardev_push_character(&kbrd, 0x5b);
238
        chardev_push_character(&kbrd, 0x44);
245
        chardev_push_character(&kbrd, 0x44);
239
        break;
246
        break;
240
    case SC_RIGHTARR:
247
    case SC_RIGHTARR:
241
        chardev_push_character(&kbrd, 0x1b);
248
        chardev_push_character(&kbrd, 0x1b);
242
        chardev_push_character(&kbrd, 0x5b);
249
        chardev_push_character(&kbrd, 0x5b);
243
        chardev_push_character(&kbrd, 0x43);
250
        chardev_push_character(&kbrd, 0x43);
244
        break;
251
        break;
245
    case SC_UPARR:
252
    case SC_UPARR:
246
        chardev_push_character(&kbrd, 0x1b);
253
        chardev_push_character(&kbrd, 0x1b);
247
        chardev_push_character(&kbrd, 0x5b);
254
        chardev_push_character(&kbrd, 0x5b);
248
        chardev_push_character(&kbrd, 0x41);
255
        chardev_push_character(&kbrd, 0x41);
249
        break;
256
        break;
250
    case SC_DOWNARR:
257
    case SC_DOWNARR:
251
        chardev_push_character(&kbrd, 0x1b);
258
        chardev_push_character(&kbrd, 0x1b);
252
        chardev_push_character(&kbrd, 0x5b);
259
        chardev_push_character(&kbrd, 0x5b);
253
        chardev_push_character(&kbrd, 0x42);
260
        chardev_push_character(&kbrd, 0x42);
254
        break;
261
        break;
255
    case SC_HOME:
262
    case SC_HOME:
256
        chardev_push_character(&kbrd, 0x1b);
263
        chardev_push_character(&kbrd, 0x1b);
257
        chardev_push_character(&kbrd, 0x4f);
264
        chardev_push_character(&kbrd, 0x4f);
258
        chardev_push_character(&kbrd, 0x48);
265
        chardev_push_character(&kbrd, 0x48);
259
        break;
266
        break;
260
    case SC_END:
267
    case SC_END:
261
        chardev_push_character(&kbrd, 0x1b);
268
        chardev_push_character(&kbrd, 0x1b);
262
        chardev_push_character(&kbrd, 0x4f);
269
        chardev_push_character(&kbrd, 0x4f);
263
        chardev_push_character(&kbrd, 0x46);
270
        chardev_push_character(&kbrd, 0x46);
264
        break;
271
        break;
265
    case SC_DELETE:
272
    case SC_DELETE:
266
        chardev_push_character(&kbrd, 0x1b);
273
        chardev_push_character(&kbrd, 0x1b);
267
        chardev_push_character(&kbrd, 0x5b);
274
        chardev_push_character(&kbrd, 0x5b);
268
        chardev_push_character(&kbrd, 0x33);
275
        chardev_push_character(&kbrd, 0x33);
269
        chardev_push_character(&kbrd, 0x7e);
276
        chardev_push_character(&kbrd, 0x7e);
270
        break;
277
        break;
271
    default:
278
    default:
272
            letter = is_lower(ascii);
279
            letter = is_lower(ascii);
273
        capslock = (keyflags & PRESSED_CAPSLOCK) || (lockflags & LOCKED_CAPSLOCK);
280
        capslock = (keyflags & PRESSED_CAPSLOCK) || (lockflags & LOCKED_CAPSLOCK);
274
        shift = keyflags & PRESSED_SHIFT;
281
        shift = keyflags & PRESSED_SHIFT;
275
        if (letter && capslock)
282
        if (letter && capslock)
276
            shift = !shift;
283
            shift = !shift;
277
        if (shift)
284
        if (shift)
278
            map = sc_secondary_map;
285
            map = sc_secondary_map;
279
        chardev_push_character(&kbrd, map[sc]);
286
        chardev_push_character(&kbrd, map[sc]);
280
        break;
287
        break;
281
    }
288
    }
282
    spinlock_unlock(&keylock);
289
    spinlock_unlock(&keylock);
283
}
290
}
284
 
291
 
285
/* Called from getc(). */
292
/* Called from getc(). */
286
void i8042_resume(chardev_t *d)
293
void z8530_resume(chardev_t *d)
287
{
294
{
288
}
295
}
289
 
296
 
290
/* Called from getc(). */
297
/* Called from getc(). */
291
void i8042_suspend(chardev_t *d)
298
void z8530_suspend(chardev_t *d)
292
{
299
{
293
}
300
}
294
 
301
 
295
static uint8_t active_read_buff_read(void)
302
static uint8_t active_read_buff_read(void)
296
{
303
{
297
    static int i=0;
304
    static int i=0;
298
    i &= (ACTIVE_READ_BUFF_SIZE-1);
305
    i &= (ACTIVE_READ_BUFF_SIZE-1);
299
    if(!active_read_buff[i]) {
306
    if(!active_read_buff[i]) {
300
        return 0;
307
        return 0;
301
    }
308
    }
302
    return active_read_buff[i++];
309
    return active_read_buff[i++];
303
}
310
}
304
 
311
 
305
static void active_read_buff_write(uint8_t ch)
312
static void active_read_buff_write(uint8_t ch)
306
{
313
{
307
    static int i=0;
314
    static int i=0;
308
    active_read_buff[i] = ch;
315
    active_read_buff[i] = ch;
309
    i++;
316
    i++;
310
    i &= (ACTIVE_READ_BUFF_SIZE-1);
317
    i &= (ACTIVE_READ_BUFF_SIZE-1);
311
    active_read_buff[i]=0;
318
    active_read_buff[i]=0;
312
}
319
}
313
 
320
 
314
 
321
 
315
static void active_read_key_pressed(uint8_t sc)
322
static void active_read_key_pressed(uint8_t sc)
316
{
323
{
317
    char *map = sc_primary_map;
324
    char *map = sc_primary_map;
318
    char ascii = sc_primary_map[sc];
325
    char ascii = sc_primary_map[sc];
319
    bool shift, capslock;
326
    bool shift, capslock;
320
    bool letter = false;
327
    bool letter = false;
321
 
328
 
322
    /*spinlock_lock(&keylock);*/
329
    /*spinlock_lock(&keylock);*/
323
    switch (sc) {
330
    switch (sc) {
324
    case SC_LSHIFT:
331
    case SC_LSHIFT:
325
    case SC_RSHIFT:
332
    case SC_RSHIFT:
326
            keyflags |= PRESSED_SHIFT;
333
            keyflags |= PRESSED_SHIFT;
327
        break;
334
        break;
328
    case SC_CAPSLOCK:
335
    case SC_CAPSLOCK:
329
        keyflags |= PRESSED_CAPSLOCK;
336
        keyflags |= PRESSED_CAPSLOCK;
330
        break;
337
        break;
331
    case SC_SPEC_ESCAPE:
338
    case SC_SPEC_ESCAPE:
332
        break;
339
        break;
333
    case SC_LEFTARR:
340
    case SC_LEFTARR:
334
        active_read_buff_write(0x1b);
341
        active_read_buff_write(0x1b);
335
        active_read_buff_write(0x5b);
342
        active_read_buff_write(0x5b);
336
        active_read_buff_write(0x44);
343
        active_read_buff_write(0x44);
337
        break;
344
        break;
338
    case SC_RIGHTARR:
345
    case SC_RIGHTARR:
339
        active_read_buff_write(0x1b);
346
        active_read_buff_write(0x1b);
340
        active_read_buff_write(0x5b);
347
        active_read_buff_write(0x5b);
341
        active_read_buff_write(0x43);
348
        active_read_buff_write(0x43);
342
        break;
349
        break;
343
    case SC_UPARR:
350
    case SC_UPARR:
344
        active_read_buff_write(0x1b);
351
        active_read_buff_write(0x1b);
345
        active_read_buff_write(0x5b);
352
        active_read_buff_write(0x5b);
346
        active_read_buff_write(0x41);
353
        active_read_buff_write(0x41);
347
        break;
354
        break;
348
    case SC_DOWNARR:
355
    case SC_DOWNARR:
349
        active_read_buff_write(0x1b);
356
        active_read_buff_write(0x1b);
350
        active_read_buff_write(0x5b);
357
        active_read_buff_write(0x5b);
351
        active_read_buff_write(0x42);
358
        active_read_buff_write(0x42);
352
        break;
359
        break;
353
    case SC_HOME:
360
    case SC_HOME:
354
        active_read_buff_write(0x1b);
361
        active_read_buff_write(0x1b);
355
        active_read_buff_write(0x4f);
362
        active_read_buff_write(0x4f);
356
        active_read_buff_write(0x48);
363
        active_read_buff_write(0x48);
357
        break;
364
        break;
358
    case SC_END:
365
    case SC_END:
359
        active_read_buff_write(0x1b);
366
        active_read_buff_write(0x1b);
360
        active_read_buff_write(0x4f);
367
        active_read_buff_write(0x4f);
361
        active_read_buff_write(0x46);
368
        active_read_buff_write(0x46);
362
        break;
369
        break;
363
    case SC_DELETE:
370
    case SC_DELETE:
364
        active_read_buff_write(0x1b);
371
        active_read_buff_write(0x1b);
365
        active_read_buff_write(0x5b);
372
        active_read_buff_write(0x5b);
366
        active_read_buff_write(0x33);
373
        active_read_buff_write(0x33);
367
        active_read_buff_write(0x7e);
374
        active_read_buff_write(0x7e);
368
        break;
375
        break;
369
    default:
376
    default:
370
            letter = is_lower(ascii);
377
            letter = is_lower(ascii);
371
        capslock = (keyflags & PRESSED_CAPSLOCK) || (lockflags & LOCKED_CAPSLOCK);
378
        capslock = (keyflags & PRESSED_CAPSLOCK) || (lockflags & LOCKED_CAPSLOCK);
372
        shift = keyflags & PRESSED_SHIFT;
379
        shift = keyflags & PRESSED_SHIFT;
373
        if (letter && capslock)
380
        if (letter && capslock)
374
            shift = !shift;
381
            shift = !shift;
375
        if (shift)
382
        if (shift)
376
            map = sc_secondary_map;
383
            map = sc_secondary_map;
377
        active_read_buff_write(map[sc]);
384
        active_read_buff_write(map[sc]);
378
        break;
385
        break;
379
    }
386
    }
380
    /*spinlock_unlock(&keylock);*/
387
    /*spinlock_unlock(&keylock);*/
381
 
388
 
382
}
389
}
383
 
390
 
384
static char key_read(chardev_t *d)
391
static char key_read(chardev_t *d)
385
{
392
{
386
    char ch;   
393
    char ch;   
387
 
394
 
388
    while(!(ch = active_read_buff_read())) {
395
    while(!(ch = active_read_buff_read())) {
389
        uint8_t x;
396
        uint8_t x;
390
        while (!(i8042_status_read() & i8042_BUFFER_FULL_MASK))
397
        while (!(z8530_status_read() & z8530_BUFFER_FULL_MASK))
391
            ;
398
            ;
392
        x = i8042_data_read();
399
        x = z8530_data_read();
393
        if (x != IGNORE_CODE) {
400
        if (x != IGNORE_CODE) {
394
            if (x & KEY_RELEASE)
401
            if (x & KEY_RELEASE)
395
                key_released(x ^ KEY_RELEASE);
402
                key_released(x ^ KEY_RELEASE);
396
            else
403
            else
397
                active_read_key_pressed(x);
404
                active_read_key_pressed(x);
398
        }
405
        }
399
    }
406
    }
400
    return ch;
407
    return ch;
401
}
408
}
402
 
409
 
403
/** Poll for key press and release events.
410
/** Poll for key press and release events.
404
 *
411
 *
405
 * This function can be used to implement keyboard polling.
412
 * This function can be used to implement keyboard polling.
406
 */
413
 */
407
void i8042_poll(void)
414
void z8530_poll(void)
408
{
415
{
409
    uint8_t x;
416
    uint8_t x;
410
 
417
 
411
    while (((x = i8042_status_read() & i8042_BUFFER_FULL_MASK))) {
418
    while (((x = z8530_status_read() & z8530_BUFFER_FULL_MASK))) {
412
        x = i8042_data_read();
419
        x = z8530_data_read();
413
        if (x != IGNORE_CODE) {
420
        if (x != IGNORE_CODE) {
414
            if (x & KEY_RELEASE)
421
            if (x & KEY_RELEASE)
415
                key_released(x ^ KEY_RELEASE);
422
                key_released(x ^ KEY_RELEASE);
416
            else
423
            else
417
                key_pressed(x);
424
                key_pressed(x);
418
        }
425
        }
419
    }
426
    }
420
}
427
}
421
 
428
 
422
/** @}
429
/** @}
423
 */
430
 */
424
 
-
 
425
 
431