Subversion Repositories HelenOS

Rev

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

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