Changes in / [3a1aa20:b8622e2] in mainline


Ignore:
Location:
uspace
Files:
6 edited

Legend:

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

    r3a1aa20 rb8622e2  
    3636#include <io/keycode.h>
    3737#include <stdint.h>
    38 #include <stdio.h>
    39 #include <usb/debug.h>
    4038#include "conv.h"
    4139
     
    143141        //[0xe7] = KC_R // TODO: right GUI
    144142       
    145         [0x53] = KC_NUM_LOCK,
    146         [0x54] = KC_NSLASH,
    147         [0x55] = KC_NTIMES,
    148         [0x56] = KC_NMINUS,
    149         [0x57] = KC_NPLUS,
    150         [0x58] = KC_NENTER,
    151         [0x59] = KC_N1,
    152         [0x5a] = KC_N2,
    153         [0x5b] = KC_N3,
    154         [0x5c] = KC_N4,
    155         [0x5d] = KC_N5,
    156         [0x5e] = KC_N6,
    157         [0x5f] = KC_N7,
    158         [0x60] = KC_N8,
    159         [0x61] = KC_N9,
    160         [0x62] = KC_N0,
    161         [0x63] = KC_NPERIOD
    162        
    163143};
    164144
     
    209189
    210190        key = map[scancode];
    211        
    212         if (scancode == 0x53) {
    213                 usb_log_debug("\n\nWe have a NUM LOCK!, sending key %u\n\n", key);
    214         }
    215        
    216         if (scancode == 0x47) {
    217                 usb_log_debug("\n\nWe have a SCROLL LOCK!, sending key %u\n\n", key);
    218         }
    219        
    220         if (scancode == 0x39) {
    221                 usb_log_debug("\n\nWe have a CAPS LOCK!, sending key %u\n\n", key);
    222         }
    223        
    224191//      if (key != 0)
    225192//              kbd_push_ev(type, key);
  • uspace/drv/usbhid/hid.h

    r3a1aa20 rb8622e2  
    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

    r3a1aa20 rb8622e2  
    5151#include <usb/descriptor.h>
    5252#include <io/console.h>
    53 #include <stdint.h>
    5453#include "hid.h"
    5554#include "descparser.h"
     
    5958
    6059#define BUFFER_SIZE 8
    61 #define BUFFER_OUT_SIZE 1
    6260#define NAME "usbhid"
    6361
    6462#define GUESSED_POLL_ENDPOINT 1
    65 #define BOOTP_REPORT_SIZE 6
    6663
    6764/** Keyboard polling endpoint description for boot protocol class. */
     
    123120
    124121static void dump_buffer(const char *msg, const uint8_t *buffer, size_t length)
    125 {uint8_t buffer[BUFFER_SIZE];
     122{
    126123        printf("%s\n", msg);
    127124       
     
    140137 */
    141138
    142 /** Currently active modifiers (locks is probably better word).
     139/** Currently active modifiers.
    143140 *
    144141 * TODO: put to device?
     
    162159static int active_layout = 0;
    163160
    164 static void usbkbd_req_set_report(usb_hid_dev_kbd_t *kbd_dev, uint16_t iface,
    165     usb_hid_report_type_t type, uint8_t *buffer, size_t buf_size)
    166 {
    167         int rc, sess_rc;
    168        
    169         sess_rc = usb_endpoint_pipe_start_session(&kbd_dev->ctrl_pipe);
    170         if (sess_rc != EOK) {
    171                 usb_log_warning("Failed to start a session: %s.\n",
    172                     str_error(sess_rc));
    173                 return;
    174         }
    175 
    176         usb_log_debug("Sending Set_Report request to the device.\n");
    177        
    178         rc = usb_control_request_set(&kbd_dev->ctrl_pipe,
    179             USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE,
    180             USB_HIDREQ_SET_REPORT, type, iface, buffer, buf_size);
    181 
    182         sess_rc = usb_endpoint_pipe_end_session(&kbd_dev->ctrl_pipe);
    183 
    184         if (rc != EOK) {
    185                 usb_log_warning("Error sending output report to the keyboard: "
    186                     "%s.\n", str_error(rc));
    187                 return;
    188         }
    189 
    190         if (sess_rc != EOK) {
    191                 usb_log_warning("Error closing session: %s.\n",
    192                     str_error(sess_rc));
    193                 return;
    194         }
    195 }
    196 
    197 static void usbkbd_req_set_protocol(usb_hid_dev_kbd_t *kbd_dev, uint16_t iface,
    198     usb_hid_protocol_t protocol)
    199 {
    200         int rc, sess_rc;
    201        
    202         sess_rc = usb_endpoint_pipe_start_session(&kbd_dev->ctrl_pipe);
    203         if (sess_rc != EOK) {
    204                 usb_log_warning("Failed to start a session: %s.\n",
    205                     str_error(sess_rc));
    206                 return;
    207         }
    208 
    209         usb_log_debug("Sending Set_Protocol request to the device.\n");
    210        
    211         rc = usb_control_request_set(&kbd_dev->ctrl_pipe,
    212             USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE,
    213             USB_HIDREQ_SET_PROTOCOL, protocol, iface, NULL, 0);
    214 
    215         sess_rc = usb_endpoint_pipe_end_session(&kbd_dev->ctrl_pipe);
    216 
    217         if (rc != EOK) {
    218                 usb_log_warning("Error sending output report to the keyboard: "
    219                     "%s.\n", str_error(rc));
    220                 return;
    221         }
    222 
    223         if (sess_rc != EOK) {
    224                 usb_log_warning("Error closing session: %s.\n",
    225                     str_error(sess_rc));
    226                 return;
    227         }
    228 }
    229 
    230 static void usbkbd_set_led(unsigned mods, usb_hid_dev_kbd_t *kbd_dev)
    231 {
    232         uint8_t buffer[BUFFER_SIZE];
    233         int rc= 0;
    234        
    235         uint8_t leds = 0;
    236 
    237         if (mods & KM_NUM_LOCK) {
    238                 leds |= USB_HID_LED_NUM_LOCK;
    239         }
    240        
    241         if (mods & KM_CAPS_LOCK) {
    242                 leds |= USB_HID_LED_CAPS_LOCK;
    243         }
    244        
    245         if (mods & KM_SCROLL_LOCK) {
    246                 leds |= USB_HID_LED_SCROLL_LOCK;
    247         }
    248 
    249         // TODO: COMPOSE and KANA
    250        
    251         usb_log_debug("Creating output report.\n");
    252         if ((rc = usb_hid_boot_keyboard_output_report(
    253             leds, buffer, BUFFER_SIZE)) != EOK) {
    254                 usb_log_warning("Error composing output report to the keyboard:"
    255                     "%s.\n", str_error(rc));
    256                 return;
    257         }
    258        
    259         // TODO: determine what interface to use!! (now set to 1)
    260         usbkbd_req_set_report(kbd_dev, 1, USB_HID_REPORT_TYPE_OUTPUT, buffer,
    261             BUFFER_SIZE);
    262 }
    263 
    264 static void kbd_push_ev(int type, unsigned int key, usb_hid_dev_kbd_t *kbd_dev)
     161static void kbd_push_ev(int type, unsigned int key)
    265162{
    266163        console_event_t ev;
     
    286183
    287184        switch (key) {
    288         case KC_CAPS_LOCK: mod_mask = KM_CAPS_LOCK; usb_log_debug2("\n\nPushing CAPS LOCK! (mask: %u)\n\n", mod_mask); break;
    289         case KC_NUM_LOCK: mod_mask = KM_NUM_LOCK; usb_log_debug2("\n\nPushing NUM LOCK! (mask: %u)\n\n", mod_mask); break;
    290         case KC_SCROLL_LOCK: mod_mask = KM_SCROLL_LOCK; usb_log_debug2("\n\nPushing SCROLL LOCK! (mask: %u)\n\n", mod_mask); break;
     185        case KC_CAPS_LOCK: mod_mask = KM_CAPS_LOCK; break;
     186        case KC_NUM_LOCK: mod_mask = KM_NUM_LOCK; break;
     187        case KC_SCROLL_LOCK: mod_mask = KM_SCROLL_LOCK; break;
    291188        default: mod_mask = 0; break;
    292189        }
    293190
    294191        if (mod_mask != 0) {
    295                 usb_log_debug2("\n\nChanging mods and lock keys\n");
    296                 usb_log_debug2("\nmods before: 0x%x\n", mods);
    297                 usb_log_debug2("\nLock keys before:0x%x\n\n", lock_keys);
    298                
    299192                if (type == KEY_PRESS) {
    300                         usb_log_debug2("\nKey pressed.\n");
    301193                        /*
    302194                         * Only change lock state on transition from released
     
    308200
    309201                        /* Update keyboard lock indicator lights. */
    310                         usbkbd_set_led(mods, kbd_dev);
     202                        // TODO
     203                        //kbd_ctl_set_ind(mods);
    311204                } else {
    312                         usb_log_debug2("\nKey released.\n");
    313205                        lock_keys = lock_keys & ~mod_mask;
    314206                }
    315207        }
    316208/*
    317         usb_log_debug2("type: %d\n", type);
    318         usb_log_debug2("mods: 0x%x\n", mods);
    319         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);
    320212*/
    321         usb_log_debug2("\n\nmods after: 0x%x\n", mods);
    322         usb_log_debug2("\nLock keys after: 0x%x\n\n", lock_keys);
    323213       
    324214        if (type == KEY_PRESS && (mods & KM_LCTRL) &&
     
    346236        ev.key = key;
    347237        ev.mods = mods;
    348        
    349         if (ev.mods & KM_NUM_LOCK) {
    350                 usb_log_debug("\n\nNum Lock turned on.\n\n");
    351         }
    352238
    353239        ev.c = layout[active_layout]->parse_ev(&ev);
    354240
    355         usb_log_debug2("Sending key %d to the console\n", ev.key);
     241        printf("Sending key %d to the console\n", ev.key);
    356242        assert(console_callback_phone != -1);
    357         async_msg_4(console_callback_phone, KBD_EVENT, ev.type, ev.key,
    358             ev.mods, ev.c);
     243        async_msg_4(console_callback_phone, KBD_EVENT, ev.type, ev.key, ev.mods, ev.c);
    359244}
    360245/*
     
    364249        /*
    365250         * TODO:
    366          * 1) key press / key release - how does the keyboard notify about
    367          *    release?
     251         * 1) key press / key release - how does the keyboard notify about release?
    368252         * 2) layouts (use the already defined), not important now
    369253         * 3)
    370254         */
    371255
    372 static const keycode_t usb_hid_modifiers_keycodes[USB_HID_MOD_COUNT] = {
    373         KC_LCTRL,         /* USB_HID_MOD_LCTRL */
    374         KC_LSHIFT,        /* USB_HID_MOD_LSHIFT */
    375         KC_LALT,          /* USB_HID_MOD_LALT */
    376         0,                /* USB_HID_MOD_LGUI */
    377         KC_RCTRL,         /* USB_HID_MOD_RCTRL */
    378         KC_RSHIFT,        /* USB_HID_MOD_RSHIFT */
    379         KC_RALT,          /* USB_HID_MOD_RALT */
    380         0,                /* USB_HID_MOD_RGUI */
    381 };
    382 
    383 static void usbkbd_check_modifier_changes(usb_hid_dev_kbd_t *kbd_dev,
    384     uint8_t modifiers)
    385 {
    386         /*
    387          * TODO: why the USB keyboard has NUM_, SCROLL_ and CAPS_LOCK
    388          *       both as modifiers and as keys with their own scancodes???
    389          *
    390          * modifiers should be sent as normal keys to usbkbd_parse_scancode()!!
    391          * so maybe it would be better if I received it from report parser in
    392          * that way
    393          */
    394        
    395         int i;
    396         for (i = 0; i < USB_HID_MOD_COUNT; ++i) {
    397                 if ((modifiers & usb_hid_modifiers_consts[i]) &&
    398                     !(kbd_dev->modifiers & usb_hid_modifiers_consts[i])) {
    399                         // modifier pressed
    400                         if (usb_hid_modifiers_keycodes[i] != 0) {
    401                                 kbd_push_ev(KEY_PRESS,
    402                                     usb_hid_modifiers_keycodes[i], kbd_dev);
    403                         }
    404                 } else if (!(modifiers & usb_hid_modifiers_consts[i]) &&
    405                     (kbd_dev->modifiers & usb_hid_modifiers_consts[i])) {
    406                         // modifier released
    407                         if (usb_hid_modifiers_keycodes[i] != 0) {
    408                                 kbd_push_ev(KEY_RELEASE,
    409                                     usb_hid_modifiers_keycodes[i], kbd_dev);
    410                         }
    411                 }       // no change
    412         }
    413        
    414         kbd_dev->modifiers = modifiers;
    415 }
    416 
    417 static void usbkbd_check_key_changes(usb_hid_dev_kbd_t *kbd_dev,
    418     const uint8_t *key_codes)
    419 {
    420         // TODO: phantom state!!
    421        
    422         unsigned int key;
    423         unsigned int i, j;
    424        
    425         // TODO: quite dummy right now, think of better implementation
    426        
    427         // key releases
    428         for (j = 0; j < kbd_dev->keycode_count; ++j) {
    429                 // try to find the old key in the new key list
    430                 i = 0;
    431                 while (i < kbd_dev->keycode_count
    432                     && key_codes[i] != kbd_dev->keycodes[j]) {
    433                         ++i;
    434                 }
    435                
    436                 if (i == kbd_dev->keycode_count) {
    437                         // not found, i.e. the key was released
    438                         key = usbkbd_parse_scancode(kbd_dev->keycodes[j]);
    439                         kbd_push_ev(KEY_RELEASE, key, kbd_dev);
    440                         usb_log_debug2("\nKey released: %d\n", key);
    441                 } else {
    442                         // found, nothing happens
    443                 }
    444         }
    445        
    446         // key presses
    447         for (i = 0; i < kbd_dev->keycode_count; ++i) {
    448                 // try to find the new key in the old key list
    449                 j = 0;
    450                 while (j < kbd_dev->keycode_count
    451                     && kbd_dev->keycodes[j] != key_codes[i]) {
    452                         ++j;
    453                 }
    454                
    455                 if (j == kbd_dev->keycode_count) {
    456                         // not found, i.e. new key pressed
    457                         key = usbkbd_parse_scancode(key_codes[i]);
    458                         usb_log_debug2("\nKey pressed: %d (keycode: %d)\n", key,
    459                             key_codes[i]);
    460                         kbd_push_ev(KEY_PRESS, key, kbd_dev);
    461                 } else {
    462                         // found, nothing happens
    463                 }
    464         }
    465        
    466         memcpy(kbd_dev->keycodes, key_codes, kbd_dev->keycode_count);
    467        
    468         usb_log_debug2("\nNew stored keycodes: ");
    469         for (i = 0; i < kbd_dev->keycode_count; ++i) {
    470                 usb_log_debug2("%d ", kbd_dev->keycodes[i]);
    471         }
    472 }
    473 
    474256/*
    475257 * Callbacks for parser
     
    478260    uint8_t modifiers, void *arg)
    479261{
    480         if (arg == NULL) {
    481                 usb_log_warning("Missing argument in callback "
    482                     "usbkbd_process_keycodes().\n");
    483                 return;
    484         }
    485 
    486         usb_log_debug2("Got keys from parser: ");
     262        printf("Got keys: ");
    487263        unsigned i;
    488264        for (i = 0; i < count; ++i) {
    489                 usb_log_debug2("%d ", key_codes[i]);
    490         }
    491         usb_log_debug2("\n");
    492        
    493         usb_hid_dev_kbd_t *kbd_dev = (usb_hid_dev_kbd_t *)arg;
    494        
    495         if (count != kbd_dev->keycode_count) {
    496                 usb_log_warning("Number of received keycodes (%d) differs from"
    497                     " expected number (%d).\n", count, kbd_dev->keycode_count);
    498                 return;
    499         }
    500        
    501         usbkbd_check_modifier_changes(kbd_dev, modifiers);
    502         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");
    503281}
    504282
     
    513291        for (i = 0; i < kbd_dev->conf->config_descriptor.interface_count; ++i) {
    514292                // TODO: endianness
    515                 uint16_t length =  kbd_dev->conf->interfaces[i].hid_desc.
    516                     report_desc_info.length;
     293                uint16_t length =
     294                    kbd_dev->conf->interfaces[i].hid_desc.report_desc_info.length;
    517295                size_t actual_size = 0;
    518296
    519297                // allocate space for the report descriptor
    520                 kbd_dev->conf->interfaces[i].report_desc =
    521                     (uint8_t *)malloc(length);
     298                kbd_dev->conf->interfaces[i].report_desc = (uint8_t *)malloc(length);
    522299               
    523300                // get the descriptor from the device
     
    540317        return EOK;
    541318}
    542 
    543319static int usbkbd_process_descriptors(usb_hid_dev_kbd_t *kbd_dev)
    544320{
     
    599375        }
    600376
     377
     378
     379
    601380        kbd_dev->conf = (usb_hid_configuration_t *)calloc(1,
    602381            sizeof(usb_hid_configuration_t));
     
    609388        free(descriptors);
    610389        if (rc != EOK) {
    611                 usb_log_warning("Problem with parsing standard descriptors.\n");
     390                printf("Problem with parsing standard descriptors.\n");
    612391                return rc;
    613392        }
     
    616395        rc = usbkbd_get_report_descriptor(kbd_dev);
    617396        if (rc != EOK) {
    618                 usb_log_warning("Problem with parsing REPORT descriptor.\n");
     397                printf("Problem with parsing HID REPORT descriptor.\n");
    619398                return rc;
    620399        }
     
    626405         * 1) select one configuration (lets say the first)
    627406         * 2) how many interfaces?? how to select one??
    628          *    ("The default setting for an interface is always alternate
    629          *      setting zero.")
     407     *    ("The default setting for an interface is always alternate setting zero.")
    630408         * 3) find endpoint which is IN and INTERRUPT (parse), save its number
    631         *    as the endpoint for polling
     409    *    as the endpoint for polling
    632410         */
    633411
     
    643421
    644422        if (kbd_dev == NULL) {
    645                 usb_log_fatal("No memory!\n");
     423                fprintf(stderr, NAME ": No memory!\n");
    646424                return NULL;
    647425        }
     
    679457        // TODO: get descriptors, parse descriptors and save endpoints
    680458        usb_endpoint_pipe_start_session(&kbd_dev->ctrl_pipe);
     459        //usb_request_set_configuration(&kbd_dev->ctrl_pipe, 1);
    681460        rc = usbkbd_process_descriptors(kbd_dev);
    682461        usb_endpoint_pipe_end_session(&kbd_dev->ctrl_pipe);
     
    684463                goto error_leave;
    685464        }
    686        
    687         // save the size of the report
    688         kbd_dev->keycode_count = BOOTP_REPORT_SIZE;
    689         kbd_dev->keycodes = (uint8_t *)calloc(
    690             kbd_dev->keycode_count, sizeof(uint8_t));
    691        
    692         if (kbd_dev->keycodes == NULL) {
    693                 usb_log_fatal("No memory!\n");
    694                 goto error_leave;
    695         }
    696        
    697         // set configuration to the first one
    698         // TODO: handle case with no configurations
    699         usb_endpoint_pipe_start_session(&kbd_dev->ctrl_pipe);
    700         usb_request_set_configuration(&kbd_dev->ctrl_pipe,
    701             kbd_dev->conf->config_descriptor.configuration_number);
    702         usb_endpoint_pipe_end_session(&kbd_dev->ctrl_pipe);
    703        
    704         // set boot protocol
    705         usbkbd_req_set_protocol(kbd_dev, 1, USB_HID_PROTOCOL_BOOT);
    706        
     465
    707466        return kbd_dev;
    708467
     
    717476        usb_hid_report_in_callbacks_t *callbacks =
    718477            (usb_hid_report_in_callbacks_t *)malloc(
    719                 sizeof(usb_hid_report_in_callbacks_t));
     478                sizeof(usb_hid_report_in_callbacks_t));
    720479        callbacks->keyboard = usbkbd_process_keycodes;
    721480
    722481        //usb_hid_parse_report(kbd_dev->parser, buffer, actual_size, callbacks,
    723482        //    NULL);
    724         /*usb_log_debug2("Calling usb_hid_boot_keyboard_input_report() with size"
    725             " %zu\n", actual_size);*/
     483        printf("Calling usb_hid_boot_keyboard_input_report() with size %zu\n",
     484            actual_size);
    726485        //dump_buffer("bufffer: ", buffer, actual_size);
    727         int rc = usb_hid_boot_keyboard_input_report(buffer, actual_size,
    728             callbacks, kbd_dev);
    729        
    730         if (rc != EOK) {
    731                 usb_log_warning("Error in usb_hid_boot_keyboard_input_report():"
    732                     "%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);
    733490        }
    734491}
     
    740497        size_t actual_size;
    741498
    742         usb_log_info("Polling keyboard...\n");
     499        printf("Polling keyboard...\n");
    743500
    744501        while (true) {
    745                 async_usleep(1000 * 1000);
     502                async_usleep(1000 * 10);
    746503
    747504                sess_rc = usb_endpoint_pipe_start_session(&kbd_dev->poll_pipe);
    748505                if (sess_rc != EOK) {
    749                         usb_log_warning("Failed to start a session: %s.\n",
     506                        printf("Failed to start a session: %s.\n",
    750507                            str_error(sess_rc));
    751508                        continue;
     
    757514
    758515                if (rc != EOK) {
    759                         usb_log_warning("Error polling the keyboard: %s.\n",
     516                        printf("Error polling the keyboard: %s.\n",
    760517                            str_error(rc));
    761518                        continue;
     
    763520
    764521                if (sess_rc != EOK) {
    765                         usb_log_warning("Error closing session: %s.\n",
     522                        printf("Error closing session: %s.\n",
    766523                            str_error(sess_rc));
    767524                        continue;
     
    773530                 */
    774531                if (actual_size == 0) {
    775                         usb_log_debug("Keyboard returned NAK\n");
     532                        printf("Keyboard returned NAK\n");
    776533                        continue;
    777534                }
     
    780537                 * TODO: Process pressed keys.
    781538                 */
    782                 usb_log_debug("Calling usbkbd_process_interrupt_in()\n");
     539                printf("Calling usbkbd_process_interrupt_in()\n");
    783540                usbkbd_process_interrupt_in(kbd_dev, buffer, actual_size);
    784541        }
     
    790547static int usbkbd_fibril_device(void *arg)
    791548{
     549        printf("!!! USB device fibril\n");
     550
    792551        if (arg == NULL) {
    793                 usb_log_error("No device!\n");
     552                printf("No device!\n");
    794553                return -1;
    795554        }
    796        
    797         usb_hid_dev_kbd_t *kbd_dev = (usb_hid_dev_kbd_t *)arg;
     555
     556        ddf_dev_t *dev = (ddf_dev_t *)arg;
     557
     558        // initialize device (get and process descriptors, get address, etc.)
     559        usb_hid_dev_kbd_t *kbd_dev = usbkbd_init_device(dev);
     560        if (kbd_dev == NULL) {
     561                printf("Error while initializing device.\n");
     562                return -1;
     563        }
    798564
    799565        usbkbd_poll_keyboard(kbd_dev);
     
    804570static int usbkbd_add_device(ddf_dev_t *dev)
    805571{
     572        /* For now, fail immediately. */
     573        //return ENOTSUP;
     574
     575        /*
     576         * When everything is okay, connect to "our" HC.
     577         *
     578         * Not supported yet, skip..
     579         */
     580//      int phone = usb_drv_hc_connect_auto(dev, 0);
     581//      if (phone < 0) {
     582//              /*
     583//               * Connecting to HC failed, roll-back and announce
     584//               * failure.
     585//               */
     586//              return phone;
     587//      }
     588
     589//      dev->parent_phone = phone;
     590
    806591        /*
    807592         * Create default function.
     
    816601        rc = ddf_fun_add_to_class(kbd_fun, "keyboard");
    817602        assert(rc == EOK);
    818        
    819         /*
    820          * Initialize device (get and process descriptors, get address, etc.)
    821          */
    822         usb_hid_dev_kbd_t *kbd_dev = usbkbd_init_device(dev);
    823         if (kbd_dev == NULL) {
    824                 usb_log_error("Error while initializing device.\n");
    825                 return -1;
    826         }
    827603
    828604        /*
    829605         * Create new fibril for handling this keyboard
    830606         */
    831         fid_t fid = fibril_create(usbkbd_fibril_device, kbd_dev);
     607        fid_t fid = fibril_create(usbkbd_fibril_device, dev);
    832608        if (fid == 0) {
    833                 usb_log_error("Failed to start fibril for HID device\n");
     609                printf("%s: failed to start fibril for HID device\n", NAME);
    834610                return ENOMEM;
    835611        }
     
    858634int main(int argc, char *argv[])
    859635{
    860         usb_log_enable(USB_LOG_LEVEL_MAX, NAME);
     636        usb_log_enable(USB_LOG_LEVEL_INFO, "usbhid");
    861637        return ddf_driver_main(&kbd_driver);
    862638}
  • uspace/lib/usb/include/usb/classes/hid.h

    r3a1aa20 rb8622e2  
    5151} usb_hid_request_t;
    5252
    53 typedef enum {
    54         USB_HID_REPORT_TYPE_INPUT = 1,
    55         USB_HID_REPORT_TYPE_OUTPUT = 2,
    56         USB_HID_REPORT_TYPE_FEATURE = 3
    57 } usb_hid_report_type_t;
    58 
    59 typedef enum {
    60         USB_HID_PROTOCOL_BOOT = 0,
    61         USB_HID_PROTOCOL_REPORT = 1
    62 } usb_hid_protocol_t;
    63 
    6453/** USB/HID subclass constants. */
    6554typedef enum {
     
    7362        USB_HID_PROTOCOL_KEYBOARD = 1,
    7463        USB_HID_PROTOCOL_MOUSE = 2
    75 } usb_hid_iface_protocol_t;
     64} usb_hid_protocol_t;
    7665
    7766/** Part of standard USB HID descriptor specifying one class descriptor.
  • uspace/lib/usb/include/usb/classes/hidparser.h

    r3a1aa20 rb8622e2  
    7070} usb_hid_report_in_callbacks_t;
    7171
    72 
    73 typedef enum {
    74         USB_HID_MOD_LCTRL = 0x01,
    75         USB_HID_MOD_LSHIFT = 0x02,
    76         USB_HID_MOD_LALT = 0x04,
    77         USB_HID_MOD_LGUI = 0x08,
    78         USB_HID_MOD_RCTRL = 0x10,
    79         USB_HID_MOD_RSHIFT = 0x20,
    80         USB_HID_MOD_RALT = 0x40,
    81         USB_HID_MOD_RGUI = 0x80,
    82         USB_HID_MOD_COUNT = 8
    83 } usb_hid_modifiers_t;
    84 
    85 typedef enum {
    86         USB_HID_LED_NUM_LOCK = 0x1,
    87         USB_HID_LED_CAPS_LOCK = 0x2,
    88         USB_HID_LED_SCROLL_LOCK = 0x4,
    89         USB_HID_LED_COMPOSE = 0x8,
    90         USB_HID_LED_KANA = 0x10,
    91         USB_HID_LED_COUNT = 5
    92 } usb_hid_led_t;
    93 
    94 static const usb_hid_modifiers_t
    95     usb_hid_modifiers_consts[USB_HID_MOD_COUNT] = {
    96         USB_HID_MOD_LCTRL,
    97         USB_HID_MOD_LSHIFT,
    98         USB_HID_MOD_LALT,
    99         USB_HID_MOD_LGUI,
    100         USB_HID_MOD_RCTRL,
    101         USB_HID_MOD_RSHIFT,
    102         USB_HID_MOD_RALT,
    103         USB_HID_MOD_RGUI
    104 };
    105 
    106 //static const usb_hid_led_t usb_hid_led_consts[USB_HID_LED_COUNT] = {
    107 //      USB_HID_LED_NUM_LOCK,
    108 //      USB_HID_LED_CAPS_LOCK,
    109 //      USB_HID_LED_SCROLL_LOCK,
    110 //      USB_HID_LED_COMPOSE,
    111 //      USB_HID_LED_KANA
    112 //};
    113 
    114 //#define USB_HID_BOOT_KEYBOARD_NUM_LOCK                0x01
    115 //#define USB_HID_BOOT_KEYBOARD_CAPS_LOCK               0x02
    116 //#define USB_HID_BOOT_KEYBOARD_SCROLL_LOCK     0x04
    117 //#define USB_HID_BOOT_KEYBOARD_COMPOSE         0x08
    118 //#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
    11977
    12078/*
  • uspace/lib/usb/src/hidparser.c

    r3a1aa20 rb8622e2  
    144144int usb_hid_boot_keyboard_output_report(uint8_t leds, uint8_t *data, size_t size)
    145145{
    146         if(size < 2){
     146        if(size != 1){
    147147                return -1;
    148148        }
    149149
    150         data[1] = leds;
     150        /* used only first five bits, others are only padding*/
     151        *data = leds;
    151152        return EOK;
    152153}
Note: See TracChangeset for help on using the changeset viewer.