Subversion Repositories HelenOS

Rev

Rev 4156 | Rev 4420 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4156 Rev 4296
Line 50... Line 50...
50
#include <console/console.h>
50
#include <console/console.h>
51
#include <proc/thread.h>
51
#include <proc/thread.h>
52
#include <arch.h>
52
#include <arch.h>
53
#include <macros.h>
53
#include <macros.h>
54
 
54
 
55
#ifdef CONFIG_SUN_KBD
-
 
56
    #define IGNORE_CODE  0x7f
55
#define IGNORE_CODE  0x7f
57
#endif
-
 
58
 
-
 
59
#define KEY_RELEASE  0x80
56
#define KEY_RELEASE  0x80
60
 
57
 
61
#define PRESSED_SHIFT     (1 << 0)
58
#define PRESSED_SHIFT     (1 << 0)
62
#define PRESSED_CAPSLOCK  (1 << 1)
59
#define PRESSED_CAPSLOCK  (1 << 1)
63
#define LOCKED_CAPSLOCK   (1 << 0)
60
#define LOCKED_CAPSLOCK   (1 << 0)
Line 70... Line 67...
70
 
67
 
71
SPINLOCK_INITIALIZE(keylock);   /**< keylock protects keyflags and lockflags. */
68
SPINLOCK_INITIALIZE(keylock);   /**< keylock protects keyflags and lockflags. */
72
static volatile int keyflags;   /**< Tracking of multiple keypresses. */
69
static volatile int keyflags;   /**< Tracking of multiple keypresses. */
73
static volatile int lockflags;  /**< Tracking of multiple keys lockings. */
70
static volatile int lockflags;  /**< Tracking of multiple keys lockings. */
74
 
71
 
75
static void key_released(uint8_t);
-
 
76
static void key_pressed(uint8_t);
-
 
77
 
-
 
78
static void kkbrd(void *arg)
-
 
79
{
-
 
80
    indev_t *in = (indev_t *) arg;
-
 
81
   
-
 
82
    while (true) {
-
 
83
        uint8_t sc = _getc(in);
-
 
84
       
-
 
85
#ifdef CONFIG_SUN_KBD
-
 
86
        if (sc == IGNORE_CODE)
-
 
87
            continue;
-
 
88
#endif
-
 
89
       
-
 
90
        if (sc & KEY_RELEASE)
-
 
91
            key_released(sc ^ KEY_RELEASE);
-
 
92
        else
-
 
93
            key_pressed(sc);
-
 
94
    }
-
 
95
}
-
 
96
 
-
 
97
void kbrd_init(indev_t *devin)
-
 
98
{
-
 
99
    indev_initialize("kbrd", &kbrdout, &kbrdout_ops);
-
 
100
    thread_t *thread
-
 
101
        = thread_create(kkbrd, devin, TASK, 0, "kkbrd", false);
-
 
102
   
-
 
103
    if (thread) {
-
 
104
        stdin = &kbrdout;
-
 
105
        thread_ready(thread);
-
 
106
    }
-
 
107
}
-
 
108
 
-
 
109
/** Process release of key.
72
/** Process release of key.
110
 *
73
 *
111
 * @param sc Scancode of the key being released.
74
 * @param sc Scancode of the key being released.
112
 */
75
 */
