| 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 | kbd_event_t ev;
|
|---|
| 77 |
|
|---|
| 78 | static int esc_count = 0;
|
|---|
| 79 |
|
|---|
| 80 | if (key == SC_ESC) {
|
|---|
| 81 | esc_count++;
|
|---|
| 82 | if (esc_count == 3)
|
|---|
| 83 | __SYSCALL0(SYS_DEBUG_ENABLE_CONSOLE);
|
|---|
| 84 | } else {
|
|---|
| 85 | esc_count = 0;
|
|---|
| 86 | }
|
|---|
| 87 |
|
|---|
| 88 | switch (key) {
|
|---|
| 89 | case SC_LSHIFT:
|
|---|
| 90 | case SC_RSHIFT:
|
|---|
| 91 | keyflags |= PRESSED_SHIFT;
|
|---|
| 92 | break;
|
|---|
| 93 | case SC_CAPSLOCK:
|
|---|
| 94 | keyflags |= PRESSED_CAPSLOCK;
|
|---|
| 95 | break;
|
|---|
| 96 | case SC_SPEC_ESCAPE:
|
|---|
| 97 | break;
|
|---|
| 98 | default:
|
|---|
| 99 | letter = ((ascii >= 'a') && (ascii <= 'z'));
|
|---|
| 100 | capslock = (keyflags & PRESSED_CAPSLOCK) || (lockflags & LOCKED_CAPSLOCK);
|
|---|
| 101 | shift = keyflags & PRESSED_SHIFT;
|
|---|
| 102 | if (letter && capslock)
|
|---|
| 103 | shift = !shift;
|
|---|
| 104 | if (shift)
|
|---|
| 105 | map = sc_secondary_map;
|
|---|
| 106 | if (map[key] != SPECIAL) {
|
|---|
| 107 | ev.key = map[key];
|
|---|
| 108 | ev.mods = 0;
|
|---|
| 109 | ev.c = map[key];
|
|---|
| 110 | keybuffer_push(keybuffer, &ev);
|
|---|
| 111 | }
|
|---|
| 112 | break;
|
|---|
| 113 | }
|
|---|
| 114 | }
|
|---|
| 115 |
|
|---|
| 116 | /**
|
|---|
| 117 | * @}
|
|---|
| 118 | */
|
|---|