Subversion Repositories HelenOS-historic

Rev

Rev 1451 | Rev 1632 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Copyright (C) 2006 Josef Cejka
  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. #include <arch/kbd.h>
  30. #include <ipc/ipc.h>
  31.  
  32.  
  33. #define KEY_F1 0x504f1bL
  34. #define KEY_F2 0x514f1bL
  35. #define KEY_F3 0x524f1bL
  36. #define KEY_F4 0x534f1bL
  37. #define KEY_F5 0x35315b1bL
  38. #define KEY_F6 0x37315b1bL
  39. #define KEY_F7 0x38315b1bL
  40. #define KEY_F8 0x39315b1bL
  41. #define KEY_F9 0x30325b1bL
  42. #define KEY_F10 0x31325b1bL
  43. #define KEY_F11 0x33325b1bL
  44. #define KEY_F12 0x34325b1bL
  45.  
  46.  
  47. #define FUNCTION_KEYS 0x100
  48.  
  49.  
  50. irq_cmd_t msim_cmds[1] = {
  51.     { CMD_MEM_READ_1, (void *)0xB0000000, 0 }
  52. };
  53.  
  54. irq_code_t msim_kbd = {
  55.     1,
  56.     msim_cmds
  57. };
  58.  
  59. int kbd_arch_init(void)
  60. {
  61.     ipc_register_irq(2, &msim_kbd);
  62.     return 1;
  63. }
  64.  
  65.  
  66. /*
  67. *
  68. * Please preserve this code (it can be used to determine scancodes)
  69. *
  70. int to_hex(int v)
  71. {
  72.         return "0123456789ABCDEF"[v];
  73. }
  74. */
  75.  
  76. int kbd_arch_process(keybuffer_t *keybuffer, int scan_code)
  77. {
  78.  
  79.     static unsigned long buf=0;
  80.     static int count=0;
  81.  
  82.  
  83.     //* Please preserve this code (it can be used to determine scancodes)
  84.     //*
  85.     //keybuffer_push(keybuffer, to_hex((scan_code>>4)&0xf));
  86.     //keybuffer_push(keybuffer, to_hex(scan_code&0xf));
  87.     //keybuffer_push(keybuffer, ' ');
  88.     //keybuffer_push(keybuffer, ' ');
  89.     //*/
  90.     //return 1;
  91.    
  92.    
  93.     if(scan_code==0x7e)
  94.     {
  95.         switch (buf){
  96.             case KEY_F5:
  97.                 keybuffer_push(keybuffer,FUNCTION_KEYS | 5 );
  98.                 buf=count=0;
  99.                 return 1;
  100.             case KEY_F6:
  101.                 keybuffer_push(keybuffer,FUNCTION_KEYS | 6 );
  102.                 buf=count=0;
  103.                 return 1;
  104.             case KEY_F7:
  105.                 keybuffer_push(keybuffer,FUNCTION_KEYS | 7 );
  106.                 buf=count=0;
  107.                 return 1;
  108.             case KEY_F8:
  109.                 keybuffer_push(keybuffer,FUNCTION_KEYS | 8 );
  110.                 buf=count=0;
  111.                 return 1;
  112.  
  113.             case KEY_F9:
  114.                 keybuffer_push(keybuffer,FUNCTION_KEYS | 9 );
  115.                 buf=count=0;
  116.                 return 1;
  117.             case KEY_F10:
  118.                 keybuffer_push(keybuffer,FUNCTION_KEYS | 10 );
  119.                 buf=count=0;
  120.                 return 1;
  121.  
  122.             case KEY_F11:
  123.                 keybuffer_push(keybuffer,FUNCTION_KEYS | 11 );
  124.                 buf=count=0;
  125.                 return 1;
  126.             case KEY_F12:
  127.                 keybuffer_push(keybuffer,FUNCTION_KEYS | 12 );
  128.                 buf=count=0;
  129.                 return 1;
  130.             default:
  131.                 keybuffer_push(keybuffer, buf & 0xff );
  132.                 keybuffer_push(keybuffer, (buf >> 8) &0xff );
  133.                 keybuffer_push(keybuffer, (buf >> 16) &0xff );
  134.                 keybuffer_push(keybuffer, (buf >> 24) &0xff );
  135.                 keybuffer_push(keybuffer, scan_code );
  136.                 buf=count=0;
  137.                 return 1;
  138.    
  139.         }
  140.     }
  141.  
  142.     buf|=((unsigned long) scan_code)<<(8*(count++));
  143.    
  144.    
  145.     if((buf & 0xff)!= (KEY_F1 & 0xff)) {
  146.  
  147.         keybuffer_push(keybuffer,buf );
  148.         buf=count=0;
  149.         return 1;
  150.     }
  151.  
  152.     if ( count <= 1 )
  153.         return 1;
  154.  
  155.     if(    (buf & 0xffff) != (KEY_F1 & 0xffff)
  156.         && (buf & 0xffff) != (KEY_F5 & 0xffff) ) {
  157.  
  158.         keybuffer_push(keybuffer, buf & 0xff );
  159.         keybuffer_push(keybuffer, (buf >> 8) &0xff );
  160.         buf=count=0;
  161.         return 1;
  162.     }
  163.  
  164.     if ( count <= 2)
  165.         return 1;
  166.  
  167.     switch (buf){
  168.         case KEY_F1:
  169.             keybuffer_push(keybuffer,FUNCTION_KEYS | 1 );
  170.             buf=count=0;
  171.             return 1;
  172.         case KEY_F2:
  173.             keybuffer_push(keybuffer,FUNCTION_KEYS | 2 );
  174.             buf=count=0;
  175.             return 1;
  176.         case KEY_F3:
  177.             keybuffer_push(keybuffer,FUNCTION_KEYS | 3 );
  178.             buf=count=0;
  179.             return 1;
  180.         case KEY_F4:
  181.             keybuffer_push(keybuffer,FUNCTION_KEYS | 4 );
  182.             buf=count=0;
  183.             return 1;
  184.     }
  185.  
  186.  
  187.     if(    (buf & 0xffffff) != (KEY_F5 & 0xffffff)
  188.         && (buf & 0xffffff) != (KEY_F9 & 0xffffff) ) {
  189.  
  190.         keybuffer_push(keybuffer, buf & 0xff );
  191.         keybuffer_push(keybuffer, (buf >> 8) &0xff );
  192.         keybuffer_push(keybuffer, (buf >> 16) &0xff );
  193.         buf=count=0;
  194.         return 1;
  195.     }
  196.  
  197.     if ( count <= 3 )
  198.         return 1;
  199.    
  200.  
  201.    
  202.    
  203.     switch (buf){
  204.         case KEY_F5:
  205.         case KEY_F6:
  206.         case KEY_F7:
  207.         case KEY_F8:
  208.         case KEY_F9:
  209.         case KEY_F10:
  210.         case KEY_F11:
  211.         case KEY_F12:
  212.             return 1;
  213.         default:
  214.             keybuffer_push(keybuffer, buf & 0xff );
  215.             keybuffer_push(keybuffer, (buf >> 8) &0xff );
  216.             keybuffer_push(keybuffer, (buf >> 16) &0xff );
  217.             keybuffer_push(keybuffer, (buf >> 24) &0xff );
  218.             buf=count=0;
  219.             return 1;
  220.        
  221.         }
  222.     return 1;
  223. }
  224.