arch/ppc32/src/kbd.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2006 Martin Decky
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * - Redistributions of source code must retain the above copyright
00010  *   notice, this list of conditions and the following disclaimer.
00011  * - Redistributions in binary form must reproduce the above copyright
00012  *   notice, this list of conditions and the following disclaimer in the
00013  *   documentation and/or other materials provided with the distribution.
00014  * - The name of the author may not be used to endorse or promote products
00015  *   derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00019  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00020  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00022  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  */
00028 
00037 #include <arch/kbd.h>
00038 #include <ipc/ipc.h>
00039 #include <sysinfo.h>
00040 #include <kbd.h>
00041 #include <keys.h>
00042 
00043 irq_cmd_t cuda_cmds[1] = {
00044         { CMD_PPC32_GETCHAR, 0, 0, 2 }
00045 };
00046 
00047 irq_code_t cuda_kbd = {
00048         1,
00049         cuda_cmds
00050 };
00051 
00052 
00053 #define SPECIAL         255
00054 #define FUNCTION_KEYS 0x100
00055 
00056 
00057 static int lchars[0x80] = {
00058         'a',
00059         's',
00060         'd',
00061         'f',
00062         'h',
00063         'g',
00064         'z',
00065         'x',
00066         'c',
00067         'v', 
00068         SPECIAL,
00069         'b',
00070         'q',
00071         'w',
00072         'e',
00073         'r',
00074         'y',
00075         't',
00076         '1',
00077         '2',
00078         '3',
00079         '4',
00080         '6',
00081         '5',
00082         '=',
00083         '9',
00084         '7',
00085         '-',
00086         '8',
00087         '0',
00088         ']',
00089         'o',
00090         'u',
00091         '[',
00092         'i', 
00093         'p',
00094         '\n',                 /* Enter */
00095         'l',
00096         'j',
00097         '\'',
00098         'k',
00099         ';',
00100         '\\',
00101         ',',
00102         '/',
00103         'n',
00104         'm',
00105         '.',
00106         '\t',                 /* Tab */
00107         ' ',
00108         '`',
00109         '\b',                 /* Backspace */
00110         SPECIAL,
00111         SPECIAL,              /* Escape */
00112         SPECIAL,              /* Ctrl */
00113         SPECIAL,              /* Alt */
00114         SPECIAL,              /* Shift */
00115         SPECIAL,              /* Caps-Lock */
00116         SPECIAL,              /* RAlt */
00117         SPECIAL,              /* Left */
00118         SPECIAL,              /* Right */
00119         SPECIAL,              /* Down */
00120         SPECIAL,              /* Up */
00121         SPECIAL, 
00122         SPECIAL,
00123         '.',                  /* Keypad . */
00124         SPECIAL, 
00125         '*',                  /* Keypad * */
00126         SPECIAL,
00127         '+',                  /* Keypad + */
00128         SPECIAL,
00129         SPECIAL,              /* NumLock */
00130         SPECIAL,
00131         SPECIAL,
00132         SPECIAL,
00133         '/',                  /* Keypad / */
00134         '\n',                 /* Keypad Enter */
00135         SPECIAL,
00136         '-',                  /* Keypad - */
00137         SPECIAL,
00138         SPECIAL,
00139         SPECIAL,
00140         '0',                  /* Keypad 0 */
00141         '1',                  /* Keypad 1 */
00142         '2',                  /* Keypad 2 */
00143         '3',                  /* Keypad 3 */
00144         '4',                  /* Keypad 4 */
00145         '5',                  /* Keypad 5 */
00146         '6',                  /* Keypad 6 */
00147         '7',                  /* Keypad 7 */
00148         SPECIAL,
00149         '8',                  /* Keypad 8 */
00150         '9',                  /* Keypad 9 */
00151         SPECIAL,
00152         SPECIAL,
00153         SPECIAL,
00154         (FUNCTION_KEYS | 5),  /* F5 */
00155         (FUNCTION_KEYS | 6),  /* F6 */
00156         (FUNCTION_KEYS | 7),  /* F7 */
00157         (FUNCTION_KEYS | 3),  /* F3 */
00158         (FUNCTION_KEYS | 8),  /* F8 */
00159         (FUNCTION_KEYS | 9),  /* F9 */
00160         SPECIAL,
00161         (FUNCTION_KEYS | 11), /* F11 */
00162         SPECIAL,
00163         (FUNCTION_KEYS | 13), /* F13 */
00164         SPECIAL,
00165         SPECIAL,              /* ScrollLock */
00166         SPECIAL,
00167         (FUNCTION_KEYS | 10), /* F10 */
00168         SPECIAL,
00169         (FUNCTION_KEYS | 12), /* F12 */
00170         SPECIAL,
00171         SPECIAL,              /* Pause */
00172         SPECIAL,              /* Insert */
00173         SPECIAL,              /* Home */
00174         SPECIAL,              /* PageUp */
00175         SPECIAL,              /* Delete */
00176         (FUNCTION_KEYS | 4),  /* F4 */
00177         SPECIAL,              /* End */
00178         (FUNCTION_KEYS | 2),  /* F2 */
00179         SPECIAL,              /* PageDown */
00180         (FUNCTION_KEYS | 1)   /* F1 */
00181 };
00182 
00183 
00184 int kbd_arch_init(void)
00185 {
00186         return ipc_register_irq(sysinfo_value("cuda.irq"), &cuda_kbd);
00187 }
00188 
00189 
00190 int kbd_arch_process(keybuffer_t *keybuffer, ipc_call_t *call) 
00191 {
00192         int param = IPC_GET_ARG2(*call);
00193 
00194         if (param != -1) {
00195                 uint8_t scancode = (uint8_t) param;
00196         
00197                 if ((scancode & 0x80) != 0x80) {
00198                         int key = lchars[scancode & 0x7f];
00199                         
00200                         if (key != SPECIAL)
00201                                 keybuffer_push(keybuffer, key);
00202                 }
00203         }
00204         
00205         return 1;
00206 }
00207 

Generated on Sun Jun 18 18:11:00 2006 for HelenOS Userspace (ppc32) by  doxygen 1.4.6