Changes in / [b8622e2:3a1aa20] in mainline


Ignore:
Location:
uspace
Files:
6 edited

Legend:

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

    rb8622e2 r3a1aa20  
    3636#include <io/keycode.h>
    3737#include <stdint.h>
     38#include <stdio.h>
     39#include <usb/debug.h>
    3840#include "conv.h"
    3941
     
    141143        //[0xe7] = KC_R // TODO: right GUI
    142144       
     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       
    143163};
    144164
     
    189209
    190210        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       
    191224//      if (key != 0)
    192225//              kbd_push_ev(type, key);
  • uspace/drv/usbhid/hid.h

    rb8622e2 r3a1aa20  
    3737#define USBHID_HID_H_
    3838
     39#include <stdint.h>
     40
    3941#include <usb/classes/hid.h>
    4042#include <ddf/driver.h>
     
    7476        usb_endpoint_pipe_t ctrl_pipe;
    7577        usb_endpoint_pipe_t poll_pipe;
     78       
     79        uint8_t *keycodes;
     80        size_t keycode_count;
     81        uint8_t modifiers;
    7682} usb_hid_dev_kbd_t;
    7783
  • uspace/drv/usbhid/main.c

    rb8622e2 r3a1aa20  
    5151#include <usb/descriptor.h>
    5252#include <io/console.h>
     53#include <stdint.h>
    5354#include "hid.h"
    5455#include "descparser.h"
     
    5859
    5960#define BUFFER_SIZE 8
     61#define BUFFER_OUT_SIZE 1
    6062#define NAME "usbhid"
    6163
    6264#define GUESSED_POLL_ENDPOINT 1
     65#define BOOTP_REPORT_SIZE 6
    6366
    6467/** Keyboard polling endpoint description for boot protocol class. */
     
    120123
    121124static void dump_buffer(const char *msg, const uint8_t *buffer, size_t length)
    122 {
     125{uint8_t buffer[BUFFER_SIZE];
    123126        printf("%s\n", msg);
    124127       
     
    137140 */
    138141
    139 /** Currently active modifiers.
     142/** Currently active modifiers (locks is probably better word).
    140143 *
    141144 * TODO: put to device?
     
    159162static int active_layout = 0;
    160163
    161 static void kbd_push_ev(int type, unsigned int key)
     164static 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
     197static 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
     230static 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
     264static void kbd_push_ev(int type, unsigned int key, usb_hid_dev_kbd_t *kbd_dev)
    162265{
    163266        console_event_t ev;
     
    183286
    184287        switch (key) {
    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;
     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;
    188291        default: mod_mask = 0; break;
    189292        }
    190293
    191294        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               
    192299                if (type == KEY_PRESS) {
     300                        usb_log_debug2("\nKey pressed.\n");
    193301                        /*
    194302                         * Only change lock state on transition from released
     
    200308
    201309                        /* Update keyboard lock indicator lights. */
    202                         // TODO
    203                         //kbd_ctl_set_ind(mods);
     310                        usbkbd_set_led(mods, kbd_dev);
    204311                } else {
     312                        usb_log_debug2("\nKey released.\n");
    205313                        lock_keys = lock_keys & ~mod_mask;
    206314                }
    207315        }
    208316/*
    209         printf("type: %d\n", type);
    210         printf("mods: 0x%x\n", mods);
    211         printf("keycode: %u\n", key);
     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);
    212320*/
     321        usb_log_debug2("\n\nmods after: 0x%x\n", mods);
     322        usb_log_debug2("\nLock keys after: 0x%x\n\n", lock_keys);
    213323       
    214324        if (type == KEY_PRESS && (mods & KM_LCTRL) &&
     
    236346        ev.key = key;
    237347        ev.mods = mods;
     348       
     349        if (ev.mods & KM_NUM_LOCK) {
     350                usb_log_debug("\n\nNum Lock turned on.\n\n");
     351        }
    238352
    239353        ev.c = layout[active_layout]->parse_ev(&ev);
    240354
    241         printf("Sending key %d to the console\n", ev.key);
     355        usb_log_debug2("Sending key %d to the console\n", ev.key);
    242356        assert(console_callback_phone != -1);
    243         async_msg_4(console_callback_phone, KBD_EVENT, ev.type, ev.key, ev.mods, ev.c);
     357        async_msg_4(console_callback_phone, KBD_EVENT, ev.type, ev.key,
     358            ev.mods, ev.c);
    244359}
    245360/*
     
    249364        /*
    250365         * TODO:
    251          * 1) key press / key release - how does the keyboard notify about release?
     366         * 1) key press / key release - how does the keyboard notify about
     367         *    release?
    252368         * 2) layouts (use the already defined), not important now
    253369         * 3)
    254370         */
    255371
     372static 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
     383static 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
     417static 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
    256474/*
    257475 * Callbacks for parser
     
    260478    uint8_t modifiers, void *arg)
    261479{
    262         printf("Got keys: ");
     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: ");
    263487        unsigned i;
    264488        for (i = 0; i < count; ++i) {
    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");
     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);
    281503}
    282504
     
    291513        for (i = 0; i < kbd_dev->conf->config_descriptor.interface_count; ++i) {
    292514                // TODO: endianness
    293                 uint16_t length =
    294                     kbd_dev->conf->interfaces[i].hid_desc.report_desc_info.length;
     515                uint16_t length =  kbd_dev->conf->interfaces[i].hid_desc.
     516                    report_desc_info.length;
    295517                size_t actual_size = 0;
    296518
    297519                // allocate space for the report descriptor
    298                 kbd_dev->conf->interfaces[i].report_desc = (uint8_t *)malloc(length);
     520                kbd_dev->conf->interfaces[i].report_desc =
     521                    (uint8_t *)malloc(length);
    299522               
    300523                // get the descriptor from the device
     
    317540        return EOK;
    318541}
     542
    319543static int usbkbd_process_descriptors(usb_hid_dev_kbd_t *kbd_dev)
    320544{
     
    375599        }
    376600
    377 
    378 
    379 
    380601        kbd_dev->conf = (usb_hid_configuration_t *)calloc(1,
    381602            sizeof(usb_hid_configuration_t));
     
    388609        free(descriptors);
    389610        if (rc != EOK) {
    390                 printf("Problem with parsing standard descriptors.\n");
     611                usb_log_warning("Problem with parsing standard descriptors.\n");
    391612                return rc;
    392613        }
     
    395616        rc = usbkbd_get_report_descriptor(kbd_dev);
    396617        if (rc != EOK) {
    397                 printf("Problem with parsing HID REPORT descriptor.\n");
     618                usb_log_warning("Problem with parsing REPORT descriptor.\n");
    398619                return rc;
    399620        }
     
    405626         * 1) select one configuration (lets say the first)
    406627         * 2) how many interfaces?? how to select one??
    407      *    ("The default setting for an interface is always alternate setting zero.")
     628         *    ("The default setting for an interface is always alternate
     629         *      setting zero.")
    408630         * 3) find endpoint which is IN and INTERRUPT (parse), save its number
    409     *    as the endpoint for polling
     631        *    as the endpoint for polling
    410632         */
    411633
     
    421643
    422644        if (kbd_dev == NULL) {
    423                 fprintf(stderr, NAME ": No memory!\n");
     645                usb_log_fatal("No memory!\n");
    424646                return NULL;
    425647        }
     
    457679        // TODO: get descriptors, parse descriptors and save endpoints
    458680        usb_endpoint_pipe_start_session(&kbd_dev->ctrl_pipe);
    459         //usb_request_set_configuration(&kbd_dev->ctrl_pipe, 1);
    460681        rc = usbkbd_process_descriptors(kbd_dev);
    461682        usb_endpoint_pipe_end_session(&kbd_dev->ctrl_pipe);
     
    463684                goto error_leave;
    464685        }
    465 
     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       
    466707        return kbd_dev;
    467708
     
    476717        usb_hid_report_in_callbacks_t *callbacks =
    477718            (usb_hid_report_in_callbacks_t *)malloc(
    478                 sizeof(usb_hid_report_in_callbacks_t));
     719                sizeof(usb_hid_report_in_callbacks_t));
    479720        callbacks->keyboard = usbkbd_process_keycodes;
    480721
    481722        //usb_hid_parse_report(kbd_dev->parser, buffer, actual_size, callbacks,
    482723        //    NULL);
    483         printf("Calling usb_hid_boot_keyboard_input_report() with size %zu\n",
    484             actual_size);
     724        /*usb_log_debug2("Calling usb_hid_boot_keyboard_input_report() with size"
     725            " %zu\n", actual_size);*/
    485726        //dump_buffer("bufffer: ", buffer, actual_size);
    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);
     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));
    490733        }
    491734}
     
    497740        size_t actual_size;
    498741
    499         printf("Polling keyboard...\n");
     742        usb_log_info("Polling keyboard...\n");
    500743
    501744        while (true) {
    502                 async_usleep(1000 * 10);
     745                async_usleep(1000 * 1000);
    503746
    504747                sess_rc = usb_endpoint_pipe_start_session(&kbd_dev->poll_pipe);
    505748                if (sess_rc != EOK) {
    506                         printf("Failed to start a session: %s.\n",
     749                        usb_log_warning("Failed to start a session: %s.\n",
    507750                            str_error(sess_rc));
    508751                        continue;
     
    514757
    515758                if (rc != EOK) {
    516                         printf("Error polling the keyboard: %s.\n",
     759                        usb_log_warning("Error polling the keyboard: %s.\n",
    517760                            str_error(rc));
    518761                        continue;
     
    520763
    521764                if (sess_rc != EOK) {
    522                         printf("Error closing session: %s.\n",
     765                        usb_log_warning("Error closing session: %s.\n",
    523766                            str_error(sess_rc));
    524767                        continue;
     
    530773                 */
    531774                if (actual_size == 0) {
    532                         printf("Keyboard returned NAK\n");
     775                        usb_log_debug("Keyboard returned NAK\n");
    533776                        continue;
    534777                }
     
    537780                 * TODO: Process pressed keys.
    538781                 */
    539                 printf("Calling usbkbd_process_interrupt_in()\n");
     782                usb_log_debug("Calling usbkbd_process_interrupt_in()\n");
    540783                usbkbd_process_interrupt_in(kbd_dev, buffer, actual_size);
    541784        }
     
    547790static int usbkbd_fibril_device(void *arg)
    548791{
    549         printf("!!! USB device fibril\n");
    550 
    551792        if (arg == NULL) {
    552                 printf("No device!\n");
     793                usb_log_error("No device!\n");
    553794                return -1;
    554795        }
    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         }
     796       
     797        usb_hid_dev_kbd_t *kbd_dev = (usb_hid_dev_kbd_t *)arg;
    564798
    565799        usbkbd_poll_keyboard(kbd_dev);
     
    570804static int usbkbd_add_device(ddf_dev_t *dev)
    571805{
    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 
    591806        /*
    592807         * Create default function.
     
    601816        rc = ddf_fun_add_to_class(kbd_fun, "keyboard");
    602817        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        }
    603827
    604828        /*
    605829         * Create new fibril for handling this keyboard
    606830         */
    607         fid_t fid = fibril_create(usbkbd_fibril_device, dev);
     831        fid_t fid = fibril_create(usbkbd_fibril_device, kbd_dev);
    608832        if (fid == 0) {
    609                 printf("%s: failed to start fibril for HID device\n", NAME);
     833                usb_log_error("Failed to start fibril for HID device\n");
    610834                return ENOMEM;
    611835        }
     
    634858int main(int argc, char *argv[])
    635859{
    636         usb_log_enable(USB_LOG_LEVEL_INFO, "usbhid");
     860        usb_log_enable(USB_LOG_LEVEL_MAX, NAME);
    637861        return ddf_driver_main(&kbd_driver);
    638862}
  • uspace/lib/usb/include/usb/classes/hid.h

    rb8622e2 r3a1aa20  
    5151} usb_hid_request_t;
    5252
     53typedef 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
     59typedef enum {
     60        USB_HID_PROTOCOL_BOOT = 0,
     61        USB_HID_PROTOCOL_REPORT = 1
     62} usb_hid_protocol_t;
     63
    5364/** USB/HID subclass constants. */
    5465typedef enum {
     
    6273        USB_HID_PROTOCOL_KEYBOARD = 1,
    6374        USB_HID_PROTOCOL_MOUSE = 2
    64 } usb_hid_protocol_t;
     75} usb_hid_iface_protocol_t;
    6576
    6677/** Part of standard USB HID descriptor specifying one class descriptor.
  • uspace/lib/usb/include/usb/classes/hidparser.h

    rb8622e2 r3a1aa20  
    7070} usb_hid_report_in_callbacks_t;
    7171
    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
     72
     73typedef 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
     85typedef 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
     94static 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
    77119
    78120/*
  • uspace/lib/usb/src/hidparser.c

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