Changeset c2417bc in mainline for kernel/genarch/src/kbrd/kbrd.c


Ignore:
Timestamp:
2009-04-21T12:46:26Z (15 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f2d2c7ba
Parents:
44b7783
Message:

change the way how input devices are wired together according to ticket #44
(also the proposal http://lists.modry.cz/cgi-bin/private/helenos-devel/2009-March/002507.html)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/genarch/src/kbrd/kbrd.c

    r44b7783 rc2417bc  
    6060#define LOCKED_CAPSLOCK   (1 << 0)
    6161
    62 static indev_t kbrdout;
    63 
    64 indev_operations_t kbrdout_ops = {
     62static indev_operations_t kbrd_raw_ops = {
    6563        .poll = NULL
    6664};
    67 
    68 SPINLOCK_INITIALIZE(keylock);   /**< keylock protects keyflags and lockflags. */
    69 static volatile int keyflags;   /**< Tracking of multiple keypresses. */
    70 static volatile int lockflags;  /**< Tracking of multiple keys lockings. */
    7165
    7266/** Process release of key.
     
    7468 * @param sc Scancode of the key being released.
    7569 */
    76 static void key_released(wchar_t sc)
     70static void key_released(kbrd_instance_t *instance, wchar_t sc)
    7771{
    78         spinlock_lock(&keylock);
     72        spinlock_lock(&instance->keylock);
     73       
    7974        switch (sc) {
    8075        case SC_LSHIFT:
    8176        case SC_RSHIFT:
    82                 keyflags &= ~PRESSED_SHIFT;
     77                instance->keyflags &= ~PRESSED_SHIFT;
    8378                break;
    8479        case SC_CAPSLOCK:
    85                 keyflags &= ~PRESSED_CAPSLOCK;
    86                 if (lockflags & LOCKED_CAPSLOCK)
    87                         lockflags &= ~LOCKED_CAPSLOCK;
     80                instance->keyflags &= ~PRESSED_CAPSLOCK;
     81                if (instance->lockflags & LOCKED_CAPSLOCK)
     82                        instance->lockflags &= ~LOCKED_CAPSLOCK;
    8883                else
    89                         lockflags |= LOCKED_CAPSLOCK;
     84                        instance->lockflags |= LOCKED_CAPSLOCK;
    9085                break;
    9186        default:
    9287                break;
    9388        }
    94         spinlock_unlock(&keylock);
     89       
     90        spinlock_unlock(&instance->keylock);
    9591}
    9692
     
    9995 * @param sc Scancode of the key being pressed.
    10096 */
    101 static void key_pressed(wchar_t sc)
     97static void key_pressed(kbrd_instance_t *instance, wchar_t sc)
    10298{
    10399        bool letter;
     
    105101        bool capslock;
    106102       
    107         spinlock_lock(&keylock);
     103        spinlock_lock(&instance->keylock);
     104       
    108105        switch (sc) {
    109106        case SC_LSHIFT:
    110107        case SC_RSHIFT:
    111                 keyflags |= PRESSED_SHIFT;
     108                instance->keyflags |= PRESSED_SHIFT;
    112109                break;
    113110        case SC_CAPSLOCK:
    114                 keyflags |= PRESSED_CAPSLOCK;
     111                instance->keyflags |= PRESSED_CAPSLOCK;
    115112                break;
    116113        case SC_SCAN_ESCAPE:
     
    118115        default:
    119116                letter = islower(sc_primary_map[sc]);
    120                 shift = keyflags & PRESSED_SHIFT;
    121                 capslock = (keyflags & PRESSED_CAPSLOCK) ||
    122                     (lockflags & LOCKED_CAPSLOCK);
     117                shift = instance->keyflags & PRESSED_SHIFT;
     118                capslock = (instance->keyflags & PRESSED_CAPSLOCK) ||
     119                    (instance->lockflags & LOCKED_CAPSLOCK);
    123120               
    124121                if ((letter) && (capslock))
     
    126123               
    127124                if (shift)
    128                         indev_push_character(stdin, sc_secondary_map[sc]);
     125                        indev_push_character(instance->sink, sc_secondary_map[sc]);
    129126                else
    130                         indev_push_character(stdin, sc_primary_map[sc]);
     127                        indev_push_character(instance->sink, sc_primary_map[sc]);
    131128                break;
    132129        }
    133         spinlock_unlock(&keylock);
     130       
     131        spinlock_unlock(&instance->keylock);
    134132}
    135133
    136134static void kkbrd(void *arg)
    137135{
    138         indev_t *in = (indev_t *) arg;
     136        kbrd_instance_t *instance = (kbrd_instance_t *) arg;
    139137       
    140138        while (true) {
    141                 wchar_t sc = _getc(in);
     139                wchar_t sc = indev_pop_character(&instance->raw);
    142140               
    143141                if (sc == IGNORE_CODE)
     
    145143               
    146144                if (sc & KEY_RELEASE)
    147                         key_released((sc ^ KEY_RELEASE) & 0x7f);
     145                        key_released(instance, (sc ^ KEY_RELEASE) & 0x7f);
    148146                else
    149                         key_pressed(sc & 0x7f);
     147                        key_pressed(instance, sc & 0x7f);
    150148        }
    151149}
    152150
    153 void kbrd_init(indev_t *devin)
     151kbrd_instance_t *kbrd_init(void)
    154152{
    155         indev_initialize("kbrd", &kbrdout, &kbrdout_ops);
    156         thread_t *thread
    157             = thread_create(kkbrd, devin, TASK, 0, "kkbrd", false);
     153        kbrd_instance_t *instance
     154            = malloc(sizeof(kbrd_instance_t), FRAME_ATOMIC);
     155        if (instance) {
     156                instance->thread
     157                        = thread_create(kkbrd, (void *) instance, TASK, 0, "kkbrd", false);
     158               
     159                if (!instance->thread) {
     160                        free(instance);
     161                        return NULL;
     162                }
     163               
     164                instance->sink = NULL;
     165                indev_initialize("kbrd", &instance->raw, &kbrd_raw_ops);
     166               
     167                spinlock_initialize(&instance->keylock, "instance_keylock");
     168                instance->keyflags = 0;
     169                instance->lockflags = 0;
     170        }
    158171       
    159         if (thread) {
    160                 stdin = &kbrdout;
    161                 thread_ready(thread);
    162         }
     172        return instance;
     173}
     174
     175indev_t *kbrd_wire(kbrd_instance_t *instance, indev_t *sink)
     176{
     177        ASSERT(instance);
     178        ASSERT(sink);
     179       
     180        instance->sink = sink;
     181        thread_ready(instance->thread);
     182       
     183        return &instance->raw;
    163184}
    164185
Note: See TracChangeset for help on using the changeset viewer.