Ignore:
File:
1 edited

Legend:

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

    re8c1fb0 rdfe53af  
    6060
    6161/*----------------------------------------------------------------------------*/
    62 /** Default modifiers when the keyboard is initialized. */
     62
    6363static const unsigned DEFAULT_ACTIVE_MODS = KM_NUM_LOCK;
    64 
    65 /** Boot protocol report size (key part). */
    6664static const size_t BOOTP_REPORT_SIZE = 6;
    67 
    68 /** Boot protocol total report size. */
    6965static const size_t BOOTP_BUFFER_SIZE = 8;
    70 
    71 /** Boot protocol output report size. */
    7266static const size_t BOOTP_BUFFER_OUT_SIZE = 1;
    73 
    74 /** Boot protocol error key code. */
    7567static const uint8_t BOOTP_ERROR_ROLLOVER = 1;
    76 
    77 /** Default idle rate for keyboards. */
    7868static const uint8_t IDLE_RATE = 0;
    79 
    80 /** Delay before a pressed key starts auto-repeating. */
    8169static const unsigned int DEFAULT_DELAY_BEFORE_FIRST_REPEAT = 500 * 1000;
    82 
    83 /** Delay between two repeats of a pressed key when auto-repeating. */
    8470static const unsigned int DEFAULT_REPEAT_DELAY = 50 * 1000;
    8571
     
    10086#define NUM_LAYOUTS 3
    10187
    102 /** Keyboard layout map. */
    10388static layout_op_t *layout[NUM_LAYOUTS] = {
    10489        &us_qwerty_op,
     
    11297/* Modifier constants                                                         */
    11398/*----------------------------------------------------------------------------*/
    114 /** Mapping of USB modifier key codes to generic modifier key codes. */
     99
    115100static const keycode_t usbhid_modifiers_keycodes[USB_HID_MOD_COUNT] = {
    116101        KC_LCTRL,         /* USB_HID_MOD_LCTRL */
     
    133118};
    134119
    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.
     120/** Default handler for IPC methods not handled by DDF.
     121 *
     122 * @param dev Device handling the call.
    143123 * @param icallid Call id.
    144124 * @param icall Call data.
     
    171151/* Key processing functions                                                   */
    172152/*----------------------------------------------------------------------------*/
    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  */
     153
    185154static void usbhid_kbd_set_led(usbhid_kbd_t *kbd_dev)
    186155{
     
    224193
    225194/*----------------------------------------------------------------------------*/
    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  */
     195
    242196void usbhid_kbd_push_ev(usbhid_kbd_t *kbd_dev, int type, unsigned int key)
    243197{
     
    338292
    339293/*----------------------------------------------------------------------------*/
    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  */
     294
    348295static void usbhid_kbd_check_modifier_changes(usbhid_kbd_t *kbd_dev,
    349296    uint8_t modifiers)
     
    381328
    382329/*----------------------------------------------------------------------------*/
    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  */
     330
    398331static void usbhid_kbd_check_key_changes(usbhid_kbd_t *kbd_dev,
    399     const uint8_t *key_codes, size_t count)
     332    const uint8_t *key_codes)
    400333{
    401334        unsigned int key;
     
    407340        i = 0;
    408341        // all fields should report Error Rollover
    409         while (i < count &&
     342        while (i < kbd_dev->key_count &&
    410343            key_codes[i] == BOOTP_ERROR_ROLLOVER) {
    411344                ++i;
    412345        }
    413         if (i == count) {
     346        if (i == kbd_dev->key_count) {
    414347                usb_log_debug("Phantom state occured.\n");
    415348                // phantom state, do nothing
     
    417350        }
    418351       
    419         /* TODO: quite dummy right now, think of better implementation */
    420         assert(count == kbd_dev->key_count);
     352        // TODO: quite dummy right now, think of better implementation
    421353       
    422354        /*
    423355         * 1) Key releases
    424356         */
    425         for (j = 0; j < count; ++j) {
     357        for (j = 0; j < kbd_dev->key_count; ++j) {
    426358                // try to find the old key in the new key list
    427359                i = 0;
     
    431363                }
    432364               
    433                 if (i == count) {
     365                if (i == kbd_dev->key_count) {
    434366                        // not found, i.e. the key was released
    435367                        key = usbhid_parse_scancode(kbd_dev->keys[j]);
     
    448380                // try to find the new key in the old key list
    449381                j = 0;
    450                 while (j < count && kbd_dev->keys[j] != key_codes[i]) {
     382                while (j < kbd_dev->key_count
     383                    && kbd_dev->keys[j] != key_codes[i]) {
    451384                        ++j;
    452385                }
    453386               
    454                 if (j == count) {
     387                if (j == kbd_dev->key_count) {
    455388                        // not found, i.e. new key pressed
    456389                        key = usbhid_parse_scancode(key_codes[i]);
     
    459392                        usbhid_kbd_push_ev(kbd_dev, KEY_PRESS, key);
    460393                        usbhid_kbd_repeat_start(kbd_dev, key);
    461                 } else {size_t
     394                } else {
    462395                        // found, nothing happens
    463396                }
    464397        }
    465        
    466         memcpy(kbd_dev->keys, key_codes, count);
     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);
    467409
    468410        usb_log_debug("New stored keycodes: %s\n",
     
    473415/* Callbacks for parser                                                       */
    474416/*----------------------------------------------------------------------------*/
    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. Expects pointer to the keyboard device
    487  *            structure representing the keyboard.
    488  *
    489  * @sa usbhid_kbd_check_key_changes(), usbhid_kbd_check_modifier_changes()
    490  */
     417
    491418static void usbhid_kbd_process_keycodes(const uint8_t *key_codes, size_t count,
    492419    uint8_t modifiers, void *arg)
     
    511438       
    512439        usbhid_kbd_check_modifier_changes(kbd_dev, modifiers);
    513         usbhid_kbd_check_key_changes(kbd_dev, key_codes, count);
     440        usbhid_kbd_check_key_changes(kbd_dev, key_codes);
    514441}
    515442
     
    759686                        usb_log_warning("Failed to start a session: %s.\n",
    760687                            str_error(sess_rc));
    761                         break;
     688                        continue;
    762689                }
    763690
     
    771698                        usb_log_warning("Error polling the keyboard: %s.\n",
    772699                            str_error(rc));
    773                         break;
     700                        continue;
    774701                }
    775702
     
    777704                        usb_log_warning("Error closing session: %s.\n",
    778705                            str_error(sess_rc));
    779                         break;
     706                        continue;
    780707                }
    781708
     
    798725                //async_usleep(kbd_dev->hid_dev->poll_interval);
    799726        }
     727
     728        // not reached
     729        assert(0);
    800730}
    801731
     
    843773 *
    844774 * This functions initializes required structures from the device's descriptors
    845  * and starts new fibril for polling the keyboard for events and another one for
    846  * handling auto-repeat of keys.
     775 * and starts a new fibril for polling the keyboard for events.
    847776 *
    848777 * During initialization, the keyboard is switched into boot protocol, the idle
     
    862791 *         ddf_fun_bind() and ddf_fun_add_to_class().
    863792 *
    864  * @sa usbhid_kbd_fibril(), usbhid_kbd_repeat_fibril()
     793 * @sa usbhid_kbd_fibril()
    865794 */
    866795int usbhid_kbd_try_add_device(ddf_dev_t *dev)
Note: See TracChangeset for help on using the changeset viewer.