Subversion Repositories HelenOS

Rev

Rev 4042 | Rev 4153 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4042 Rev 4092
Line 60... Line 60...
60
 
60
 
61
#define PRESSED_SHIFT       (1 << 0)
61
#define PRESSED_SHIFT     (1 << 0)
62
#define PRESSED_CAPSLOCK    (1 << 1)
62
#define PRESSED_CAPSLOCK  (1 << 1)
63
#define LOCKED_CAPSLOCK     (1 << 0)
63
#define LOCKED_CAPSLOCK   (1 << 0)
64
 
64
 
65
chardev_t kbrdin;
-
 
66
static chardev_t *kbdout;
65
static indev_t kbrdout;
67
 
66
 
68
static void kbrdin_suspend(chardev_t *d)
-
 
69
{
-
 
70
}
-
 
71
 
-
 
72
static void kbrdin_resume(chardev_t *d)
-
 
73
{
-
 
74
}
-
 
75
 
-
 
76
chardev_operations_t kbrdin_ops = {
67
indev_operations_t kbrdout_ops = {
77
    .suspend = kbrdin_suspend,
-
 
78
    .resume = kbrdin_resume,
68
    .poll = NULL
79
};
69
};
80
 
70
 
81
SPINLOCK_INITIALIZE(keylock);       /**< keylock protects keyflags and lockflags. */
71
SPINLOCK_INITIALIZE(keylock);   /**< keylock protects keyflags and lockflags. */
82
static volatile int keyflags;       /**< Tracking of multiple keypresses. */
72
static volatile int keyflags;   /**< Tracking of multiple keypresses. */
83
static volatile int lockflags;      /**< Tracking of multiple keys lockings. */
73
static volatile int lockflags;  /**< Tracking of multiple keys lockings. */
Line 85... Line 75...
85
static void key_released(uint8_t);
75
static void key_released(uint8_t);
86
static void key_pressed(uint8_t);
76
static void key_pressed(uint8_t);
87
 
77
 
88
static void kkbrd(void *arg)
78
static void kkbrd(void *arg)
89
{
79
{
90
    chardev_t *in = (chardev_t *) arg;
80
    indev_t *in = (indev_t *) arg;
91
    uint8_t sc;
-
 
92
 
81
   
93
    while (1) {
82
    while (true) {
94
        sc = _getc(in);
83
        uint8_t sc = _getc(in);
95
 
84
       
96
#ifdef CONFIG_SUN_KBD
85
#ifdef CONFIG_SUN_KBD
97
        if (sc == IGNORE_CODE)
86
        if (sc == IGNORE_CODE)
98
            continue;
87
            continue;
99
#endif
88
#endif
Line 103... Line 92...
103
        else
92
        else
104
            key_pressed(sc);
93
            key_pressed(sc);
105
    }
94
    }
106
}
95
}
107
 
96
 
108
 
-
 
109
void kbrd_init(chardev_t *devout)
97
void kbrd_init(indev_t *devin)
110
{
98
{
111
    thread_t *t;
-
 
112
 
-
 
113
    chardev_initialize("kbrd", &kbrdin, &kbrdin_ops);
99
    indev_initialize("kbrd", &kbrdout, &kbrdout_ops);
114
    kbdout = devout;
100
    thread_t *thread
-
 
101
        = thread_create(kkbrd, devin, TASK, 0, "kkbrd", false);
115
   
102
   
116
    t = thread_create(kkbrd, &kbrdin, TASK, 0, "kkbrd", false);
103
    if (thread) {
117
    ASSERT(t);
104
        stdin = &kbrdout;
118
    thread_ready(t);
105
        thread_ready(thread);
-
 
106
    }
119
}
107
}
120
 
108
 
