Subversion Repositories HelenOS

Rev

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

Rev 3942 Rev 3943
1
/*
1
/*
2
 * Copyright (c) 2006 Josef Cejka
2
 * Copyright (c) 2006 Josef Cejka
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
/**
29
/**
30
 * @addtogroup kbdgen generic
30
 * @addtogroup kbdgen generic
31
 * @brief   HelenOS generic uspace keyboard handler.
31
 * @brief   HelenOS generic uspace keyboard handler.
32
 * @ingroup  kbd
32
 * @ingroup  kbd
33
 * @{
33
 * @{
34
 */
34
 */
35
/** @file
35
/** @file
36
 */
36
 */
37
 
37
 
38
#include <ipc/ipc.h>
38
#include <ipc/ipc.h>
39
#include <ipc/services.h>
39
#include <ipc/services.h>
40
#include <stdio.h>
40
#include <stdio.h>
41
#include <unistd.h>
41
#include <unistd.h>
42
#include <stdlib.h>
42
#include <stdlib.h>
43
#include <stdio.h>
43
#include <stdio.h>
44
#include <ipc/ns.h>
44
#include <ipc/ns.h>
45
#include <async.h>
45
#include <async.h>
46
#include <errno.h>
46
#include <errno.h>
47
#include <libadt/fifo.h>
47
#include <libadt/fifo.h>
48
#include <kbd/kbd.h>
48
#include <kbd/kbd.h>
49
#include <kbd/keycode.h>
49
#include <kbd/keycode.h>
50
 
50
 
51
#include <kbd.h>
51
#include <kbd.h>
52
#include <key_buffer.h>
52
#include <key_buffer.h>
53
#include <kbd_port.h>
53
#include <kbd_port.h>
54
#include <kbd_ctl.h>
54
#include <kbd_ctl.h>
55
#include <layout.h>
55
#include <layout.h>
56
 
56
 
57
#define NAME "kbd"
57
#define NAME "kbd"
58
 
58
 
59
int cons_connected = 0;
59
int cons_connected = 0;
60
int phone2cons = -1;
60
int phone2cons = -1;
61
keybuffer_t keybuffer;
61
keybuffer_t keybuffer;
62
 
62
 
63
/** Currently active modifiers. */
63
/** Currently active modifiers. */
64
static unsigned mods = KM_NUM_LOCK;
64
static unsigned mods = KM_NUM_LOCK;
65
 
65
 
-
 
66
/** Currently pressed lock keys. We track these to tackle autorepeat. */
-
 
67
static unsigned lock_keys;
-
 
68
 
66
void kbd_push_scancode(int scancode)
69
void kbd_push_scancode(int scancode)
67
{
70
{
68
    printf("scancode: 0x%x\n", scancode);
71
    printf("scancode: 0x%x\n", scancode);
69
    kbd_ctl_parse_scancode(scancode);
72
    kbd_ctl_parse_scancode(scancode);
70
}
73
}
71
 
74
 
72
void kbd_push_ev(int type, unsigned int key)
75
void kbd_push_ev(int type, unsigned int key)
73
{
76
{
74
    kbd_event_t ev;
77
    kbd_event_t ev;
75
    unsigned mod_mask;
78
    unsigned mod_mask;
76
 
79
 
77
    switch (key) {
80
    switch (key) {
78
    case KC_LCTRL: mod_mask = KM_LCTRL; break;
81
    case KC_LCTRL: mod_mask = KM_LCTRL; break;
79
    case KC_RCTRL: mod_mask = KM_RCTRL; break;
82
    case KC_RCTRL: mod_mask = KM_RCTRL; break;
80
    case KC_LSHIFT: mod_mask = KM_LSHIFT; break;
83
    case KC_LSHIFT: mod_mask = KM_LSHIFT; break;
81
    case KC_RSHIFT: mod_mask = KM_RSHIFT; break;
84
    case KC_RSHIFT: mod_mask = KM_RSHIFT; break;
82
    case KC_LALT: mod_mask = KM_LALT; break;
85
    case KC_LALT: mod_mask = KM_LALT; break;
83
    case KC_RALT: mod_mask = KM_RALT; break;
86
    case KC_RALT: mod_mask = KM_RALT; break;
84
    default: mod_mask = 0; break;
87
    default: mod_mask = 0; break;
85
    }
88
    }
86
 
89
 
87
    if (mod_mask != 0) {
90
    if (mod_mask != 0) {
88
        if (type == KE_PRESS)
91
        if (type == KE_PRESS)
89
            mods = mods | mod_mask;
92
            mods = mods | mod_mask;
90
        else
93
        else
91
            mods = mods & ~mod_mask;
94
            mods = mods & ~mod_mask;
92
    }
95
    }
93
 
96
 
94
    switch (key) {
97
    switch (key) {
95
    case KC_CAPS_LOCK: mod_mask = KM_CAPS_LOCK; break;
98
    case KC_CAPS_LOCK: mod_mask = KM_CAPS_LOCK; break;
96
    case KC_NUM_LOCK: mod_mask = KM_NUM_LOCK; break;
99
    case KC_NUM_LOCK: mod_mask = KM_NUM_LOCK; break;
97
    case KC_SCROLL_LOCK: mod_mask = KM_SCROLL_LOCK; break;
100
    case KC_SCROLL_LOCK: mod_mask = KM_SCROLL_LOCK; break;
98
    default: mod_mask = 0; break;
101
    default: mod_mask = 0; break;
99
    }
102
    }
100
 
103
 
-
 
104
    if (mod_mask != 0) {
101
    if (mod_mask != 0 && type == KE_PRESS)
105
        if (type == KE_PRESS) {
-
 
106
            /*
-
 
107
             * Only change lock state on transition from released
-
 
108
             * to pressed. This prevents autorepeat from messing
-
 
109
             * up the lock state.
-
 
110
             */
102
        mods = mods ^ mod_mask;
111
            mods = mods ^ (mod_mask & ~lock_keys);
-
 
112
            lock_keys = lock_keys | mod_mask;
-
 
113
        } else {
-
 
114
            lock_keys = lock_keys & ~mod_mask;
-
 
115
        }
-
 
116
    }
103
 
117
 
104
    printf("type: %d\n", type);
118
    printf("type: %d\n", type);
105
    printf("mods: 0x%x\n", mods);
119
    printf("mods: 0x%x\n", mods);
106
    printf("keycode: %u\n", key);
120
    printf("keycode: %u\n", key);
107
 
121
 
108
    ev.type = type;
122
    ev.type = type;
109
    ev.key = key;
123
    ev.key = key;
110
    ev.mods = mods;
124
    ev.mods = mods;
111
 
125
 
112
    ev.c = layout_parse_ev(&ev);
126
    ev.c = layout_parse_ev(&ev);
113
 
127
 
114
    async_msg_4(phone2cons, KBD_EVENT, ev.type, ev.key, ev.mods, ev.c);
128
    async_msg_4(phone2cons, KBD_EVENT, ev.type, ev.key, ev.mods, ev.c);
115
}
129
}
116
 
