Changes in / [92574f4:a80849c] in mainline


Ignore:
Location:
uspace
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/usbhid/hid.h

    r92574f4 ra80849c  
    3737#define USBHID_HID_H_
    3838
    39 #include <stdint.h>
    40 
    4139#include <usb/classes/hid.h>
    4240#include <ddf/driver.h>
     
    7674        usb_endpoint_pipe_t ctrl_pipe;
    7775        usb_endpoint_pipe_t poll_pipe;
    78        
    79         uint8_t *keycodes;
    80         size_t keycode_count;
    81         uint8_t modifiers;
    8276} usb_hid_dev_kbd_t;
    8377
  • uspace/drv/usbhid/main.c

    r92574f4 ra80849c  
    5151#include <usb/descriptor.h>
    5252#include <io/console.h>
    53 #include <stdint.h>
    5453#include "hid.h"
    5554#include "descparser.h"
     
    6261
    6362#define GUESSED_POLL_ENDPOINT 1
    64 #define BOOTP_REPORT_SIZE 6
    6563
    6664/** Keyboard polling endpoint description for boot protocol class. */
     
    209207        }
    210208/*
    211         usb_log_debug2("type: %d\n", type);
    212         usb_log_debug2("mods: 0x%x\n", mods);
    213         usb_log_debug2("keycode: %u\n", key);
     209        printf("type: %d\n", type);
     210        printf("mods: 0x%x\n", mods);
     211        printf("keycode: %u\n", key);
    214212*/
    215213       
     
    241239        ev.c = layout[active_layout]->parse_ev(&ev);
    242240
    243         usb_log_debug("Sending key %d to the console\n", ev.key);
     241        printf("Sending key %d to the console\n", ev.key);
    244242        assert(console_callback_phone != -1);
    245         async_msg_4(console_callback_phone, KBD_EVENT, ev.type, ev.key,
    246             ev.mods, ev.c);
     243        async_msg_4(console_callback_phone, KBD_EVENT, ev.type, ev.key, ev.mods, ev.c);
    247244}
    248245/*
     
    252249        /*
    253250         * TODO:
    254          * 1) key press / key release - how does the keyboard notify about
    255          *    release?
     251         * 1) key press / key release - how does the keyboard notify about release?
    256252         * 2) layouts (use the already defined), not important now
    257253         * 3)
    258254         */
    259255
    260 static const keycode_t usb_hid_modifiers_boot_keycodes[5] = {
    261         KC_NUM_LOCK,      /* USB_HID_MOD_BOOT_NUM_LOCK */
    262         KC_CAPS_LOCK,     /* USB_HID_MOD_BOOT_CAPS_LOCK */
    263         KC_SCROLL_LOCK,   /* USB_HID_MOD_BOOT_SCROLL_LOCK */
    264         0,                /* USB_HID_MOD_BOOT_COMPOSE */
    265         0                 /* USB_HID_MOD_BOOT_KANA */
    266 };
    267 
    268 static void usbkbd_check_modifier_changes(usb_hid_dev_kbd_t *kbd_dev,
    269     uint8_t modifiers)
    270 {
    271         /*
    272          * TODO: why the USB keyboard has NUM_, SCROLL_ and CAPS_LOCK
    273          *       both as modifiers and as keys with their own scancodes???
    274          *
    275          * modifiers should be sent as normal keys to usbkbd_parse_scancode()!!
    276          * so maybe it would be better if I received it from report parser in
    277          * that way
    278          */
    279        
    280         int i;
    281         for (i = 0; i < USB_HID_MOD_BOOT_COUNT; ++i) {
    282                 if ((modifiers & usb_hid_modifiers_boot_consts[i]) &&
    283                     !(kbd_dev->modifiers & usb_hid_modifiers_boot_consts[i])) {
    284                         // modifier pressed
    285                         if (usb_hid_modifiers_boot_keycodes[i] != 0) {
    286                                 kbd_push_ev(KEY_PRESS,
    287                                     usb_hid_modifiers_boot_keycodes[i]);
    288                         }
    289                 } else if (!(modifiers & usb_hid_modifiers_boot_consts[i]) &&
    290                     (kbd_dev->modifiers & usb_hid_modifiers_boot_consts[i])) {
    291                         // modifier released
    292                         if (usb_hid_modifiers_boot_keycodes[i] != 0) {
    293                                 kbd_push_ev(KEY_RELEASE,
    294                                     usb_hid_modifiers_boot_keycodes[i]);
    295                         }
    296                 }       // no change
    297         }
    298 }
    299 
    300 static void usbkbd_check_key_changes(usb_hid_dev_kbd_t *kbd_dev,
    301     const uint8_t *key_codes)
    302 {
    303         // TODO: phantom state!!
    304        
    305         unsigned int key;
    306         unsigned int i, j;
    307        
    308         // TODO: quite dummy right now, think of better implementation
    309        
    310         // key releases
    311         for (j = 0; j < kbd_dev->keycode_count; ++j) {
    312                 // try to find the old key in the new key list
    313                 i = 0;
    314                 while (i < kbd_dev->keycode_count
    315                     && key_codes[i] != kbd_dev->keycodes[j]) {
    316                         ++j;
    317                 }
    318                
    319                 if (j == kbd_dev->keycode_count) {
    320                         // not found, i.e. the key was released
    321                         key = usbkbd_parse_scancode(kbd_dev->keycodes[j]);
    322                         kbd_push_ev(KEY_RELEASE, key);
    323                 } else {
    324                         // found, nothing happens
    325                 }
    326         }
    327        
    328         // key presses
    329         for (i = 0; i < kbd_dev->keycode_count; ++i) {
    330                 // try to find the new key in the old key list
    331                 j = 0;
    332                 while (j < kbd_dev->keycode_count
    333                     && kbd_dev->keycodes[j] != key_codes[i]) {
    334                         ++j;
    335                 }
    336                
    337                 assert(kbd_dev->keycode_count <= kbd_dev->keycode_count);
    338                
    339                 if (j == kbd_dev->keycode_count) {
    340                         // not found, i.e. new key pressed
    341                         key = usbkbd_parse_scancode(key_codes[i]);
    342                         kbd_push_ev(KEY_PRESS, key);
    343                 } else {
    344                         // found, nothing happens
    345                 }
    346         }
    347 }
    348 
    349256/*
    350257 * Callbacks for parser
     
    353260    uint8_t modifiers, void *arg)
    354261{
    355         if (arg == NULL) {
    356                 usb_log_warning("Missing argument in callback "
    357                     "usbkbd_process_keycodes().\n");
    358                 return;
    359         }
    360 
    361         usb_log_debug2("Got keys from parser: ");
     262        printf("Got keys: ");
    362263        unsigned i;
    363264        for (i = 0; i < count; ++i) {
    364                 usb_log_debug2("%d ", key_codes[i]);
    365         }
    366         usb_log_debug2("\n");
    367        
    368         usb_hid_dev_kbd_t *kbd_dev = (usb_hid_dev_kbd_t *)arg;
    369        
    370         if (count != kbd_dev->keycode_count) {
    371                 usb_log_warning("Number of received keycodes (%d) differs from"
    372                     " expected number (%d).\n", count, kbd_dev->keycode_count);
    373                 return;
    374         }
    375        
    376         usbkbd_check_modifier_changes(kbd_dev, modifiers);
    377         usbkbd_check_key_changes(kbd_dev, key_codes);
     265                printf("%d ", key_codes[i]);
     266        }
     267        printf("\n");
     268
     269        for (i = 0; i < count; ++i) {
     270                // TODO: Key press / release
     271
     272                // TODO: NOT WORKING
     273                unsigned int key = usbkbd_parse_scancode(key_codes[i]);
     274
     275                if (key == 0) {
     276                        continue;
     277                }
     278                kbd_push_ev(KEY_PRESS, key);
     279        }
     280        printf("\n");
    378281}
    379282
     
    388291        for (i = 0; i < kbd_dev->conf->config_descriptor.interface_count; ++i) {
    389292                // TODO: endianness
    390                 uint16_t length =  kbd_dev->conf->interfaces[i].hid_desc.
    391                     report_desc_info.length;
     293                uint16_t length =
     294                    kbd_dev->conf->interfaces[i].hid_desc.report_desc_info.length;
    392295                size_t actual_size = 0;
    393296
    394297                // allocate space for the report descriptor
    395                 kbd_dev->conf->interfaces[i].report_desc =
    396                     (uint8_t *)malloc(length);
     298                kbd_dev->conf->interfaces[i].report_desc = (uint8_t *)malloc(length);
    397299               
    398300                // get the descriptor from the device
     
    415317        return EOK;
    416318}
    417 
    418319static int usbkbd_process_descriptors(usb_hid_dev_kbd_t *kbd_dev)
    419320{
     
    487388        free(descriptors);
    488389        if (rc != EOK) {
    489                 usb_log_warning("Problem with parsing standard descriptors.\n");
     390                printf("Problem with parsing standard descriptors.\n");
    490391                return rc;
    491392        }
     
    494395        rc = usbkbd_get_report_descriptor(kbd_dev);
    495396        if (rc != EOK) {
    496                 usb_log_warning("Problem with parsing REPORT descriptor.\n");
     397                printf("Problem with parsing HID REPORT descriptor.\n");
    497398                return rc;
    498399        }
     
    504405         * 1) select one configuration (lets say the first)
    505406         * 2) how many interfaces?? how to select one??
    506          *    ("The default setting for an interface is always alternate
    507          *      setting zero.")
     407     *    ("The default setting for an interface is always alternate setting zero.")
    508408         * 3) find endpoint which is IN and INTERRUPT (parse), save its number
    509         *    as the endpoint for polling
     409    *    as the endpoint for polling
    510410         */
    511411
     
    521421
    522422        if (kbd_dev == NULL) {
    523                 usb_log_fatal("No memory!\n");
     423                fprintf(stderr, NAME ": No memory!\n");
    524424                return NULL;
    525425        }
     
    576476        usb_hid_report_in_callbacks_t *callbacks =
    577477            (usb_hid_report_in_callbacks_t *)malloc(
    578                 sizeof(usb_hid_report_in_callbacks_t));
     478                sizeof(usb_hid_report_in_callbacks_t));
    579479        callbacks->keyboard = usbkbd_process_keycodes;
    580480
    581481        //usb_hid_parse_report(kbd_dev->parser, buffer, actual_size, callbacks,
    582482        //    NULL);
    583         /*usb_log_debug2("Calling usb_hid_boot_keyboard_input_report() with size"
    584             " %zu\n", actual_size);*/
     483        printf("Calling usb_hid_boot_keyboard_input_report() with size %zu\n",
     484            actual_size);
    585485        //dump_buffer("bufffer: ", buffer, actual_size);
    586         int rc = usb_hid_boot_keyboard_input_report(buffer, actual_size,
    587             callbacks, kbd_dev);
    588        
    589         if (rc != EOK) {
    590                 usb_log_warning("Error in usb_hid_boot_keyboard_input_report():"
    591                     "%s\n", str_error(rc));
     486        int rc = usb_hid_boot_keyboard_input_report(buffer, actual_size, callbacks,
     487            NULL);
     488        if (rc != EOK) {
     489                printf("Error in usb_hid_boot_keyboard_input_report(): %d\n", rc);
    592490        }
    593491}
     
    599497        size_t actual_size;
    600498
    601         usb_log_info("Polling keyboard...\n");
     499        printf("Polling keyboard...\n");
    602500
    603501        while (true) {
     
    606504                sess_rc = usb_endpoint_pipe_start_session(&kbd_dev->poll_pipe);
    607505                if (sess_rc != EOK) {
    608                         usb_log_warning("Failed to start a session: %s.\n",
     506                        printf("Failed to start a session: %s.\n",
    609507                            str_error(sess_rc));
    610508                        continue;
     
    616514
    617515                if (rc != EOK) {
    618                         usb_log_warning("Error polling the keyboard: %s.\n",
     516                        printf("Error polling the keyboard: %s.\n",
    619517                            str_error(rc));
    620518                        continue;
     
    622520
    623521                if (sess_rc != EOK) {
    624                         usb_log_warning("Error closing session: %s.\n",
     522                        printf("Error closing session: %s.\n",
    625523                            str_error(sess_rc));
    626524                        continue;
     
    632530                 */
    633531                if (actual_size == 0) {
    634                         usb_log_debug("Keyboard returned NAK\n");
     532                        printf("Keyboard returned NAK\n");
    635533                        continue;
    636534                }
     
    639537                 * TODO: Process pressed keys.
    640538                 */
    641                 usb_log_debug("Calling usbkbd_process_interrupt_in()\n");
     539                printf("Calling usbkbd_process_interrupt_in()\n");
    642540                usbkbd_process_interrupt_in(kbd_dev, buffer, actual_size);
    643541        }
     
    649547static int usbkbd_fibril_device(void *arg)
    650548{
     549        printf("!!! USB device fibril\n");
     550
    651551        if (arg == NULL) {
    652                 usb_log_error("No device!\n");
     552                printf("No device!\n");
    653553                return -1;
    654554        }
     
    659559        usb_hid_dev_kbd_t *kbd_dev = usbkbd_init_device(dev);
    660560        if (kbd_dev == NULL) {
    661                 usb_log_error("Error while initializing device.\n");
     561                printf("Error while initializing device.\n");
    662562                return -1;
    663563        }
     
    707607        fid_t fid = fibril_create(usbkbd_fibril_device, dev);
    708608        if (fid == 0) {
    709                 usb_log_error("Failed to start fibril for HID device\n");
     609                printf("%s: failed to start fibril for HID device\n", NAME);
    710610                return ENOMEM;
    711611        }
     
    734634int main(int argc, char *argv[])
    735635{
    736         usb_log_enable(USB_LOG_LEVEL_MAX, NAME);
     636        usb_log_enable(USB_LOG_LEVEL_INFO, "usbhid");
    737637        return ddf_driver_main(&kbd_driver);
    738638}
  • uspace/lib/usb/include/usb/classes/hidparser.h

    r92574f4 ra80849c  
    7070} usb_hid_report_in_callbacks_t;
    7171
    72 
    73 typedef enum {
    74         USB_HID_MOD_BOOT_NUM_LOCK = 0x01,
    75         USB_HID_MOD_BOOT_CAPS_LOCK = 0x02,
    76         USB_HID_MOD_BOOT_SCROLL_LOCK = 0x04,
    77         USB_HID_MOD_BOOT_COMPOSE = 0x08,
    78         USB_HID_MOD_BOOT_KANA = 0x10,
    79         USB_HID_MOD_BOOT_COUNT = 5
    80 } usb_hid_modifiers_boot_t;
    81 
    82 static const usb_hid_modifiers_boot_t usb_hid_modifiers_boot_consts[5] = {
    83         USB_HID_MOD_BOOT_NUM_LOCK,
    84         USB_HID_MOD_BOOT_CAPS_LOCK,
    85         USB_HID_MOD_BOOT_SCROLL_LOCK,
    86         USB_HID_MOD_BOOT_COMPOSE,
    87         USB_HID_MOD_BOOT_KANA
    88 };
    89 
    90 //#define USB_HID_BOOT_KEYBOARD_NUM_LOCK                0x01
    91 //#define USB_HID_BOOT_KEYBOARD_CAPS_LOCK               0x02
    92 //#define USB_HID_BOOT_KEYBOARD_SCROLL_LOCK     0x04
    93 //#define USB_HID_BOOT_KEYBOARD_COMPOSE         0x08
    94 //#define USB_HID_BOOT_KEYBOARD_KANA                    0x10
     72#define USB_HID_BOOT_KEYBOARD_NUM_LOCK          0x01
     73#define USB_HID_BOOT_KEYBOARD_CAPS_LOCK         0x02
     74#define USB_HID_BOOT_KEYBOARD_SCROLL_LOCK       0x04
     75#define USB_HID_BOOT_KEYBOARD_COMPOSE           0x08
     76#define USB_HID_BOOT_KEYBOARD_KANA                      0x10
    9577
    9678/*
Note: See TracChangeset for help on using the changeset viewer.