4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 * Generic Keyboard Support: Polled I/O support for kbtrans-supported keyboards.
33 #define KEYMAP_SIZE_VARIABLE
35 #include <sys/types.h>
36 #include <sys/stream.h>
39 #include <sys/vuid_event.h>
40 #include <sys/consdev.h>
41 #include <sys/kbtrans.h>
42 #include "kbtrans_lower.h"
43 #include "kbtrans_streams.h"
46 * Internal Function Prototypes
48 static void kbtrans_polled_pressed(struct kbtrans
*, uint_t
, kbtrans_key_t
,
50 static void kbtrans_polled_released(struct kbtrans
*, kbtrans_key_t
);
51 static void kbtrans_polled_setled(struct kbtrans
*);
52 static void kbtrans_polled_setup_repeat(struct kbtrans
*, uint_t
,
54 static void kbtrans_polled_cancel_repeat(struct kbtrans
*);
57 * Functions to be called when a key is translated during polled
60 struct keyboard_callback kbtrans_polled_callbacks
= {
61 NULL
, /* keypressed_raw */
62 NULL
, /* keyreleased_raw */
63 kbtrans_polled_pressed
, /* keypressed */
64 kbtrans_polled_released
, /* keyreleased */
65 kbtrans_polled_setup_repeat
, /* setup_repeat */
66 kbtrans_polled_cancel_repeat
, /* cancel_repeat */
67 kbtrans_polled_setled
, /* setled */
72 * Return B_TRUE if character is pending, else return B_FALSE
75 kbtrans_ischar(struct kbtrans
*upper
)
77 struct kbtrans_callbacks
*cb
;
78 struct kbtrans_hardware
*hw
;
83 * If we've still got input pending, say so.
85 if (*upper
->kbtrans_polled_pending_chars
!= '\0') {
90 * Reset to an empty buffer.
92 upper
->kbtrans_polled_buf
[0] = '\0';
93 upper
->kbtrans_polled_pending_chars
= upper
->kbtrans_polled_buf
;
95 cb
= upper
->kbtrans_streams_hw_callbacks
;
96 hw
= upper
->kbtrans_streams_hw
;
99 * Process scancodes until either we have input ready
100 * or we run out of scancodes.
102 while (cb
->kbtrans_polled_keycheck(hw
, &key
, &state
)) {
103 kbtrans_processkey(&upper
->kbtrans_lower
,
104 &kbtrans_polled_callbacks
, key
, state
);
106 * If that generated any input, we're ready.
108 if (*upper
->kbtrans_polled_pending_chars
!= '\0') {
121 kbtrans_getchar(struct kbtrans
*upper
)
123 while (!kbtrans_ischar(upper
))
126 return (*upper
->kbtrans_polled_pending_chars
++);
130 kbtrans_polled_putcode(struct kbtrans
*upper
, char code
)
135 * NB: KBTRANS_POLLED_BUF_SIZE is one smaller than
136 * the size of the buffer, to allow for a trailing
139 for (i
= 0; i
< KBTRANS_POLLED_BUF_SIZE
; i
++) {
140 if (upper
->kbtrans_polled_buf
[i
] == '\0') {
141 upper
->kbtrans_polled_buf
[i
] = code
;
142 upper
->kbtrans_polled_buf
[i
+1] = '\0';
146 DPRINTF(PRINT_L2
, PRINT_MASK_PACKET
,
147 (upper
, "kbtrans_polled_pressed: "
148 "buffer overflow, character 0x%x discarded\n", code
));
150 * Didn't fit, throw it on the floor.
155 * kbtrans_polled_pressed:
156 * This function is called when we are in polled mode and a key is
157 * pressed. The key is put into the kbtrans_polled_buf so that it
158 * can be picked up later by kbtrans_ischar()
162 kbtrans_polled_pressed(
163 struct kbtrans
*upper
,
168 struct kbtrans_lower
*lower
= &upper
->kbtrans_lower
;
172 * Based on the type of key, we may need to do some ASCII
173 * specific post processing.
181 * There is no ascii equivalent. We will ignore these
188 * These will no doubt only cause problems. Ignore them.
195 * These are the multi byte keys (Home, Up, Down ...)
197 cp
= &lower
->kbtrans_keystringtab
[entry
& 0x0F][0];
200 * Copy the string from the keystringtable, and send it
201 * upstream a character at a time.
203 while (*cp
!= '\0') {
204 kbtrans_polled_putcode(upper
, *cp
);
212 * These are the keys on the keypad. Look up the
213 * answer in the kb_numlock_table and send it upstream.
215 kbtrans_polled_putcode(upper
,
216 lower
->kbtrans_numlock_table
[entry
&0x1F]);
220 case 0: /* normal character */
223 * Send the byte upstream.
225 kbtrans_polled_putcode(upper
, (char)entry
);
231 * kbtrans_polled_released:
232 * This function is called when a key is released. Nothing is
237 kbtrans_polled_released(struct kbtrans
*upper
, kbtrans_key_t key
)
239 /* Nothing for now */
243 * kbtrans_polled_setled:
244 * This function is called to set the LEDs.
247 kbtrans_polled_setled(struct kbtrans
*upper
)
249 struct kbtrans_callbacks
*cb
;
250 struct kbtrans_hardware
*hw
;
252 cb
= upper
->kbtrans_streams_hw_callbacks
;
253 hw
= upper
->kbtrans_streams_hw
;
255 cb
->kbtrans_polled_setled(hw
, upper
->kbtrans_lower
.kbtrans_led_state
);
259 * kbtrans_polled_setup_repeat:
260 * Function to be called in order to handle a repeating key.
265 kbtrans_polled_setup_repeat(
266 struct kbtrans
*upper
,
270 /* Nothing for now */
274 * kbtrans_polled_cancel_repeat:
275 * Function to be called to cancel a repeating key,
276 * so that we don't end up with an autorepeating key
277 * on the stream because its release was handled by the
281 kbtrans_polled_cancel_repeat(struct kbtrans
*upper
)
284 * Streams code will time out and will discard the
287 upper
->kbtrans_lower
.kbtrans_repeatkey
= 0;