130
 
117
static void console_connection(ipc_callid_t iid, ipc_call_t *icall)
131
static void console_connection(ipc_callid_t iid, ipc_call_t *icall)
118
{
132
{
119
    ipc_callid_t callid;
133
    ipc_callid_t callid;
120
    ipc_call_t call;
134
    ipc_call_t call;
121
    int retval;
135
    int retval;
122
 
136
 
123
    if (cons_connected) {
137
    if (cons_connected) {
124
        ipc_answer_0(iid, ELIMIT);
138
        ipc_answer_0(iid, ELIMIT);
125
        return;
139
        return;
126
    }
140
    }
127
    cons_connected = 1;
141
    cons_connected = 1;
128
    ipc_answer_0(iid, EOK);
142
    ipc_answer_0(iid, EOK);
129
 
143
 
130
    while (1) {
144
    while (1) {
131
        callid = async_get_call(&call);
145
        callid = async_get_call(&call);
132
        switch (IPC_GET_METHOD(call)) {
146
        switch (IPC_GET_METHOD(call)) {
133
        case IPC_M_PHONE_HUNGUP:
147
        case IPC_M_PHONE_HUNGUP:
134
            cons_connected = 0;
148
            cons_connected = 0;
135
            ipc_hangup(phone2cons);
149
            ipc_hangup(phone2cons);
136
            phone2cons = -1;
150
            phone2cons = -1;
137
            ipc_answer_0(callid, EOK);
151
            ipc_answer_0(callid, EOK);
138
            return;
152
            return;
139
        case IPC_M_CONNECT_TO_ME:
153
        case IPC_M_CONNECT_TO_ME:
140
            if (phone2cons != -1) {
154
            if (phone2cons != -1) {
141
                retval = ELIMIT;
155
                retval = ELIMIT;
142
                break;
156
                break;
143
            }
157
            }
144
            phone2cons = IPC_GET_ARG5(call);
158
            phone2cons = IPC_GET_ARG5(call);
145
            retval = 0;
159
            retval = 0;
146
            break;
160
            break;
147
        default:
161
        default:
148
            retval = EINVAL;
162
            retval = EINVAL;
149
        }
163
        }
150
        ipc_answer_0(callid, retval);
164
        ipc_answer_0(callid, retval);
151
    }  
165
    }  
152
}
166
}
153
 
167
 
154
 
168
 
155
int main(int argc, char **argv)
169
int main(int argc, char **argv)
156
{
170
{
157
    printf(NAME ": HelenOS Keyboard service\n");
171
    printf(NAME ": HelenOS Keyboard service\n");
158
   
172
   
159
    ipcarg_t phonead;
173
    ipcarg_t phonead;
160
   
174
   
161
    /* Initialize port driver. */
175
    /* Initialize port driver. */
162
    if (kbd_port_init())
176
    if (kbd_port_init())
163
        return -1;
177
        return -1;
164
   
178
   
165
    /* Initialize key buffer */
179
    /* Initialize key buffer */
166
    keybuffer_init(&keybuffer);
180
    keybuffer_init(&keybuffer);
167
   
181
   
168
    async_set_client_connection(console_connection);
182
    async_set_client_connection(console_connection);
169
 
183
 
170
    /* Register service at nameserver. */
184
    /* Register service at nameserver. */
171
    if (ipc_connect_to_me(PHONE_NS, SERVICE_KEYBOARD, 0, 0, &phonead) != 0)
185
    if (ipc_connect_to_me(PHONE_NS, SERVICE_KEYBOARD, 0, 0, &phonead) != 0)
172
        return -1;
186
        return -1;
173
   
187
   
174
    printf(NAME ": Accepting connections\n");
188
    printf(NAME ": Accepting connections\n");
175
    async_manager();
189
    async_manager();
176
 
190
 
177
    /* Not reached. */
191
    /* Not reached. */
178
    return 0;
192
    return 0;
179
}
193
}
180
 
194
 
181
/**
195
/**
182
 * @}
196
 * @}
183
 */
197
 */
184
 
198