Subversion Repositories HelenOS

Rev

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

  1. /*
  2.  * Copyright (c) 2001-2004 Jakub Jermar
  3.  * Copyright (c) 2006 Josef Cejka
  4.  * All rights reserved.
  5.  *
  6.  * Redistribution and use in source and binary forms, with or without
  7.  * modification, are permitted provided that the following conditions
  8.  * are met:
  9.  *
  10.  * - Redistributions of source code must retain the above copyright
  11.  *   notice, this list of conditions and the following disclaimer.
  12.  * - Redistributions in binary form must reproduce the above copyright
  13.  *   notice, this list of conditions and the following disclaimer in the
  14.  *   documentation and/or other materials provided with the distribution.
  15.  * - The name of the author may not be used to endorse or promote products
  16.  *   derived from this software without specific prior written permission.
  17.  *
  18.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  19.  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  20.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  21.  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  22.  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  23.  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  24.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  25.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  27.  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28.  */
  29.  
  30. /** @addtogroup kbd
  31.  * @brief   Handling of keyboard IRQ notifications for several architectures.
  32.  * @ingroup  kbd
  33.  * @{
  34.  */
  35. /** @file
  36.  */
  37.  
  38. #include <key_buffer.h>
  39. #include <arch/scanc.h>
  40. #include <genarch/scanc.h>
  41. #include <genarch/kbd.h>
  42. #include <libc.h>
  43.  
  44. #define PRESSED_SHIFT       (1<<0)
  45. #define PRESSED_CAPSLOCK    (1<<1)
  46. #define LOCKED_CAPSLOCK     (1<<0)
  47.  
  48. static volatile int keyflags;       /**< Tracking of multiple keypresses. */
  49. static volatile int lockflags;      /**< Tracking of multiple keys lockings. */
  50.  
  51. void key_released(keybuffer_t *keybuffer, unsigned char key)
  52. {
  53.     switch (key) {
  54.     case SC_LSHIFT:
  55.     case SC_RSHIFT:
  56.         keyflags &= ~PRESSED_SHIFT;
  57.         break;
  58.     case SC_CAPSLOCK:
  59.         keyflags &= ~PRESSED_CAPSLOCK;
  60.         if (lockflags & LOCKED_CAPSLOCK)
  61.             lockflags &= ~LOCKED_CAPSLOCK;
  62.         else
  63.             lockflags |= LOCKED_CAPSLOCK;
  64.         break;
  65.     default:
  66.         break;
  67.     }
  68. }
  69.  
  70. void key_pressed(keybuffer_t *keybuffer, unsigned char key)
  71. {
  72.     int *map = sc_primary_map;
  73.     int ascii = sc_primary_map[key];
  74.     int shift, capslock;
  75.     int letter = 0;
  76.  
  77.     static int esc_count = 0;
  78.  
  79.     if (key == SC_ESC) {
  80.         esc_count++;
  81.         if (esc_count == 3)
  82.             __SYSCALL0(SYS_DEBUG_ENABLE_CONSOLE);
  83.     } else {
  84.         esc_count = 0;
  85.     }
  86.    
  87.     switch (key) {
  88.     case SC_LSHIFT:
  89.     case SC_RSHIFT:
  90.             keyflags |= PRESSED_SHIFT;
  91.         break;
  92.     case SC_CAPSLOCK:
  93.         keyflags |= PRESSED_CAPSLOCK;
  94.         break;
  95.     case SC_SPEC_ESCAPE:
  96.         break;
  97.     default:
  98.             letter = ((ascii >= 'a') && (ascii <= 'z'));
  99.         capslock = (keyflags & PRESSED_CAPSLOCK) || (lockflags & LOCKED_CAPSLOCK);
  100.         shift = keyflags & PRESSED_SHIFT;
  101.         if (letter && capslock)
  102.             shift = !shift;
  103.         if (shift)
  104.             map = sc_secondary_map;
  105.         if (map[key] != SPECIAL)
  106.             keybuffer_push(keybuffer, map[key]);   
  107.         break;
  108.     }
  109. }
  110.  
  111. /**
  112.  * @}
  113.  */
  114.