Ignore:
File:
1 edited

Legend:

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

    rfc5ed5d rb05e2fe  
    5151#include <usb/classes/hidparser.h>
    5252#include <usb/classes/classes.h>
    53 #include <usb/classes/hidut.h>
    5453
    5554#include "kbddev.h"
     
    123122        KC_RALT,          /* USB_HID_MOD_RALT */
    124123        0,                /* USB_HID_MOD_RGUI */
    125 };
    126 
    127 typedef 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 
    134 static const usbhid_lock_code usbhid_lock_codes[USBHID_LOCK_COUNT] = {
    135         USBHID_LOCK_NUM,
    136         USBHID_LOCK_CAPS,
    137         USBHID_LOCK_SCROLL
    138124};
    139125
     
    360346 * @sa usbhid_kbd_push_ev()
    361347 */
    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 
    398 static 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);
     348static 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;
    403380}
    404381
     
    427404        /*
    428405         * 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.
    432406         */
    433407        i = 0;
     
    460434                        // not found, i.e. the key was released
    461435                        key = usbhid_parse_scancode(kbd_dev->keys[j]);
    462                         if (!usbhid_kbd_is_lock(key)) {
    463                                 usbhid_kbd_repeat_stop(kbd_dev, key);
    464                         }
     436                        usbhid_kbd_repeat_stop(kbd_dev, key);
    465437                        usbhid_kbd_push_ev(kbd_dev, KEY_RELEASE, key);
    466438                        usb_log_debug2("Key released: %d\n", key);
     
    486458                            key_codes[i]);
    487459                        usbhid_kbd_push_ev(kbd_dev, KEY_PRESS, key);
    488                         if (!usbhid_kbd_is_lock(key)) {
    489                                 usbhid_kbd_repeat_start(kbd_dev, key);
    490                         }
     460                        usbhid_kbd_repeat_start(kbd_dev, key);
    491461                } else {
    492462                        // found, nothing happens
     
    532502
    533503        usb_log_debug("Got keys from parser: %s\n",
    534             usb_debug_str_buffer(key_codes, count, 0));
     504            usb_debug_str_buffer(key_codes, kbd_dev->key_count, 0));
    535505       
    536506        if (count != kbd_dev->key_count) {
     
    540510        }
    541511       
    542         ///usbhid_kbd_check_modifier_changes(kbd_dev, key_codes, count);
     512        usbhid_kbd_check_modifier_changes(kbd_dev, modifiers);
    543513        usbhid_kbd_check_key_changes(kbd_dev, key_codes, count);
    544514}
     
    565535                                    uint8_t *buffer, size_t actual_size)
    566536{
    567         assert(kbd_dev->initialized);
    568         assert(kbd_dev->hid_dev->parser != NULL);
    569        
    570537        usb_hid_report_in_callbacks_t *callbacks =
    571538            (usb_hid_report_in_callbacks_t *)malloc(
     
    574541        callbacks->keyboard = usbhid_kbd_process_keycodes;
    575542
    576         usb_log_debug("Calling usb_hid_parse_report() with "
     543        usb_log_debug("Calling usb_hid_boot_keyboard_input_report() with "
    577544            "buffer %s\n", usb_debug_str_buffer(buffer, actual_size, 0));
    578545       
    579 //      int rc = usb_hid_boot_keyboard_input_report(buffer, actual_size,
    580 //          callbacks, kbd_dev);
    581         int rc = usb_hid_parse_report(kbd_dev->hid_dev->parser, buffer,
    582             actual_size, callbacks, kbd_dev);
     546        int rc = usb_hid_boot_keyboard_input_report(buffer, actual_size,
     547            callbacks, kbd_dev);
    583548       
    584549        if (rc != EOK) {
     
    649614                free((*kbd_dev)->repeat_mtx);
    650615        }
    651 
     616       
    652617        free(*kbd_dev);
    653618        *kbd_dev = NULL;
     
    709674       
    710675        // save the size of the report (boot protocol report by default)
    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        
     676        kbd_dev->key_count = BOOTP_REPORT_SIZE;
    720677        kbd_dev->keys = (uint8_t *)calloc(
    721678            kbd_dev->key_count, sizeof(uint8_t));
     
    752709        assert(kbd_dev->hid_dev != NULL);
    753710        assert(kbd_dev->hid_dev->initialized);
    754         //usbhid_req_set_protocol(kbd_dev->hid_dev, USB_HID_PROTOCOL_BOOT);
     711        usbhid_req_set_protocol(kbd_dev->hid_dev, USB_HID_PROTOCOL_BOOT);
    755712       
    756713        usbhid_kbd_set_led(kbd_dev);
Note: See TracChangeset for help on using the changeset viewer.