Rev 3943 | Rev 3969 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3943 | Rev 3944 | ||
---|---|---|---|
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. */ |
66 | /** Currently pressed lock keys. We track these to tackle autorepeat. */ |
67 | static unsigned lock_keys; |
67 | static unsigned lock_keys; |
68 | 68 | ||
69 | void kbd_push_scancode(int scancode) |
69 | void kbd_push_scancode(int scancode) |
70 | { |
70 | { |
71 | printf("scancode: 0x%x\n", scancode); |
71 | /* printf("scancode: 0x%x\n", scancode);*/ |
72 | kbd_ctl_parse_scancode(scancode); |
72 | kbd_ctl_parse_scancode(scancode); |
73 | } |
73 | } |
74 | 74 | ||
75 | void kbd_push_ev(int type, unsigned int key) |
75 | void kbd_push_ev(int type, unsigned int key) |
76 | { |
76 | { |
77 | kbd_event_t ev; |
77 | kbd_event_t ev; |
78 | unsigned mod_mask; |
78 | unsigned mod_mask; |
79 | 79 | ||
80 | switch (key) { |
80 | switch (key) { |
81 | case KC_LCTRL: mod_mask = KM_LCTRL; break; |
81 | case KC_LCTRL: mod_mask = KM_LCTRL; break; |
82 | case KC_RCTRL: mod_mask = KM_RCTRL; break; |
82 | case KC_RCTRL: mod_mask = KM_RCTRL; break; |
83 | case KC_LSHIFT: mod_mask = KM_LSHIFT; break; |
83 | case KC_LSHIFT: mod_mask = KM_LSHIFT; break; |
84 | case KC_RSHIFT: mod_mask = KM_RSHIFT; break; |
84 | case KC_RSHIFT: mod_mask = KM_RSHIFT; break; |
85 | case KC_LALT: mod_mask = KM_LALT; break; |
85 | case KC_LALT: mod_mask = KM_LALT; break; |
86 | case KC_RALT: mod_mask = KM_RALT; break; |
86 | case KC_RALT: mod_mask = KM_RALT; break; |
87 | default: mod_mask = 0; break; |
87 | default: mod_mask = 0; break; |
88 | } |
88 | } |
89 | 89 | ||
90 | if (mod_mask != 0) { |
90 | if (mod_mask != 0) { |
91 | if (type == KE_PRESS) |
91 | if (type == KE_PRESS) |
92 | mods = mods | mod_mask; |
92 | mods = mods | mod_mask; |
93 | else |
93 | else |
94 | mods = mods & ~mod_mask; |
94 | mods = mods & ~mod_mask; |
95 | } |
95 | } |
96 | 96 | ||
97 | switch (key) { |
97 | switch (key) { |
98 | case KC_CAPS_LOCK: mod_mask = KM_CAPS_LOCK; break; |
98 | case KC_CAPS_LOCK: mod_mask = KM_CAPS_LOCK; break; |
99 | case KC_NUM_LOCK: mod_mask = KM_NUM_LOCK; break; |
99 | case KC_NUM_LOCK: mod_mask = KM_NUM_LOCK; break; |
100 | case KC_SCROLL_LOCK: mod_mask = KM_SCROLL_LOCK; break; |
100 | case KC_SCROLL_LOCK: mod_mask = KM_SCROLL_LOCK; break; |
101 | default: mod_mask = 0; break; |
101 | default: mod_mask = 0; break; |
102 | } |
102 | } |
103 | 103 | ||
104 | if (mod_mask != 0) { |
104 | if (mod_mask != 0) { |
105 | if (type == KE_PRESS) { |
105 | if (type == KE_PRESS) { |
106 | /* |
106 | /* |
107 | * Only change lock state on transition from released |
107 | * Only change lock state on transition from released |
108 | * to pressed. This prevents autorepeat from messing |
108 | * to pressed. This prevents autorepeat from messing |
109 | * up the lock state. |
109 | * up the lock state. |
110 | */ |
110 | */ |
111 | mods = mods ^ (mod_mask & ~lock_keys); |
111 | mods = mods ^ (mod_mask & ~lock_keys); |
112 | lock_keys = lock_keys | mod_mask; |
112 | lock_keys = lock_keys | mod_mask; |
113 | } else { |
113 | } else { |
114 | lock_keys = lock_keys & ~mod_mask; |
114 | lock_keys = lock_keys & ~mod_mask; |
115 | } |
115 | } |
116 | } |
116 | } |
117 | 117 | /* |
|
118 | printf("type: %d\n", type); |
118 | printf("type: %d\n", type); |
119 | printf("mods: 0x%x\n", mods); |
119 | printf("mods: 0x%x\n", mods); |
120 | printf("keycode: %u\n", key); |
120 | printf("keycode: %u\n", key); |
121 | 121 | */ |
|
122 | ev.type = type; |
122 | ev.type = type; |
123 | ev.key = key; |
123 | ev.key = key; |
124 | ev.mods = mods; |
124 | ev.mods = mods; |
125 | 125 | ||
126 | ev.c = layout_parse_ev(&ev); |
126 | ev.c = layout_parse_ev(&ev); |
127 | 127 | ||
128 | 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); |
129 | } |
129 | } |
130 | 130 | ||
131 | 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) |
132 | { |
132 | { |
133 | ipc_callid_t callid; |
133 | ipc_callid_t callid; |
134 | ipc_call_t call; |
134 | ipc_call_t call; |
135 | int retval; |
135 | int retval; |
136 | 136 | ||
137 | if (cons_connected) { |
137 | if (cons_connected) { |
138 | ipc_answer_0(iid, ELIMIT); |
138 | ipc_answer_0(iid, ELIMIT); |
139 | return; |
139 | return; |
140 | } |
140 | } |
141 | cons_connected = 1; |
141 | cons_connected = 1; |
142 | ipc_answer_0(iid, EOK); |
142 | ipc_answer_0(iid, EOK); |
143 | 143 | ||
144 | while (1) { |
144 | while (1) { |
145 | callid = async_get_call(&call); |
145 | callid = async_get_call(&call); |
146 | switch (IPC_GET_METHOD(call)) { |
146 | switch (IPC_GET_METHOD(call)) { |
147 | case IPC_M_PHONE_HUNGUP: |
147 | case IPC_M_PHONE_HUNGUP: |
148 | cons_connected = 0; |
148 | cons_connected = 0; |
149 | ipc_hangup(phone2cons); |
149 | ipc_hangup(phone2cons); |
150 | phone2cons = -1; |
150 | phone2cons = -1; |
151 | ipc_answer_0(callid, EOK); |
151 | ipc_answer_0(callid, EOK); |
152 | return; |
152 | return; |
153 | case IPC_M_CONNECT_TO_ME: |
153 | case IPC_M_CONNECT_TO_ME: |
154 | if (phone2cons != -1) { |
154 | if (phone2cons != -1) { |
155 | retval = ELIMIT; |
155 | retval = ELIMIT; |
156 | break; |
156 | break; |
157 | } |
157 | } |
158 | phone2cons = IPC_GET_ARG5(call); |
158 | phone2cons = IPC_GET_ARG5(call); |
159 | retval = 0; |
159 | retval = 0; |
160 | break; |
160 | break; |
161 | default: |
161 | default: |
162 | retval = EINVAL; |
162 | retval = EINVAL; |
163 | } |
163 | } |
164 | ipc_answer_0(callid, retval); |
164 | ipc_answer_0(callid, retval); |
165 | } |
165 | } |
166 | } |
166 | } |
167 | 167 | ||
168 | 168 | ||
169 | int main(int argc, char **argv) |
169 | int main(int argc, char **argv) |
170 | { |
170 | { |
171 | printf(NAME ": HelenOS Keyboard service\n"); |
171 | printf(NAME ": HelenOS Keyboard service\n"); |
172 | 172 | ||
173 | ipcarg_t phonead; |
173 | ipcarg_t phonead; |
174 | 174 | ||
175 | /* Initialize port driver. */ |
175 | /* Initialize port driver. */ |
176 | if (kbd_port_init()) |
176 | if (kbd_port_init()) |
177 | return -1; |
177 | return -1; |
178 | 178 | ||
179 | /* Initialize key buffer */ |
179 | /* Initialize key buffer */ |
180 | keybuffer_init(&keybuffer); |
180 | keybuffer_init(&keybuffer); |
181 | 181 | ||
182 | async_set_client_connection(console_connection); |
182 | async_set_client_connection(console_connection); |
183 | 183 | ||
184 | /* Register service at nameserver. */ |
184 | /* Register service at nameserver. */ |
185 | 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) |
186 | return -1; |
186 | return -1; |
187 | 187 | ||
188 | printf(NAME ": Accepting connections\n"); |
188 | printf(NAME ": Accepting connections\n"); |
189 | async_manager(); |
189 | async_manager(); |
190 | 190 | ||
191 | /* Not reached. */ |
191 | /* Not reached. */ |
192 | return 0; |
192 | return 0; |
193 | } |
193 | } |
194 | 194 | ||
195 | /** |
195 | /** |
196 | * @} |
196 | * @} |
197 | */ |
197 | */ |
198 | 198 |