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


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

Getting size of report from parser, changed key processing.

File:
1 edited

Legend:

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

    rbb41b85 rfc5ed5d  
    5151#include <usb/classes/hidparser.h>
    5252#include <usb/classes/classes.h>
     53#include <usb/classes/hidut.h>
    5354
    5455#include "kbddev.h"
     
    122123        KC_RALT,          /* USB_HID_MOD_RALT */
    123124        0,                /* USB_HID_MOD_RGUI */
     125};
     126
     127typedef enum usbhid_lock_code {
     128        USBHID_LOCK_NUM = 0x53,
     129        USBHID_LOCK_CAPS = 0x39,
     130        USBHID_LOCK_SCROLL = 0x47,
     131        USBHID_LOCK_COUNT = 3
     132} usbhid_lock_code;
     133
     134static const usbhid_lock_code usbhid_lock_codes[USBHID_LOCK_COUNT] = {
     135        USBHID_LOCK_NUM,
     136        USBHID_LOCK_CAPS,
     137        USBHID_LOCK_SCROLL
    124138};
    125139
     
    346360 * @sa usbhid_kbd_push_ev()
    347361 */
    348 static void usbhid_kbd_check_modifier_changes(usbhid_kbd_t *kbd_dev,
    349     uint8_t modifiers)
    350 {
    351         /*
    352          * TODO: why the USB keyboard has NUM_, SCROLL_ and CAPS_LOCK
    353          *       both as modifiers and as keys with their own scancodes???
    354          *
    355          * modifiers should be sent as normal keys to usbhid_parse_scancode()!!
    356          * so maybe it would be better if I received it from report parser in
    357          * that way
    358          */
    359        
    360         int i;
    361         for (i = 0; i < USB_HID_MOD_COUNT; ++i) {
    362                 if ((modifiers & usb_hid_modifiers_consts[i]) &&
    363                     !(kbd_dev->modifiers & usb_hid_modifiers_consts[i])) {
    364                         // modifier pressed
    365                         if (usbhid_modifiers_keycodes[i] != 0) {
    366                                 usbhid_kbd_push_ev(kbd_dev, KEY_PRESS,
    367                                     usbhid_modifiers_keycodes[i]);
    368                         }
    369                 } else if (!(modifiers & usb_hid_modifiers_consts[i]) &&
    370                     (kbd_dev->modifiers & usb_hid_modifiers_consts[i])) {
    371                         // modifier released
    372                         if (usbhid_modifiers_keycodes[i] != 0) {
    373                                 usbhid_kbd_push_ev(kbd_dev, KEY_RELEASE,
    374                                     usbhid_modifiers_keycodes[i]);
    375                         }
    376                 }       // no change
    377         }
    378        
    379         kbd_dev->modifiers = modifiers;
     362//static void usbhid_kbd_check_modifier_changes(usbhid_kbd_t *kbd_dev,
     363//    const uint8_t *key_codes, size_t count)
     364//{
     365//      /*
     366//       * TODO: why the USB keyboard has NUM_, SCROLL_ and CAPS_LOCK
     367//       *       both as modifiers and as keyUSB_HID_LOCK_COUNTs with their own scancodes???
     368//       *
     369//       * modifiers should be sent as normal keys to usbhid_parse_scancode()!!
     370//       * so maybe it would be better if I received it from report parser in
     371//       * that way
     372//       */
     373       
     374//      int i;
     375//      for (i = 0; i < count; ++i) {
     376//              if ((modifiers & usb_hid_modifiers_consts[i]) &&
     377//                  !(kbd_dev->modifiers & usb_hid_modifiers_consts[i])) {
     378//                      // modifier pressed
     379//                      if (usbhid_modifiers_keycodes[i] != 0) {
     380//                              usbhid_kbd_push_ev(kbd_dev, KEY_PRESS,
     381//                                  usbhid_modifiers_keycodes[i]);
     382//                      }
     383//              } else if (!(modifiers & usb_hid_modifiers_consts[i]) &&
     384//                  (kbd_dev->modifiers & usb_hid_modifiers_consts[i])) {
     385//                      // modifier released
     386//                      if (usbhid_modifiers_keycodes[i] != 0) {
     387//                              usbhid_kbd_push_ev(kbd_dev, KEY_RELEASE,
     388//                                  usbhid_modifiers_keycodes[i]);
     389//                      }
     390//              }       // no change
     391//      }
     392       
     393//      kbd_dev->modifiers = modifiers;
     394//}
     395
     396/*----------------------------------------------------------------------------*/
     397
     398static inline int usbhid_kbd_is_lock(unsigned int key_code)
     399{
     400        return (key_code == KC_NUM_LOCK
     401            || key_code == KC_SCROLL_LOCK
     402            || key_code == KC_CAPS_LOCK);
    380403}
    381404
     
    404427        /*
    405428         * First of all, check if the kbd have reported phantom state.
     429         *
     430         * TODO: this must be changed as we don't know which keys are modifiers
     431         *       and which are regular keys.
    406432         */
    407433        i = 0;
     
    434460                        // not found, i.e. the key was released
    435461                        key = usbhid_parse_scancode(kbd_dev->keys[j]);
    436                         usbhid_kbd_repeat_stop(kbd_dev, key);
     462                        if (!usbhid_kbd_is_lock(key)) {
     463                                usbhid_kbd_repeat_stop(kbd_dev, key);
     464                        }
    437465                        usbhid_kbd_push_ev(kbd_dev, KEY_RELEASE, key);
    438466                        usb_log_debug2("Key released: %d\n", key);
     
    458486                            key_codes[i]);
    459487                        usbhid_kbd_push_ev(kbd_dev, KEY_PRESS, key);
    460                         usbhid_kbd_repeat_start(kbd_dev, key);
     488                        if (!usbhid_kbd_is_lock(key)) {
     489                                usbhid_kbd_repeat_start(kbd_dev, key);
     490                        }
    461491                } else {
    462492                        // found, nothing happens
     
    510540        }
    511541       
    512         usbhid_kbd_check_modifier_changes(kbd_dev, modifiers);
     542        ///usbhid_kbd_check_modifier_changes(kbd_dev, key_codes, count);
    513543        usbhid_kbd_check_key_changes(kbd_dev, key_codes, count);
    514544}
     
    679709       
    680710        // save the size of the report (boot protocol report by default)
    681         kbd_dev->key_count = BOOTP_REPORT_SIZE;
     711//      kbd_dev->key_count = BOOTP_REPORT_SIZE;
     712       
     713        usb_hid_report_path_t path;
     714        path.usage_page = USB_HIDUT_PAGE_KEYBOARD;
     715        kbd_dev->key_count = usb_hid_report_input_length(
     716            kbd_dev->hid_dev->parser, &path);
     717       
     718        usb_log_debug("Size of the input report: %zu\n", kbd_dev->key_count);
     719       
    682720        kbd_dev->keys = (uint8_t *)calloc(
    683721            kbd_dev->key_count, sizeof(uint8_t));
Note: See TracChangeset for help on using the changeset viewer.