Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/usbhid/kbd/kbdrepeat.c

    r5f6e25e r2d1ba51  
    4545#include "kbddev.h"
    4646
    47 
    48 /** Delay between auto-repeat state checks when no key is being repeated. */
    49 static unsigned int CHECK_DELAY = 10000;
    50 
    51 /*----------------------------------------------------------------------------*/
    5247/**
    5348 * Main loop handling the auto-repeat of keys.
     
    6055 * If the same key is still pressed, it uses the delay between repeats stored
    6156 * in the keyboard structure to wait until the key should be repeated.
    62  * 
     57 *
    6358 * If the currently repeated key is not pressed any more (
    64  * usb_kbd_repeat_stop() was called), it stops repeating it and starts 
     59 * usb_kbd_repeat_stop() was called), it stops repeating it and starts
    6560 * checking again.
    6661 *
    6762 * @note For accessing the keyboard device auto-repeat information a fibril
    6863 *       mutex (repeat_mtx) from the @a kbd structure is used.
    69  * 
     64 *
    7065 * @param kbd Keyboard device structure.
    7166 */
     
    7368{
    7469        unsigned int delay = 0;
    75        
     70
    7671        usb_log_debug("Starting autorepeat loop.\n");
    7772
    7873        while (true) {
    79                 // check if the kbd structure is usable
     74                /* Check if the kbd structure is usable. */
    8075                if (!usb_kbd_is_initialized(kbd)) {
    81                         if (usb_kbd_is_ready_to_destroy(kbd)) {
    82                                 usb_kbd_destroy(kbd);
    83                         }
     76                        usb_log_warning("kbd not ready, exiting autorepeat.\n");
    8477                        return;
    8578                }
    86                
    87                 fibril_mutex_lock(kbd->repeat_mtx);
     79
     80                fibril_mutex_lock(&kbd->repeat_mtx);
    8881
    8982                if (kbd->repeat.key_new > 0) {
    9083                        if (kbd->repeat.key_new == kbd->repeat.key_repeated) {
    91                                 usb_log_debug2("Repeating key: %u.\n", 
     84                                usb_log_debug2("Repeating key: %u.\n",
    9285                                    kbd->repeat.key_repeated);
    93                                 // ugly hack with the NULL
    94                                 usb_kbd_push_ev(NULL, kbd, KEY_PRESS,
     86                                usb_kbd_push_ev(kbd, KEY_PRESS,
    9587                                    kbd->repeat.key_repeated);
    9688                                delay = kbd->repeat.delay_between;
     
    109101                        delay = CHECK_DELAY;
    110102                }
    111                 fibril_mutex_unlock(kbd->repeat_mtx);
    112                
     103                fibril_mutex_unlock(&kbd->repeat_mtx);
    113104                async_usleep(delay);
    114105        }
    115106}
    116 
    117107/*----------------------------------------------------------------------------*/
    118108/**
     
    120110 *
    121111 * Starts the loop for checking changes in auto-repeat.
    122  * 
     112 *
    123113 * @param arg User-specified argument. Expects pointer to the keyboard device
    124114 *            structure representing the keyboard.
     
    130120{
    131121        usb_log_debug("Autorepeat fibril spawned.\n");
    132        
     122
    133123        if (arg == NULL) {
    134124                usb_log_error("No device!\n");
    135125                return EINVAL;
    136126        }
    137        
    138         usb_kbd_t *kbd = (usb_kbd_t *)arg;
    139        
     127
     128        usb_kbd_t *kbd = arg;
     129
    140130        usb_kbd_repeat_loop(kbd);
    141        
     131
    142132        return EOK;
    143133}
    144 
    145134/*----------------------------------------------------------------------------*/
    146135/**
     
    156145void usb_kbd_repeat_start(usb_kbd_t *kbd, unsigned int key)
    157146{
    158         fibril_mutex_lock(kbd->repeat_mtx);
     147        fibril_mutex_lock(&kbd->repeat_mtx);
    159148        kbd->repeat.key_new = key;
    160         fibril_mutex_unlock(kbd->repeat_mtx);
     149        fibril_mutex_unlock(&kbd->repeat_mtx);
    161150}
    162 
    163151/*----------------------------------------------------------------------------*/
    164152/**
     
    166154 *
    167155 * @note Only one key is repeated at any time, but this function may be called
    168  *       even with key that is not currently repeated (in that case nothing 
     156 *       even with key that is not currently repeated (in that case nothing
    169157 *       happens).
    170158 *
     
    174162void usb_kbd_repeat_stop(usb_kbd_t *kbd, unsigned int key)
    175163{
    176         fibril_mutex_lock(kbd->repeat_mtx);
     164        fibril_mutex_lock(&kbd->repeat_mtx);
    177165        if (key == kbd->repeat.key_new) {
    178166                kbd->repeat.key_new = 0;
    179167        }
    180         fibril_mutex_unlock(kbd->repeat_mtx);
     168        fibril_mutex_unlock(&kbd->repeat_mtx);
    181169}
    182 
    183170/**
    184171 * @}
Note: See TracChangeset for help on using the changeset viewer.