Rev 4669 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4669 | Rev 4718 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2009 Vineeth Pillai |
2 | * Copyright (c) 2009 Vineeth Pillai |
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 | /** @addtogroup genarch |
29 | /** @addtogroup genarch |
30 | * @{ |
30 | * @{ |
31 | */ |
31 | */ |
32 | /** |
32 | /** |
33 | * @file |
33 | * @file |
34 | * @brief pl050 Keyboard processing. |
34 | * @brief pl050 Keyboard processing. |
35 | */ |
35 | */ |
36 | 36 | ||
37 | #include <genarch/kbrd/kbrd.h> |
37 | #include <genarch/kbrd/kbrd.h> |
38 | #include <genarch/kbrd/scanc.h> |
38 | #include <genarch/kbrd/scanc.h> |
39 | 39 | ||
40 | #include <genarch/kbrd/scanc_pl050.h> |
40 | #include <genarch/kbrd/scanc_pl050.h> |
41 | 41 | ||
42 | #include <synch/spinlock.h> |
42 | #include <synch/spinlock.h> |
43 | #include <console/chardev.h> |
43 | #include <console/chardev.h> |
44 | #include <console/console.h> |
44 | #include <console/console.h> |
45 | #include <proc/thread.h> |
45 | #include <proc/thread.h> |
46 | #include <arch.h> |
46 | #include <arch.h> |
47 | #include <macros.h> |
47 | #include <macros.h> |
48 | 48 | ||
49 | #define PRESSED_SHIFT (1 << 0) |
49 | #define PRESSED_SHIFT (1 << 0) |
50 | #define PRESSED_CAPSLOCK (1 << 1) |
50 | #define PRESSED_CAPSLOCK (1 << 1) |
51 | #define LOCKED_CAPSLOCK (1 << 0) |
51 | #define LOCKED_CAPSLOCK (1 << 0) |
52 | 52 | ||
53 | #define PL050_KEY_RELEASE 0xF0 |
53 | #define PL050_KEY_RELEASE 0xF0 |
54 | #define PL050_ESC_KEY 0xE0 |
54 | #define PL050_ESC_KEY 0xE0 |
55 | #define PL050_CAPS_SCAN_CODE 0x58 |
55 | #define PL050_CAPS_SCAN_CODE 0x58 |
56 | #define PL050_NUM_SCAN_CODE 0x77 |
56 | #define PL050_NUM_SCAN_CODE 0x77 |
57 | #define PL050_SCROLL_SCAN_CODE 0x7E |
57 | #define PL050_SCROLL_SCAN_CODE 0x7E |
58 | 58 | ||
59 | static bool is_lock_key(wchar_t); |
59 | static bool is_lock_key(wchar_t); |
60 | 60 | ||
61 | static indev_operations_t kbrd_raw_ops = { |
61 | static indev_operations_t kbrd_raw_ops = { |
62 | .poll = NULL |
62 | .poll = NULL |
63 | }; |
63 | }; |
64 | 64 | ||
65 | /** Process release of key. |
65 | /** Process release of key. |
66 | * |
66 | * |
67 | * @param sc Scancode of the key being released. |
67 | * @param sc Scancode of the key being released. |
68 | */ |
68 | */ |
69 | static void key_released(kbrd_instance_t *instance, wchar_t sc) |
69 | static void key_released(kbrd_instance_t *instance, wchar_t sc) |
70 | { |
70 | { |
71 | spinlock_lock(&instance->keylock); |
71 | spinlock_lock(&instance->keylock); |
72 | 72 | ||
73 | switch (sc) { |
73 | switch (sc) { |
74 | case SC_LSHIFT: |
74 | case SC_LSHIFT: |
75 | case SC_RSHIFT: |
75 | case SC_RSHIFT: |
76 | instance->keyflags &= ~PRESSED_SHIFT; |
76 | instance->keyflags &= ~PRESSED_SHIFT; |
77 | break; |
77 | break; |
78 | case SC_CAPSLOCK: |
78 | case SC_CAPSLOCK: |
79 | instance->keyflags &= ~PRESSED_CAPSLOCK; |
79 | instance->keyflags &= ~PRESSED_CAPSLOCK; |
80 | if (instance->lockflags & LOCKED_CAPSLOCK) |
80 | if (instance->lockflags & LOCKED_CAPSLOCK) |
81 | instance->lockflags &= ~LOCKED_CAPSLOCK; |
81 | instance->lockflags &= ~LOCKED_CAPSLOCK; |
82 | else |
82 | else |
83 | instance->lockflags |= LOCKED_CAPSLOCK; |
83 | instance->lockflags |= LOCKED_CAPSLOCK; |
84 | break; |
84 | break; |
85 | default: |
85 | default: |
86 | break; |
86 | break; |
87 | } |
87 | } |
88 | 88 | ||
89 | spinlock_unlock(&instance->keylock); |
89 | spinlock_unlock(&instance->keylock); |
90 | } |
90 | } |
91 | 91 | ||
92 | /** Process keypress. |
92 | /** Process keypress. |
93 | * |
93 | * |
94 | * @param sc Scancode of the key being pressed. |
94 | * @param sc Scancode of the key being pressed. |
95 | */ |
95 | */ |
96 | static void key_pressed(kbrd_instance_t *instance, wchar_t sc) |
96 | static void key_pressed(kbrd_instance_t *instance, wchar_t sc) |
97 | { |
97 | { |
98 | bool letter; |
98 | bool letter; |
99 | bool shift; |
99 | bool shift; |
100 | bool capslock; |
100 | bool capslock; |
101 | 101 | ||
102 | spinlock_lock(&instance->keylock); |
102 | spinlock_lock(&instance->keylock); |
103 | 103 | ||
104 | switch (sc) { |
104 | switch (sc) { |
105 | case SC_LSHIFT: |
105 | case SC_LSHIFT: |
106 | case SC_RSHIFT: |
106 | case SC_RSHIFT: |
107 | instance->keyflags |= PRESSED_SHIFT; |
107 | instance->keyflags |= PRESSED_SHIFT; |
108 | break; |
108 | break; |
109 | case SC_CAPSLOCK: |
109 | case SC_CAPSLOCK: |
110 | instance->keyflags |= PRESSED_CAPSLOCK; |
110 | instance->keyflags |= PRESSED_CAPSLOCK; |
111 | break; |
111 | break; |
112 | case SC_SCAN_ESCAPE: |
112 | case SC_SCAN_ESCAPE: |
113 | break; |
113 | break; |
114 | default: |
114 | default: |
115 | letter = islower(sc_primary_map[sc]); |
115 | letter = islower(sc_primary_map[sc]); |
116 | shift = instance->keyflags & PRESSED_SHIFT; |
116 | shift = instance->keyflags & PRESSED_SHIFT; |
117 | capslock = (instance->keyflags & PRESSED_CAPSLOCK) || |
117 | capslock = (instance->keyflags & PRESSED_CAPSLOCK) || |
118 | (instance->lockflags & LOCKED_CAPSLOCK); |
118 | (instance->lockflags & LOCKED_CAPSLOCK); |
119 | 119 | ||
120 | if ((letter) && (capslock)) |
120 | if ((letter) && (capslock)) |
121 | shift = !shift; |
121 | shift = !shift; |
122 | 122 | ||
123 | if (shift) |
123 | if (shift) |
124 | indev_push_character(instance->sink, sc_secondary_map[sc]); |
124 | indev_push_character(instance->sink, sc_secondary_map[sc]); |
125 | else |
125 | else |
126 | indev_push_character(instance->sink, sc_primary_map[sc]); |
126 | indev_push_character(instance->sink, sc_primary_map[sc]); |
127 | break; |
127 | break; |
128 | } |
128 | } |
129 | 129 | ||
130 | spinlock_unlock(&instance->keylock); |
130 | spinlock_unlock(&instance->keylock); |
131 | } |
131 | } |
132 | 132 | ||
133 | static void kkbrd(void *arg) |
133 | static void kkbrd(void *arg) |
134 | { |
134 | { |
135 | static int key_released_flag = 0; |
135 | static int key_released_flag = 0; |
136 | static int is_locked = 0; |
136 | static int is_locked = 0; |
137 | kbrd_instance_t *instance = (kbrd_instance_t *) arg; |
137 | kbrd_instance_t *instance = (kbrd_instance_t *) arg; |
138 | 138 | ||
139 | while (true) { |
139 | while (true) { |
140 | wchar_t sc = indev_pop_character(&instance->raw); |
140 | wchar_t sc = indev_pop_character(&instance->raw); |
141 | 141 | ||
142 | if (sc == PL050_KEY_RELEASE) { |
142 | if (sc == PL050_KEY_RELEASE) { |
143 | key_released_flag = 1; |
143 | key_released_flag = 1; |
144 | } else { |
144 | } else { |
145 | if (key_released_flag) { |
145 | if (key_released_flag) { |
146 | key_released_flag = 0; |
146 | key_released_flag = 0; |
147 | if (is_lock_key(sc)) { |
147 | if (is_lock_key(sc)) { |
148 | if (!is_locked) { |
148 | if (!is_locked) { |
149 | is_locked = 1; |
149 | is_locked = 1; |
150 | } else { |
150 | } else { |
151 | is_locked = 0; |
151 | is_locked = 0; |
152 | continue; |
152 | continue; |
153 | } |
153 | } |
154 | } |
154 | } |
155 | key_released(instance, sc); |
155 | key_released(instance, sc); |
156 | 156 | ||
157 | } else { |
157 | } else { |
158 | if (is_lock_key(sc) && is_locked) |
158 | if (is_lock_key(sc) && is_locked) |
159 | continue; |
159 | continue; |
160 | key_pressed(instance, sc); |
160 | key_pressed(instance, sc); |
161 | } |
161 | } |
162 | } |
162 | } |
163 | 163 | ||
164 | } |
164 | } |
165 | } |
165 | } |
166 | 166 | ||
167 | kbrd_instance_t *kbrd_init(void) |
167 | kbrd_instance_t *kbrd_init(void) |
168 | { |
168 | { |
169 | kbrd_instance_t *instance |
169 | kbrd_instance_t *instance |
170 | = malloc(sizeof(kbrd_instance_t), FRAME_ATOMIC); |
170 | = malloc(sizeof(kbrd_instance_t), FRAME_ATOMIC); |
171 | if (instance) { |
171 | if (instance) { |
172 | instance->thread |
172 | instance->thread |
173 | = thread_create(kkbrd, (void *) instance, TASK, 0, "kkbrd", false); |
173 | = thread_create(kkbrd, (void *) instance, TASK, 0, "kkbrd", false); |
174 | 174 | ||
175 | if (!instance->thread) { |
175 | if (!instance->thread) { |
176 | free(instance); |
176 | free(instance); |
177 | return NULL; |
177 | return NULL; |
178 | } |
178 | } |
179 | 179 | ||
180 | instance->sink = NULL; |
180 | instance->sink = NULL; |
181 | indev_initialize("kbrd", &instance->raw, &kbrd_raw_ops); |
181 | indev_initialize("kbrd", &instance->raw, &kbrd_raw_ops); |
182 | 182 | ||
183 | spinlock_initialize(&instance->keylock, "instance_keylock"); |
183 | spinlock_initialize(&instance->keylock, "instance_keylock"); |
184 | instance->keyflags = 0; |
184 | instance->keyflags = 0; |
185 | instance->lockflags = 0; |
185 | instance->lockflags = 0; |
186 | } |
186 | } |
187 | 187 | ||
188 | return instance; |
188 | return instance; |
189 | } |
189 | } |
190 | 190 | ||
191 | indev_t *kbrd_wire(kbrd_instance_t *instance, indev_t *sink) |
191 | indev_t *kbrd_wire(kbrd_instance_t *instance, indev_t *sink) |
192 | { |
192 | { |
193 | ASSERT(instance); |
193 | ASSERT(instance); |
194 | ASSERT(sink); |
194 | ASSERT(sink); |
195 | 195 | ||
196 | instance->sink = sink; |
196 | instance->sink = sink; |
197 | thread_ready(instance->thread); |
197 | thread_ready(instance->thread); |
198 | 198 | ||
199 | return &instance->raw; |
199 | return &instance->raw; |
200 | } |
200 | } |
201 | 201 | ||
202 | static bool is_lock_key(wchar_t sc) |
202 | static bool is_lock_key(wchar_t sc) |
203 | { |
203 | { |
204 | return ((sc == PL050_CAPS_SCAN_CODE) || (sc == PL050_NUM_SCAN_CODE) || |
204 | return ((sc == PL050_CAPS_SCAN_CODE) || (sc == PL050_NUM_SCAN_CODE) || |
205 | (sc == PL050_SCROLL_SCAN_CODE)); |
205 | (sc == PL050_SCROLL_SCAN_CODE)); |
206 | } |
206 | } |
207 | 207 | ||
208 | /** @} |
208 | /** @} |
209 | */ |
209 | */ |
210 | 210 |