arch/mips32/src/kbd.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2006 Josef Cejka
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 
00036 #include <arch/kbd.h>
00037 #include <ipc/ipc.h>
00038 #include <sysinfo.h>
00039 #include <kbd.h>
00040 #include <keys.h>
00041 
00042 #define MSIM_KEY_F1 0x504f1bL
00043 #define MSIM_KEY_F2 0x514f1bL
00044 #define MSIM_KEY_F3 0x524f1bL
00045 #define MSIM_KEY_F4 0x534f1bL
00046 #define MSIM_KEY_F5 0x35315b1bL
00047 #define MSIM_KEY_F6 0x37315b1bL
00048 #define MSIM_KEY_F7 0x38315b1bL
00049 #define MSIM_KEY_F8 0x39315b1bL
00050 #define MSIM_KEY_F9 0x30325b1bL
00051 #define MSIM_KEY_F10 0x31325b1bL
00052 #define MSIM_KEY_F11 0x33325b1bL
00053 #define MSIM_KEY_F12 0x34325b1bL
00054 
00055 
00056 #define GXEMUL_KEY_F1 0x504f5b1bL
00057 #define GXEMUL_KEY_F2 0x514f5b1bL
00058 #define GXEMUL_KEY_F3 0x524f5b1bL
00059 #define GXEMUL_KEY_F4 0x534f5b1bL
00060 #define GXEMUL_KEY_F5 0x35315b1bL
00061 #define GXEMUL_KEY_F6 0x37315b1bL
00062 #define GXEMUL_KEY_F7 0x38315b1bL
00063 #define GXEMUL_KEY_F8 0x39315b1bL
00064 #define GXEMUL_KEY_F9 0x38325b1bL
00065 #define GXEMUL_KEY_F10 0x39325b1bL
00066 #define GXEMUL_KEY_F11 0x33325b1bL
00067 #define GXEMUL_KEY_F12 0x34325b1bL
00068 
00069 
00070 #define FUNCTION_KEYS 0x100
00071 
00072 
00073 irq_cmd_t msim_cmds[1] = {
00074         { CMD_MEM_READ_1, (void *)0xB0000000, 0, 2 }
00075 };
00076 
00077 irq_code_t msim_kbd = {
00078         1,
00079         msim_cmds
00080 };
00081 
00082 static int msim,gxemul;
00083 static int fb_fb;
00084 
00085 
00086 int kbd_arch_init(void)
00087 {
00088         fb_fb=sysinfo_value("fb.kind")==1;
00089         ipc_register_irq(2, &msim_kbd);
00090         return 0;
00091 }
00092 
00093 
00094 /*
00095 //*
00096 //* Please preserve this code (it can be used to determine scancodes)
00097 //*
00098 int to_hex(int v) 
00099 {
00100         return "0123456789ABCDEF"[v];
00101 }
00102 */
00103 
00104 static int kbd_arch_process_no_fb(keybuffer_t *keybuffer, int scan_code)
00105 {
00106 
00107         static unsigned long buf=0;
00108         static int count=0;     
00109 
00110 
00111         /* Please preserve this code (it can be used to determine scancodes)
00112         
00113         keybuffer_push(keybuffer, to_hex((scan_code>>4)&0xf));
00114         keybuffer_push(keybuffer, to_hex(scan_code&0xf));
00115         keybuffer_push(keybuffer, ' ');
00116         keybuffer_push(keybuffer, ' ');
00117         
00118         return 1;
00119         */
00120         
00121         if(scan_code==0x7e)
00122         {
00123                 switch (buf){
00124                         case MSIM_KEY_F5:
00125                                 keybuffer_push(keybuffer,FUNCTION_KEYS | 5 );
00126                                 buf=count=0;
00127                                 return 1;
00128                         case MSIM_KEY_F6:
00129                                 keybuffer_push(keybuffer,FUNCTION_KEYS | 6 );
00130                                 buf=count=0;
00131                                 return 1;
00132                         case MSIM_KEY_F7:
00133                                 keybuffer_push(keybuffer,FUNCTION_KEYS | 7 );
00134                                 buf=count=0;
00135                                 return 1;
00136                         case MSIM_KEY_F8:
00137                                 keybuffer_push(keybuffer,FUNCTION_KEYS | 8 );
00138                                 buf=count=0;
00139                                 return 1;
00140 
00141                         case MSIM_KEY_F9:
00142                                 keybuffer_push(keybuffer,FUNCTION_KEYS | 9 );
00143                                 buf=count=0;
00144                                 return 1;
00145                         case MSIM_KEY_F10:
00146                                 keybuffer_push(keybuffer,FUNCTION_KEYS | 10 );
00147                                 buf=count=0;
00148                                 return 1;
00149 
00150                         case MSIM_KEY_F11:
00151                                 keybuffer_push(keybuffer,FUNCTION_KEYS | 11 );
00152                                 buf=count=0;
00153                                 return 1;
00154                         case MSIM_KEY_F12:
00155                                 keybuffer_push(keybuffer,FUNCTION_KEYS | 12 );
00156                                 buf=count=0;
00157                                 return 1;
00158                         default:
00159                                 keybuffer_push(keybuffer, buf & 0xff );
00160                                 keybuffer_push(keybuffer, (buf >> 8) &0xff );
00161                                 keybuffer_push(keybuffer, (buf >> 16) &0xff );
00162                                 keybuffer_push(keybuffer, (buf >> 24) &0xff );
00163                                 keybuffer_push(keybuffer, scan_code );
00164                                 buf=count=0;
00165                                 return 1;
00166         
00167                 }
00168         }
00169 
00170         buf|=((unsigned long) scan_code)<<(8*(count++));
00171         
00172         
00173         if((buf & 0xff)!= (MSIM_KEY_F1 & 0xff)) {
00174 
00175                 keybuffer_push(keybuffer,buf );
00176                 buf=count=0;
00177                 return 1;
00178         }
00179 
00180         if ( count <= 1 ) 
00181                 return 1;
00182 
00183         if(    (buf & 0xffff) != (MSIM_KEY_F1 & 0xffff) 
00184             && (buf & 0xffff) != (MSIM_KEY_F5 & 0xffff) ) {
00185 
00186                 keybuffer_push(keybuffer, buf & 0xff );
00187                 keybuffer_push(keybuffer, (buf >> 8) &0xff );
00188                 buf=count=0;
00189                 return 1;
00190         }
00191 
00192         if ( count <= 2) 
00193                 return 1;
00194 
00195         switch (buf){
00196                 case MSIM_KEY_F1:
00197                         keybuffer_push(keybuffer,FUNCTION_KEYS | 1 );
00198                         buf=count=0;
00199                         return 1;
00200                 case MSIM_KEY_F2:
00201                         keybuffer_push(keybuffer,FUNCTION_KEYS | 2 );
00202                         buf=count=0;
00203                         return 1;
00204                 case MSIM_KEY_F3:
00205                         keybuffer_push(keybuffer,FUNCTION_KEYS | 3 );
00206                         buf=count=0;
00207                         return 1;
00208                 case MSIM_KEY_F4:
00209                         keybuffer_push(keybuffer,FUNCTION_KEYS | 4 );
00210                         buf=count=0;
00211                         return 1;
00212         }
00213 
00214 
00215         if(    (buf & 0xffffff) != (MSIM_KEY_F5 & 0xffffff)
00216             && (buf & 0xffffff) != (MSIM_KEY_F9 & 0xffffff) ) {
00217 
00218                 keybuffer_push(keybuffer, buf & 0xff );
00219                 keybuffer_push(keybuffer, (buf >> 8) &0xff );
00220                 keybuffer_push(keybuffer, (buf >> 16) &0xff );
00221                 buf=count=0;
00222                 return 1;
00223         }
00224 
00225         if ( count <= 3 ) 
00226                 return 1;
00227         
00228 
00229         
00230         
00231         switch (buf){
00232                 case MSIM_KEY_F5:
00233                 case MSIM_KEY_F6:
00234                 case MSIM_KEY_F7:
00235                 case MSIM_KEY_F8:
00236                 case MSIM_KEY_F9:
00237                 case MSIM_KEY_F10:
00238                 case MSIM_KEY_F11:
00239                 case MSIM_KEY_F12:
00240                         return 1;
00241                 default:
00242                         keybuffer_push(keybuffer, buf & 0xff );
00243                         keybuffer_push(keybuffer, (buf >> 8) &0xff );
00244                         keybuffer_push(keybuffer, (buf >> 16) &0xff );
00245                         keybuffer_push(keybuffer, (buf >> 24) &0xff );
00246                         buf=count=0;
00247                         return 1;
00248                 
00249                 }
00250         return 1;
00251 }
00252 
00253 
00254 
00255 static int kbd_arch_process_fb(keybuffer_t *keybuffer, int scan_code)
00256 {
00257 
00258         static unsigned long buf=0;
00259         static int count=0;     
00260 
00261 
00262         /* Please preserve this code (it can be used to determine scancodes)
00263         
00264         keybuffer_push(keybuffer, to_hex((scan_code>>4)&0xf));
00265         keybuffer_push(keybuffer, to_hex(scan_code&0xf));
00266         keybuffer_push(keybuffer, ' ');
00267         keybuffer_push(keybuffer, ' ');
00268         
00269         return 1;
00270         */
00271         
00272         if ( scan_code == '\r' )
00273                 scan_code = '\n' ;
00274         
00275         buf|=((unsigned long) scan_code)<<(8*(count++));
00276         
00277         
00278         if((buf & 0xff)!= (GXEMUL_KEY_F1 & 0xff)) {
00279 
00280                 keybuffer_push(keybuffer,buf );
00281                 buf=count=0;
00282                 return 1;
00283         }
00284 
00285         if ( count <= 1 ) 
00286                 return 1;
00287 
00288         if(    (buf & 0xffff) != (GXEMUL_KEY_F1 & 0xffff)  ) {
00289 
00290                 keybuffer_push(keybuffer, buf & 0xff );
00291                 keybuffer_push(keybuffer, (buf >> 8) &0xff );
00292                 buf=count=0;
00293                 return 1;
00294         }
00295 
00296         if ( count <= 2) 
00297                 return 1;
00298 
00299 
00300         if(    (buf & 0xffffff) != (GXEMUL_KEY_F1 & 0xffffff)
00301             && (buf & 0xffffff) != (GXEMUL_KEY_F5 & 0xffffff)
00302             && (buf & 0xffffff) != (GXEMUL_KEY_F9 & 0xffffff) ) {
00303 
00304                 keybuffer_push(keybuffer, buf & 0xff );
00305                 keybuffer_push(keybuffer, (buf >> 8) &0xff );
00306                 keybuffer_push(keybuffer, (buf >> 16) &0xff );
00307                 buf=count=0;
00308                 return 1;
00309         }
00310 
00311         if ( count <= 3 ) 
00312                 return 1;
00313         
00314 
00315         switch (buf){
00316 
00317                 case GXEMUL_KEY_F1:
00318                         keybuffer_push(keybuffer,FUNCTION_KEYS | 1 );
00319                         buf=count=0;
00320                         return 1;
00321                 case GXEMUL_KEY_F2:
00322                         keybuffer_push(keybuffer,FUNCTION_KEYS | 2 );
00323                         buf=count=0;
00324                         return 1;
00325                 case GXEMUL_KEY_F3:
00326                         keybuffer_push(keybuffer,FUNCTION_KEYS | 3 );
00327                         buf=count=0;
00328                         return 1;
00329                 case GXEMUL_KEY_F4:
00330                         keybuffer_push(keybuffer,FUNCTION_KEYS | 4 );
00331                         buf=count=0;
00332                         return 1;
00333                 case GXEMUL_KEY_F5:
00334                         keybuffer_push(keybuffer,FUNCTION_KEYS | 5 );
00335                         buf=count=0;
00336                         return 1;
00337                 case GXEMUL_KEY_F6:
00338                         keybuffer_push(keybuffer,FUNCTION_KEYS | 6 );
00339                         buf=count=0;
00340                         return 1;
00341                 case GXEMUL_KEY_F7:
00342                         keybuffer_push(keybuffer,FUNCTION_KEYS | 7 );
00343                         buf=count=0;
00344                         return 1;
00345                 case GXEMUL_KEY_F8:
00346                         keybuffer_push(keybuffer,FUNCTION_KEYS | 8 );
00347                         buf=count=0;
00348                         return 1;
00349                 case GXEMUL_KEY_F9:
00350                         keybuffer_push(keybuffer,FUNCTION_KEYS | 9 );
00351                         buf=count=0;
00352                         return 1;
00353                 case GXEMUL_KEY_F10:
00354                         keybuffer_push(keybuffer,FUNCTION_KEYS | 10 );
00355                         buf=count=0;
00356                         return 1;
00357                 case GXEMUL_KEY_F11:
00358                         keybuffer_push(keybuffer,FUNCTION_KEYS | 11 );
00359                         buf=count=0;
00360                         return 1;
00361                 case GXEMUL_KEY_F12:
00362                         keybuffer_push(keybuffer,FUNCTION_KEYS | 12 );
00363                         buf=count=0;
00364                         return 1;
00365 
00366                 default:
00367                         keybuffer_push(keybuffer, buf & 0xff );
00368                         keybuffer_push(keybuffer, (buf >> 8) &0xff );
00369                         keybuffer_push(keybuffer, (buf >> 16) &0xff );
00370                         keybuffer_push(keybuffer, (buf >> 24) &0xff );
00371                         buf=count=0;
00372                         return 1;
00373                 
00374                 }
00375         return 1;
00376 }
00377 
00378 int kbd_arch_process(keybuffer_t *keybuffer, ipc_call_t *call)
00379 {
00380         int scan_code = IPC_GET_ARG2(*call);
00381         static int esc_count=0;
00382 
00383         
00384         if ( scan_code == 0x1b ) {
00385                 esc_count++;
00386                 if ( esc_count == 3 ) {
00387                         __SYSCALL0(SYS_DEBUG_ENABLE_CONSOLE);
00388                 }       
00389         } else {
00390                 esc_count=0;
00391         }
00392 
00393         if(fb_fb) return kbd_arch_process_fb(keybuffer, scan_code);
00394         return kbd_arch_process_no_fb(keybuffer, scan_code);
00395 
00396         return 0;
00397 }

Generated on Sun Jun 18 18:05:37 2006 for HelenOS Userspace (mips32) by  doxygen 1.4.6