121
/** Process release of key.
109
/** Process release of key.
122
 *
110
 *
123
 * @param sc Scancode of the key being released.
111
 * @param sc Scancode of the key being released.
Line 164... Line 152...
164
        keyflags |= PRESSED_CAPSLOCK;
152
        keyflags |= PRESSED_CAPSLOCK;
165
        break;
153
        break;
166
    case SC_SPEC_ESCAPE:
154
    case SC_SPEC_ESCAPE:
167
        break;
155
        break;
168
    case SC_LEFTARR:
156
    case SC_LEFTARR:
169
        chardev_push_character(kbdout, 0x1b);
157
        indev_push_character(stdin, 0x1b);
170
        chardev_push_character(kbdout, 0x5b);
158
        indev_push_character(stdin, 0x5b);
171
        chardev_push_character(kbdout, 0x44);
159
        indev_push_character(stdin, 0x44);
172
        break;
160
        break;
173
    case SC_RIGHTARR:
161
    case SC_RIGHTARR:
174
        chardev_push_character(kbdout, 0x1b);
162
        indev_push_character(stdin, 0x1b);
175
        chardev_push_character(kbdout, 0x5b);
163
        indev_push_character(stdin, 0x5b);
176
        chardev_push_character(kbdout, 0x43);
164
        indev_push_character(stdin, 0x43);
177
        break;
165
        break;
178
    case SC_UPARR:
166
    case SC_UPARR:
179
        chardev_push_character(kbdout, 0x1b);
167
        indev_push_character(stdin, 0x1b);
180
        chardev_push_character(kbdout, 0x5b);
168
        indev_push_character(stdin, 0x5b);
181
        chardev_push_character(kbdout, 0x41);
169
        indev_push_character(stdin, 0x41);
182
        break;
170
        break;
183
    case SC_DOWNARR:
171
    case SC_DOWNARR:
184
        chardev_push_character(kbdout, 0x1b);
172
        indev_push_character(stdin, 0x1b);
185
        chardev_push_character(kbdout, 0x5b);
173
        indev_push_character(stdin, 0x5b);
186
        chardev_push_character(kbdout, 0x42);
174
        indev_push_character(stdin, 0x42);
187
        break;
175
        break;
188
    case SC_HOME:
176
    case SC_HOME:
189
        chardev_push_character(kbdout, 0x1b);
177
        indev_push_character(stdin, 0x1b);
190
        chardev_push_character(kbdout, 0x4f);
178
        indev_push_character(stdin, 0x4f);
191
        chardev_push_character(kbdout, 0x48);
179
        indev_push_character(stdin, 0x48);
192
        break;
180
        break;
193
    case SC_END:
181
    case SC_END:
194
        chardev_push_character(kbdout, 0x1b);
182
        indev_push_character(stdin, 0x1b);
195
        chardev_push_character(kbdout, 0x4f);
183
        indev_push_character(stdin, 0x4f);
196
        chardev_push_character(kbdout, 0x46);
184
        indev_push_character(stdin, 0x46);
197
        break;
185
        break;
198
    case SC_DELETE:
186
    case SC_DELETE:
199
        chardev_push_character(kbdout, 0x1b);
187
        indev_push_character(stdin, 0x1b);
200
        chardev_push_character(kbdout, 0x5b);
188
        indev_push_character(stdin, 0x5b);
201
        chardev_push_character(kbdout, 0x33);
189
        indev_push_character(stdin, 0x33);
202
        chardev_push_character(kbdout, 0x7e);
190
        indev_push_character(stdin, 0x7e);
203
        break;
191
        break;
204
    default:
192
    default:
205
            letter = islower(ascii);
193
        letter = islower(ascii);
206
        capslock = (keyflags & PRESSED_CAPSLOCK) ||
194
        capslock = (keyflags & PRESSED_CAPSLOCK) ||
207
            (lockflags & LOCKED_CAPSLOCK);
195
            (lockflags & LOCKED_CAPSLOCK);
208
        shift = keyflags & PRESSED_SHIFT;
196
        shift = keyflags & PRESSED_SHIFT;
209
        if (letter && capslock)
197
        if (letter && capslock)
210
            shift = !shift;
198
            shift = !shift;
211
        if (shift)
199
        if (shift)
212
            map = sc_secondary_map;
200
            map = sc_secondary_map;
213
        chardev_push_character(kbdout, map[sc]);
201
        indev_push_character(stdin, map[sc]);
214
        break;
202
        break;
215
    }
203
    }
216
    spinlock_unlock(&keylock);
204
    spinlock_unlock(&keylock);
217
}
205
}
218
 
206