Changeset 17ada7a in mainline


Ignore:
Timestamp:
2011-03-10T13:42:14Z (13 years ago)
Author:
Lubos Slovak <lubos.slovak@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7309799
Parents:
dfe53af
Message:

Comments + minor changes.

  • Doxygen comments to all functions in kbddev.c
  • Added parameter count to usbhid_kbd_check_key_changes()
Location:
uspace/drv/usbhid
Files:
2 edited

Legend:

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

    rdfe53af r17ada7a  
    6060
    6161/*----------------------------------------------------------------------------*/
    62 
     62/** Default modifiers when the keyboard is initialized. */
    6363static const unsigned DEFAULT_ACTIVE_MODS = KM_NUM_LOCK;
     64
     65/** Boot protocol report size (key part). */
    6466static const size_t BOOTP_REPORT_SIZE = 6;
     67
     68/** Boot protocol total report size. */
    6569static const size_t BOOTP_BUFFER_SIZE = 8;
     70
     71/** Boot protocol output report size. */
    6672static const size_t BOOTP_BUFFER_OUT_SIZE = 1;
     73
     74/** Boot protocol error key code. */
    6775static const uint8_t BOOTP_ERROR_ROLLOVER = 1;
     76
     77/** Default idle rate for keyboards. */
    6878static const uint8_t IDLE_RATE = 0;
     79
     80/** Delay before a pressed key starts auto-repeating. */
    6981static const unsigned int DEFAULT_DELAY_BEFORE_FIRST_REPEAT = 500 * 1000;
     82
     83/** Delay between two repeats of a pressed key when auto-repeating. */
    7084static const unsigned int DEFAULT_REPEAT_DELAY = 50 * 1000;
    7185
     
    86100#define NUM_LAYOUTS 3
    87101
     102/** Keyboard layout map. */
    88103static layout_op_t *layout[NUM_LAYOUTS] = {
    89104        &us_qwerty_op,
     
    97112/* Modifier constants                                                         */
    98113/*----------------------------------------------------------------------------*/
    99 
     114/** Mapping of USB modifier key codes to generic modifier key codes. */
    100115static const keycode_t usbhid_modifiers_keycodes[USB_HID_MOD_COUNT] = {
    101116        KC_LCTRL,         /* USB_HID_MOD_LCTRL */
     
    118133};
    119134
    120 /** Default handler for IPC methods not handled by DDF.
    121  *
    122  * @param dev Device handling the call.
     135/**
     136 * Default handler for IPC methods not handled by DDF.
     137 *
     138 * Currently recognizes only one method (IPC_M_CONNECT_TO_ME), in which case it
     139 * assumes the caller is the console and thus it stores IPC phone to it for
     140 * later use by the driver to notify about key events.
     141 *
     142 * @param fun Device function handling the call.
    123143 * @param icallid Call id.
    124144 * @param icall Call data.
     
    151171/* Key processing functions                                                   */
    152172/*----------------------------------------------------------------------------*/
    153 
     173/**
     174 * Handles turning of LED lights on and off.
     175 *
     176 * In case of USB keyboards, the LEDs are handled in the driver, not in the
     177 * device. When there should be a change (lock key was pressed), the driver
     178 * uses a Set_Report request sent to the device to set the state of the LEDs.
     179 *
     180 * This functions sets the LED lights according to current settings of modifiers
     181 * kept in the keyboard device structure.
     182 *
     183 * @param kbd_dev Keyboard device structure.
     184 */
    154185static void usbhid_kbd_set_led(usbhid_kbd_t *kbd_dev)
    155186{
     
    193224
    194225/*----------------------------------------------------------------------------*/
    195 
     226/**
     227 * Processes key events.
     228 *
     229 * @note This function was copied from AT keyboard driver and modified to suit
     230 *       USB keyboard.
     231 *
     232 * @note Lock keys are not sent to the console, as they are completely handled
     233 *       in the driver. It may, however, be required later that the driver
     234 *       sends also these keys to application (otherwise it cannot use those
     235 *       keys at all).
     236 *
     237 * @param kbd_dev Keyboard device structure.
     238 * @param type Type of the event (press / release). Recognized values:
     239 *             KEY_PRESS, KEY_RELEASE
     240 * @param key Key code of the key according to HID Usage Tables.
     241 */
    196242void usbhid_kbd_push_ev(usbhid_kbd_t *kbd_dev, int type, unsigned int key)
    197243{
     
    292338
    293339/*----------------------------------------------------------------------------*/
    294 
     340/**
     341 * Checks if modifiers were pressed or released and generates key events.
     342 *
     343 * @param kbd_dev Keyboard device structure.
     344 * @param modifiers Bitmap of modifiers.
     345 *
     346 * @sa usbhid_kbd_push_ev()
     347 */
    295348static void usbhid_kbd_check_modifier_changes(usbhid_kbd_t *kbd_dev,
    296349    uint8_t modifiers)
     
    328381
    329382/*----------------------------------------------------------------------------*/
    330 
     383/**
     384 * Checks if some keys were pressed or released and generates key events.
     385 *
     386 * An event is created only when key is pressed or released. Besides handling
     387 * the events (usbhid_kbd_push_ev()), the auto-repeat fibril is notified about
     388 * key presses and releases (see usbhid_kbd_repeat_start() and
     389 * usbhid_kbd_repeat_stop()).
     390 *
     391 * @param kbd_dev Keyboard device structure.
     392 * @param key_codes Parsed keyboard report - codes of currently pressed keys
     393 *                  according to HID Usage Tables.
     394 * @param count Number of key codes in report (size of the report).
     395 *
     396 * @sa usbhid_kbd_push_ev(), usbhid_kbd_repeat_start(), usbhid_kbd_repeat_stop()
     397 */
    331398static void usbhid_kbd_check_key_changes(usbhid_kbd_t *kbd_dev,
    332     const uint8_t *key_codes)
     399    const uint8_t *key_codes, size_t count)
    333400{
    334401        unsigned int key;
     
    340407        i = 0;
    341408        // all fields should report Error Rollover
    342         while (i < kbd_dev->key_count &&
     409        while (i < count &&
    343410            key_codes[i] == BOOTP_ERROR_ROLLOVER) {
    344411                ++i;
    345412        }
    346         if (i == kbd_dev->key_count) {
     413        if (i == count) {
    347414                usb_log_debug("Phantom state occured.\n");
    348415                // phantom state, do nothing
     
    350417        }
    351418       
    352         // TODO: quite dummy right now, think of better implementation
     419        /* TODO: quite dummy right now, think of better implementation */
     420        assert(count == kbd_dev->key_count);
    353421       
    354422        /*
    355423         * 1) Key releases
    356424         */
    357         for (j = 0; j < kbd_dev->key_count; ++j) {
     425        for (j = 0; j < count; ++j) {
    358426                // try to find the old key in the new key list
    359427                i = 0;
     
    363431                }
    364432               
    365                 if (i == kbd_dev->key_count) {
     433                if (i == count) {
    366434                        // not found, i.e. the key was released
    367435                        key = usbhid_parse_scancode(kbd_dev->keys[j]);
     
    380448                // try to find the new key in the old key list
    381449                j = 0;
    382                 while (j < kbd_dev->key_count
    383                     && kbd_dev->keys[j] != key_codes[i]) {
     450                while (j < count && kbd_dev->keys[j] != key_codes[i]) {
    384451                        ++j;
    385452                }
    386453               
    387                 if (j == kbd_dev->key_count) {
     454                if (j == count) {
    388455                        // not found, i.e. new key pressed
    389456                        key = usbhid_parse_scancode(key_codes[i]);
     
    392459                        usbhid_kbd_push_ev(kbd_dev, KEY_PRESS, key);
    393460                        usbhid_kbd_repeat_start(kbd_dev, key);
    394                 } else {
     461                } else {size_t
    395462                        // found, nothing happens
    396463                }
    397464        }
    398 //      // report all currently pressed keys
    399 //      for (i = 0; i < kbd_dev->keycode_count; ++i) {
    400 //              if (key_codes[i] != 0) {
    401 //                      key = usbhid_parse_scancode(key_codes[i]);
    402 //                      usb_log_debug2("Key pressed: %d (keycode: %d)\n", key,
    403 //                          key_codes[i]);
    404 //                      usbhid_kbd_push_ev(kbd_dev, KEY_PRESS, key);
    405 //              }
    406 //      }
    407        
    408         memcpy(kbd_dev->keys, key_codes, kbd_dev->key_count);
     465       
     466        memcpy(kbd_dev->keys, key_codes, count);
    409467
    410468        usb_log_debug("New stored keycodes: %s\n",
     
    415473/* Callbacks for parser                                                       */
    416474/*----------------------------------------------------------------------------*/
    417 
     475/**
     476 * Callback function for the HID report parser.
     477 *
     478 * This function is called by the HID report parser with the parsed report.
     479 * The parsed report is used to check if any events occured (key was pressed or
     480 * released, modifier was pressed or released).
     481 *
     482 * @param key_codes Parsed keyboard report - codes of currently pressed keys
     483 *                  according to HID Usage Tables.
     484 * @param count Number of key codes in report (size of the report).
     485 * @param modifiers Bitmap of modifiers (Ctrl, Alt, Shift, GUI).
     486 * @param arg User-specified argument.
     487 *
     488 * @sa usbhid_kbd_check_key_changes(), usbhid_kbd_check_modifier_changes()
     489 */
    418490static void usbhid_kbd_process_keycodes(const uint8_t *key_codes, size_t count,
    419491    uint8_t modifiers, void *arg)
     
    438510       
    439511        usbhid_kbd_check_modifier_changes(kbd_dev, modifiers);
    440         usbhid_kbd_check_key_changes(kbd_dev, key_codes);
     512        usbhid_kbd_check_key_changes(kbd_dev, key_codes, count);
    441513}
    442514
     
    773845 *
    774846 * This functions initializes required structures from the device's descriptors
    775  * and starts a new fibril for polling the keyboard for events.
     847 * and starts new fibril for polling the keyboard for events and another one for
     848 * handling auto-repeat of keys.
    776849 *
    777850 * During initialization, the keyboard is switched into boot protocol, the idle
     
    791864 *         ddf_fun_bind() and ddf_fun_add_to_class().
    792865 *
    793  * @sa usbhid_kbd_fibril()
     866 * @sa usbhid_kbd_fibril(), usbhid_kbd_repeat_fibril()
    794867 */
    795868int usbhid_kbd_try_add_device(ddf_dev_t *dev)
  • uspace/drv/usbhid/kbdrepeat.c

    rdfe53af r17ada7a  
    4545#include "kbddev.h"
    4646
    47 static unsigned int CHECK_DELAY = 1000;
     47static unsigned int CHECK_DELAY = 10000;
    4848
    4949/*----------------------------------------------------------------------------*/
Note: See TracChangeset for help on using the changeset viewer.