source: mainline/kernel/genarch/src/kbrd/kbrd_at.c@ b272c67a

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since b272c67a was 5012203, checked in by Jakub Jermar <jakub@…>, 10 years ago

IntegratorCP: switch to using the PC/AT (set 2) scancodes

This is consistent with a change introduced in QEMU 2.6.0. It appears
that the previously provided and then removed PL050 scan codes were
actually PC/AT set 2 scancodes.

  • Property mode set to 100644
File size: 5.0 KB
Line 
1/*
2 * Copyright (c) 2009 Vineeth Pillai
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
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
15 * derived from this software without specific prior written permission.
16 *
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
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
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
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
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup genarch
30 * @{
31 */
32/**
33 * @file
34 * @brief PC/AT Keyboard processing.
35 */
36
37#include <genarch/kbrd/kbrd.h>
38#include <genarch/kbrd/scanc.h>
39
40#include <genarch/kbrd/scanc_at.h>
41
42#include <synch/spinlock.h>
43#include <console/chardev.h>
44#include <console/console.h>
45#include <proc/thread.h>
46#include <arch.h>
47#include <macros.h>
48
49#define PRESSED_SHIFT (1 << 0)
50#define PRESSED_CAPSLOCK (1 << 1)
51#define LOCKED_CAPSLOCK (1 << 0)
52
53#define AT_KEY_RELEASE 0xF0
54#define AT_ESC_KEY 0xE0
55#define AT_CAPS_SCAN_CODE 0x58
56#define AT_NUM_SCAN_CODE 0x77
57#define AT_SCROLL_SCAN_CODE 0x7E
58
59static bool is_lock_key(wchar_t);
60
61static indev_operations_t kbrd_raw_ops = {
62 .poll = NULL
63};
64
65/** Process release of key.
66 *
67 * @param sc Scancode of the key being released.
68 */
69static void key_released(kbrd_instance_t *instance, wchar_t sc)
70{
71 spinlock_lock(&instance->keylock);
72
73 switch (sc) {
74 case SC_LSHIFT:
75 case SC_RSHIFT:
76 instance->keyflags &= ~PRESSED_SHIFT;
77 break;
78 case SC_CAPSLOCK:
79 instance->keyflags &= ~PRESSED_CAPSLOCK;
80 if (instance->lockflags & LOCKED_CAPSLOCK)
81 instance->lockflags &= ~LOCKED_CAPSLOCK;
82 else
83 instance->lockflags |= LOCKED_CAPSLOCK;
84 break;
85 default:
86 break;
87 }
88
89 spinlock_unlock(&instance->keylock);
90}
91
92/** Process keypress.
93 *
94 * @param sc Scancode of the key being pressed.
95 */
96static void key_pressed(kbrd_instance_t *instance, wchar_t sc)
97{
98 bool letter;
99 bool shift;
100 bool capslock;
101
102 spinlock_lock(&instance->keylock);
103
104 switch (sc) {
105 case SC_LSHIFT:
106 case SC_RSHIFT:
107 instance->keyflags |= PRESSED_SHIFT;
108 break;
109 case SC_CAPSLOCK:
110 instance->keyflags |= PRESSED_CAPSLOCK;
111 break;
112 case SC_SCAN_ESCAPE:
113 break;
114 default:
115 letter = islower(sc_primary_map[sc]);
116 shift = instance->keyflags & PRESSED_SHIFT;
117 capslock = (instance->keyflags & PRESSED_CAPSLOCK) ||
118 (instance->lockflags & LOCKED_CAPSLOCK);
119
120 if ((letter) && (capslock))
121 shift = !shift;
122
123 if (shift)
124 indev_push_character(instance->sink, sc_secondary_map[sc]);
125 else
126 indev_push_character(instance->sink, sc_primary_map[sc]);
127 break;
128 }
129
130 spinlock_unlock(&instance->keylock);
131}
132
133static void kkbrd(void *arg)
134{
135 static int key_released_flag = 0;
136 static int is_locked = 0;
137 kbrd_instance_t *instance = (kbrd_instance_t *) arg;
138
139 while (true) {
140 wchar_t sc = indev_pop_character(&instance->raw);
141
142 if (sc == AT_KEY_RELEASE) {
143 key_released_flag = 1;
144 } else {
145 if (key_released_flag) {
146 key_released_flag = 0;
147 if (is_lock_key(sc)) {
148 if (!is_locked) {
149 is_locked = 1;
150 } else {
151 is_locked = 0;
152 continue;
153 }
154 }
155 key_released(instance, sc);
156
157 } else {
158 if (is_lock_key(sc) && is_locked)
159 continue;
160 key_pressed(instance, sc);
161 }
162 }
163
164 }
165}
166
167kbrd_instance_t *kbrd_init(void)
168{
169 kbrd_instance_t *instance;
170
171 instance = malloc(sizeof(kbrd_instance_t), FRAME_ATOMIC);
172 if (instance) {
173 instance->thread = thread_create(kkbrd, (void *) instance, TASK, 0,
174 "kkbrd");
175
176 if (!instance->thread) {
177 free(instance);
178 return NULL;
179 }
180
181 instance->sink = NULL;
182 indev_initialize("kbrd", &instance->raw, &kbrd_raw_ops);
183
184 spinlock_initialize(&instance->keylock, "kbrd_at.instance.keylock");
185 instance->keyflags = 0;
186 instance->lockflags = 0;
187 }
188
189 return instance;
190}
191
192indev_t *kbrd_wire(kbrd_instance_t *instance, indev_t *sink)
193{
194 ASSERT(instance);
195 ASSERT(sink);
196
197 instance->sink = sink;
198 thread_ready(instance->thread);
199
200 return &instance->raw;
201}
202
203static bool is_lock_key(wchar_t sc)
204{
205 return ((sc == AT_CAPS_SCAN_CODE) || (sc == AT_NUM_SCAN_CODE) ||
206 (sc == AT_SCROLL_SCAN_CODE));
207}
208
209/** @}
210 */
Note: See TracBrowser for help on using the repository browser.