113
void key_released(uint8_t sc)
76
static void key_released(wchar_t sc)
114
{
77
{
115
    spinlock_lock(&keylock);
78
    spinlock_lock(&keylock);
116
    switch (sc) {
79
    switch (sc) {
117
    case SC_LSHIFT:
80
    case SC_LSHIFT:
118
    case SC_RSHIFT:
81
    case SC_RSHIFT:
Line 133... Line 96...
133
 
96
 
134
/** Process keypress.
97
/** Process keypress.
135
 *
98
 *
136
 * @param sc Scancode of the key being pressed.
99
 * @param sc Scancode of the key being pressed.
137
 */
100
 */
138
void key_pressed(uint8_t sc)
101
static void key_pressed(wchar_t sc)
139
{
102
{
140
    char *map = sc_primary_map;
103
    bool letter;
141
    char ascii = sc_primary_map[sc];
-
 
142
    bool shift, capslock;
104
    bool shift;
143
    bool letter = false;
105
    bool capslock;
144
   
106
   
145
    spinlock_lock(&keylock);
107
    spinlock_lock(&keylock);
146
    switch (sc) {
108
    switch (sc) {
147
    case SC_LSHIFT:
109
    case SC_LSHIFT:
148
    case SC_RSHIFT:
110
    case SC_RSHIFT:
149
        keyflags |= PRESSED_SHIFT;
111
        keyflags |= PRESSED_SHIFT;
150
        break;
112
        break;
151
    case SC_CAPSLOCK:
113
    case SC_CAPSLOCK:
152
        keyflags |= PRESSED_CAPSLOCK;
114
        keyflags |= PRESSED_CAPSLOCK;
153
        break;
115
        break;
154
    case SC_SPEC_ESCAPE:
116
    case SC_SCAN_ESCAPE:
155
        break;
-
 
156
    case SC_LEFTARR:
-
 
157
        indev_push_character(stdin, 0x1b);
-
 
158
        indev_push_character(stdin, 0x5b);
-
 
159
        indev_push_character(stdin, 0x44);
-
 
160
        break;
-
 
161
    case SC_RIGHTARR:
-
 
162
        indev_push_character(stdin, 0x1b);
-
 
163
        indev_push_character(stdin, 0x5b);
-
 
164
        indev_push_character(stdin, 0x43);
-
 
165
        break;
-
 
166
    case SC_UPARR:
-
 
167
        indev_push_character(stdin, 0x1b);
-
 
168
        indev_push_character(stdin, 0x5b);
-
 
169
        indev_push_character(stdin, 0x41);
-
 
170
        break;
-
 
171
    case SC_DOWNARR:
-
 
172
        indev_push_character(stdin, 0x1b);
-
 
173
        indev_push_character(stdin, 0x5b);
-
 
174
        indev_push_character(stdin, 0x42);
-
 
175
        break;
-
 
176
    case SC_HOME:
-
 
177
        indev_push_character(stdin, 0x1b);
-
 
178
        indev_push_character(stdin, 0x4f);
-
 
179
        indev_push_character(stdin, 0x48);
-
 
180
        break;
-
 
181
    case SC_END:
-
 
182
        indev_push_character(stdin, 0x1b);
-
 
183
        indev_push_character(stdin, 0x4f);
-
 
184
        indev_push_character(stdin, 0x46);
-
 
185
        break;
-
 
186
    case SC_DELETE:
-
 
187
        indev_push_character(stdin, 0x1b);
-
 
188
        indev_push_character(stdin, 0x5b);
-
 
189
        indev_push_character(stdin, 0x33);
-
 
190
        indev_push_character(stdin, 0x7e);
-
 
191
        break;
117
        break;
192
    default:
118
    default:
193
        letter = islower(ascii);
119
        letter = islower(sc_primary_map[sc]);
-
 
120
        shift = keyflags & PRESSED_SHIFT;
194
        capslock = (keyflags & PRESSED_CAPSLOCK) ||
121
        capslock = (keyflags & PRESSED_CAPSLOCK) ||
195
            (lockflags & LOCKED_CAPSLOCK);
122
            (lockflags & LOCKED_CAPSLOCK);
196
        shift = keyflags & PRESSED_SHIFT;
-
 
-
 
123
       
197
        if (letter && capslock)
124
        if ((letter) && (capslock))
198
            shift = !shift;
125
            shift = !shift;
-
 
126
       
199
        if (shift)
127
        if (shift)
200
            map = sc_secondary_map;
128
            indev_push_character(stdin, sc_secondary_map[sc]);
-
 
129
        else
201
        indev_push_character(stdin, map[sc]);
130
            indev_push_character(stdin, sc_primary_map[sc]);
202
        break;
131
        break;
203
    }
132
    }
204
    spinlock_unlock(&keylock);
133
    spinlock_unlock(&keylock);
205
}
134
}
206
 
135
 
-
 
136
static void kkbrd(void *arg)
-
 
137
{
-
 
138
    indev_t *in = (indev_t *) arg;
-
 
139
   
-
 
140
    while (true) {
-
 
141
        wchar_t sc = _getc(in);
-
 
142
       
-
 
143
        if (sc == IGNORE_CODE)
-
 
144
            continue;
-
 
145
       
-
 
146
        if (sc & KEY_RELEASE)
-
 
147
            key_released((sc ^ KEY_RELEASE) & 0x7f);
-
 
148
        else
-
 
149
            key_pressed(sc & 0x7f);
-
 
150
    }
-
 
151
}
-
 
152
 
-
 
153
void kbrd_init(indev_t *devin)
-
 
154
{
-
 
155
    indev_initialize("kbrd", &kbrdout, &kbrdout_ops);
-
 
156
    thread_t *thread
-
 
157
        = thread_create(kkbrd, devin, TASK, 0, "kkbrd", false);
-
 
158
   
-
 
159
    if (thread) {
-
 
160
        stdin = &kbrdout;
-
 
161
        thread_ready(thread);
-
 
162
    }
-
 
163
}
-
 
164
 
207
/** @}
165
/** @}
208
 */
166
 */