Changeset dfe53af in mainline for uspace/drv/usbhid/kbddev.c


Ignore:
Timestamp:
2011-03-10T10:47:55Z (14 years ago)
Author:
Lubos Slovak <lubos.slovak@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
17ada7a, 8a02ff3
Parents:
269bd9b4
Message:

Auto-repeat of keys.

  • Added structure usbhid_kbd_repeat_t.
  • Added functions for:
    • checking repeat status in a loop
    • starting to repeat a key
    • stopping to repeat a key
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/usbhid/kbddev.c

    r269bd9b4 rdfe53af  
    3737#include <errno.h>
    3838#include <str_error.h>
    39 #include <fibril.h>
    4039#include <stdio.h>
    4140
     
    4342#include <ipc/kbd.h>
    4443#include <async.h>
     44#include <fibril.h>
     45#include <fibril_synch.h>
    4546
    4647#include <usb/usb.h>
     
    5657#include "layout.h"
    5758#include "conv.h"
     59#include "kbdrepeat.h"
    5860
    5961/*----------------------------------------------------------------------------*/
     
    6567static const uint8_t BOOTP_ERROR_ROLLOVER = 1;
    6668static const uint8_t IDLE_RATE = 0;
     69static const unsigned int DEFAULT_DELAY_BEFORE_FIRST_REPEAT = 500 * 1000;
     70static const unsigned int DEFAULT_REPEAT_DELAY = 50 * 1000;
    6771
    6872/** Keyboard polling endpoint description for boot protocol class. */
     
    190194/*----------------------------------------------------------------------------*/
    191195
    192 static void usbhid_kbd_push_ev(usbhid_kbd_t *kbd_dev, int type,
    193     unsigned int key)
     196void usbhid_kbd_push_ev(usbhid_kbd_t *kbd_dev, int type, unsigned int key)
    194197{
    195198        console_event_t ev;
     
    233236                         * up the lock state.
    234237                         */
     238                        unsigned int locks_old = kbd_dev->lock_keys;
     239                       
    235240                        kbd_dev->mods =
    236241                            kbd_dev->mods ^ (mod_mask & ~kbd_dev->lock_keys);
     
    238243
    239244                        /* Update keyboard lock indicator lights. */
    240                         usbhid_kbd_set_led(kbd_dev);
     245                        if (kbd_dev->lock_keys != locks_old) {
     246                                usbhid_kbd_set_led(kbd_dev);
     247                        }
    241248                } else {
    242249                        kbd_dev->lock_keys = kbd_dev->lock_keys & ~mod_mask;
     
    359366                        // not found, i.e. the key was released
    360367                        key = usbhid_parse_scancode(kbd_dev->keys[j]);
     368                        usbhid_kbd_repeat_stop(kbd_dev, key);
    361369                        usbhid_kbd_push_ev(kbd_dev, KEY_RELEASE, key);
    362370                        usb_log_debug2("Key released: %d\n", key);
     
    383391                            key_codes[i]);
    384392                        usbhid_kbd_push_ev(kbd_dev, KEY_PRESS, key);
     393                        usbhid_kbd_repeat_start(kbd_dev, key);
    385394                } else {
    386395                        // found, nothing happens
     
    527536        }
    528537       
     538        if ((*kbd_dev)->repeat_mtx != NULL) {
     539                /* TODO: replace by some check and wait */
     540                assert(!fibril_mutex_is_locked((*kbd_dev)->repeat_mtx));
     541                free((*kbd_dev)->repeat_mtx);
     542        }
     543       
    529544        free(*kbd_dev);
    530545        *kbd_dev = NULL;
     
    598613        kbd_dev->mods = DEFAULT_ACTIVE_MODS;
    599614        kbd_dev->lock_keys = 0;
     615       
     616        kbd_dev->repeat.key_new = 0;
     617        kbd_dev->repeat.key_repeated = 0;
     618        kbd_dev->repeat.delay_before = DEFAULT_DELAY_BEFORE_FIRST_REPEAT;
     619        kbd_dev->repeat.delay_between = DEFAULT_REPEAT_DELAY;
     620       
     621        kbd_dev->repeat_mtx = (fibril_mutex_t *)(
     622            malloc(sizeof(fibril_mutex_t)));
     623        if (kbd_dev->repeat_mtx == NULL) {
     624                usb_log_fatal("No memory!\n");
     625                free(kbd_dev->keys);
     626                return ENOMEM;
     627        }
     628       
     629        fibril_mutex_initialize(kbd_dev->repeat_mtx);
    600630       
    601631        /*
     
    833863        }
    834864        fibril_add_ready(fid);
     865       
     866        /*
     867         * Create new fibril for auto-repeat
     868         */
     869        fid = fibril_create(usbhid_kbd_repeat_fibril, kbd_dev);
     870        if (fid == 0) {
     871                usb_log_error("Failed to start fibril for KBD auto-repeat");
     872                return ENOMEM;
     873        }
     874        fibril_add_ready(fid);
    835875
    836876        (void)keyboard_ops;
Note: See TracChangeset for help on using the changeset viewer.