Subversion Repositories HelenOS

Rev

Rev 4629 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Copyright (c) 2001-2004 Jakub Jermar
  3.  * Copyright (c) 2006 Josef Cejka
  4.  * Copyright (c) 2009 Vineeth Pillai
  5.  * All rights reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  *
  11.  * - Redistributions of source code must retain the above copyright
  12.  *   notice, this list of conditions and the following disclaimer.
  13.  * - Redistributions in binary form must reproduce the above copyright
  14.  *   notice, this list of conditions and the following disclaimer in the
  15.  *   documentation and/or other materials provided with the distribution.
  16.  * - The name of the author may not be used to endorse or promote products
  17.  *   derived from this software without specific prior written permission.
  18.  *
  19.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  20.  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  21.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  22.  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  23.  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  24.  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  28.  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29.  */
  30.  
  31. /** @addtogroup kbdarm32 arm32
  32.  * @brief   HelenOS arm32/integratorcp arch dependent parts of uspace keyboard handler.
  33.  * @ingroup  kbd
  34.  * @{
  35.  */
  36. /** @file
  37.  * @ingroup kbdarm32
  38.  */
  39. #include <stdio.h>
  40. #include <arch/kbd.h>
  41. #include <ipc/ipc.h>
  42. #include <unistd.h>
  43. #include <kbd.h>
  44. #include <arch/pl050.h>
  45. #include <keys.h>
  46. #include <genarch/kbd.h>
  47. #include <sysinfo.h>
  48. #include <as.h>
  49. #include <ipc/ipc.h>
  50. #include <ipc/ns.h>
  51. #include <ipc/services.h>
  52. #include <ddi.h>
  53. #include <align.h>
  54.  
  55. #define PL050_KEY_RELEASE 0xF0
  56. #define PL050_ESC_KEY   0xE0
  57.  
  58. irq_cmd_t pl050_cmds[] = {
  59.     { CMD_MEM_READ_1, (void *) 0, 0, 1 },
  60.     { CMD_MEM_READ_1, (void *) 0, 0, 2}
  61. };
  62.  
  63. irq_code_t pl050_kbd = {
  64.     2,
  65.     pl050_cmds
  66. };
  67.  
  68.  
  69. static  void *kbd_physaddr;
  70. static  void *kbd_addr;
  71.  
  72. /** Register uspace irq handler
  73.  * @return
  74.  */
  75. int kbd_arch_init(void)
  76. {
  77.     kbd_physaddr = (void *)sysinfo_value("kbd.pbase");
  78.  
  79.     kbd_addr = (void*)sysinfo_value("kbd.vbase");
  80.  
  81.     pl050_cmds[0].addr = (void *)(kbd_addr+PL050_DATA);
  82.     pl050_cmds[1].addr = (void *)(kbd_addr+PL050_STAT);
  83.  
  84.     /* Enable kbd */
  85.     ipc_register_irq(sysinfo_value("kbd.inr"), sysinfo_value("kbd.devno"), 0, &pl050_kbd);
  86.  
  87.     return 0;
  88. }
  89.  
  90. /** Process keyboard & mouse events */
  91. int kbd_arch_process(keybuffer_t *keybuffer, ipc_call_t *call)
  92. {
  93.     static int key_released_flag = 0;
  94.     static int caps_count = 0;
  95.    
  96.     int scan_code = IPC_GET_ARG1(*call);
  97.  
  98.     if (scan_code == 0x58) {
  99.         if (caps_count == 2) {
  100.             caps_count = 0;
  101.             return 1;
  102.         } else if (key_released_flag && !caps_count) {
  103.             key_released_flag = 0;
  104.             return 1;
  105.         }
  106.         caps_count++;
  107.     }
  108.        
  109.  
  110.     if (scan_code == PL050_KEY_RELEASE) {
  111.         key_released_flag = 1;
  112.     } else {
  113.         if (key_released_flag) {
  114.             key_released(keybuffer, scan_code);
  115.         } else {
  116.             key_pressed(keybuffer, scan_code);
  117.         }
  118.         key_released_flag = 0;
  119.     }
  120.  
  121.     return  1;
  122. }
  123.  
  124. /**
  125.  * @}
  126.  */
  127.