Rev 3386 | Rev 4263 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3386 | Rev 4153 | ||
---|---|---|---|
Line 35... | Line 35... | ||
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> |
- | 46 | #include <async.h> |
|
45 | #include <errno.h> |
47 | #include <errno.h> |
46 | #include <arch/kbd.h> |
- | |
47 | #include <kbd.h> |
- | |
48 | #include <libadt/fifo.h> |
48 | #include <libadt/fifo.h> |
- | 49 | #include <kbd/kbd.h> |
|
- | 50 | #include <kbd/keycode.h> |
|
- | 51 | ||
- | 52 | #include <kbd.h> |
|
49 | #include <key_buffer.h> |
53 | #include <key_buffer.h> |
- | 54 | #include <kbd_port.h> |
|
50 | #include <async.h> |
55 | #include <kbd_ctl.h> |
51 | #include <keys.h> |
56 | #include <layout.h> |
52 | 57 | ||
53 | #define NAME "kbd" |
58 | #define NAME "kbd" |
54 | 59 | ||
55 | int cons_connected = 0; |
60 | int cons_connected = 0; |
56 | int phone2cons = -1; |
61 | int phone2cons = -1; |
57 | keybuffer_t keybuffer; |
62 | keybuffer_t keybuffer; |
- | 63 | ||
- | 64 | /** Currently active modifiers. */ |
|
- | 65 | static unsigned mods = KM_NUM_LOCK; |
|
- | 66 | ||
- | 67 | /** Currently pressed lock keys. We track these to tackle autorepeat. */ |
|
- | 68 | static unsigned lock_keys; |
|
58 | 69 | ||
- | 70 | int cir_service = 0; |
|
- | 71 | int cir_phone = -1; |
|
- | 72 | ||
59 | static void irq_handler(ipc_callid_t iid, ipc_call_t *call) |
73 | void kbd_push_scancode(int scancode) |
60 | { |
74 | { |
61 | int chr; |
75 | /* printf("scancode: 0x%x\n", scancode);*/ |
- | 76 | kbd_ctl_parse_scancode(scancode); |
|
- | 77 | } |
|
62 | 78 | ||
63 | #ifdef MOUSE_ENABLED |
- | |
64 | if (mouse_arch_process(phone2cons, call)) |
79 | void kbd_push_ev(int type, unsigned int key) |
65 | return; |
- | |
66 | #endif |
- | |
67 | 80 | { |
|
68 | kbd_arch_process(&keybuffer, call); |
81 | kbd_event_t ev; |
- | 82 | unsigned mod_mask; |
|
69 | 83 | ||
- | 84 | switch (key) { |
|
70 | if (cons_connected && phone2cons != -1) { |
85 | case KC_LCTRL: mod_mask = KM_LCTRL; break; |
71 | /* |
- | |
- | 86 | case KC_RCTRL: mod_mask = KM_RCTRL; break; |
|
- | 87 | case KC_LSHIFT: mod_mask = KM_LSHIFT; break; |
|
72 | * recode to ASCII - one interrupt can produce more than one |
88 | case KC_RSHIFT: mod_mask = KM_RSHIFT; break; |
- | 89 | case KC_LALT: mod_mask = KM_LALT; break; |
|
- | 90 | case KC_RALT: mod_mask = KM_RALT; break; |
|
73 | * code so result is stored in fifo |
91 | default: mod_mask = 0; break; |
74 | */ |
92 | } |
- | 93 | ||
75 | while (!keybuffer_empty(&keybuffer)) { |
94 | if (mod_mask != 0) { |
76 | if (!keybuffer_pop(&keybuffer, (int *)&chr)) |
95 | if (type == KE_PRESS) |
- | 96 | mods = mods | mod_mask; |
|
77 | break; |
97 | else |
- | 98 | mods = mods & ~mod_mask; |
|
- | 99 | } |
|
78 | 100 | ||
- | 101 | switch (key) { |
|
- | 102 | case KC_CAPS_LOCK: mod_mask = KM_CAPS_LOCK; break; |
|
79 | async_msg_1(phone2cons, KBD_PUSHCHAR, chr); |
103 | case KC_NUM_LOCK: mod_mask = KM_NUM_LOCK; break; |
- | 104 | case KC_SCROLL_LOCK: mod_mask = KM_SCROLL_LOCK; break; |
|
- | 105 | default: mod_mask = 0; break; |
|
- | 106 | } |
|
- | 107 | ||
- | 108 | if (mod_mask != 0) { |
|
- | 109 | if (type == KE_PRESS) { |
|
- | 110 | /* |
|
- | 111 | * Only change lock state on transition from released |
|
- | 112 | * to pressed. This prevents autorepeat from messing |
|
- | 113 | * up the lock state. |
|
- | 114 | */ |
|
- | 115 | mods = mods ^ (mod_mask & ~lock_keys); |
|
- | 116 | lock_keys = lock_keys | mod_mask; |
|
- | 117 | } else { |
|
- | 118 | lock_keys = lock_keys & ~mod_mask; |
|
80 | } |
119 | } |
81 | } |
120 | } |
- | 121 | /* |
|
- | 122 | printf("type: %d\n", type); |
|
- | 123 | printf("mods: 0x%x\n", mods); |
|
- | 124 | printf("keycode: %u\n", key); |
|
- | 125 | */ |
|
- | 126 | ev.type = type; |
|
- | 127 | ev.key = key; |
|
- | 128 | ev.mods = mods; |
|
- | 129 | ||
- | 130 | ev.c = layout_parse_ev(&ev); |
|
- | 131 | ||
- | 132 | async_msg_4(phone2cons, KBD_EVENT, ev.type, ev.key, ev.mods, ev.c); |
|
82 | } |
133 | } |
83 | 134 | ||
84 | 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) |
85 | { |
136 | { |
86 | ipc_callid_t callid; |
137 | ipc_callid_t callid; |
Line 123... | Line 174... | ||
123 | { |
174 | { |
124 | printf(NAME ": HelenOS Keyboard service\n"); |
175 | printf(NAME ": HelenOS Keyboard service\n"); |
125 | 176 | ||
126 | ipcarg_t phonead; |
177 | ipcarg_t phonead; |
127 | 178 | ||
- | 179 | if (sysinfo_value("kbd.cir.fhc") == 1) |
|
- | 180 | cir_service = SERVICE_FHC; |
|
- | 181 | else if (sysinfo_value("kbd.cir.obio") == 1) |
|
- | 182 | cir_service = SERVICE_OBIO; |
|
- | 183 | ||
- | 184 | if (cir_service) { |
|
- | 185 | while (cir_phone < 0) { |
|
- | 186 | cir_phone = ipc_connect_me_to_blocking(PHONE_NS, cir_service, |
|
- | 187 | 0, 0); |
|
- | 188 | } |
|
- | 189 | } |
|
- | 190 | ||
128 | /* Initialize arch dependent parts */ |
191 | /* Initialize port driver. */ |
129 | if (kbd_arch_init()) |
192 | if (kbd_port_init() != 0) |
- | 193 | return -1; |
|
- | 194 | ||
- | 195 | /* Initialize controller driver. */ |
|
- | 196 | if (kbd_ctl_init() != 0) |
|
130 | return -1; |
197 | return -1; |
131 | 198 | ||
132 | /* Initialize key buffer */ |
199 | /* Initialize key buffer */ |
133 | keybuffer_init(&keybuffer); |
200 | keybuffer_init(&keybuffer); |
134 | 201 | ||
135 | async_set_client_connection(console_connection); |
202 | async_set_client_connection(console_connection); |
136 | async_set_interrupt_received(irq_handler); |
- | |
- | 203 | ||
137 | /* Register service at nameserver */ |
204 | /* Register service at nameserver. */ |
138 | if (ipc_connect_to_me(PHONE_NS, SERVICE_KEYBOARD, 0, 0, &phonead) != 0) |
205 | if (ipc_connect_to_me(PHONE_NS, SERVICE_KEYBOARD, 0, 0, &phonead) != 0) |
139 | return -1; |
206 | return -1; |
140 | 207 | ||
141 | printf(NAME ": Accepting connections\n"); |
208 | printf(NAME ": Accepting connections\n"); |
142 | async_manager(); |
209 | async_manager(); |
143 | 210 | ||
144 | /* Never reached */ |
211 | /* Not reached. */ |
145 | return 0; |
212 | return 0; |
146 | } |
213 | } |
147 | 214 | ||
148 | /** |
215 | /** |
149 | * @} |
216 | * @} |