Changeset df6ded8 in mainline for uspace/drv/hid/usbhid/kbd/kbddev.c


Ignore:
Timestamp:
2018-02-28T16:37:50Z (6 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1b20da0
Parents:
f5e5f73 (diff), b2dca8de (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
git-author:
Jakub Jermar <jakub@…> (2018-02-28 16:06:42)
git-committer:
Jakub Jermar <jakub@…> (2018-02-28 16:37:50)
Message:

Merge github.com:helenos-xhci-team/helenos

This commit merges support for USB 3 and generally refactors, fixes,
extends and cleans up the existing USB framework.

Notable additions and features:

  • new host controller driver has been implemented to control various xHC models (among others, NEC Renesas uPD720200)
  • isochronous data transfer mode
  • support for explicit USB device removal
  • USB tablet driver
File:
1 edited

Legend:

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

    rf5e5f73 rdf6ded8  
    11/*
    22 * Copyright (c) 2011 Lubos Slovak
     3 * Copyright (c) 2018 Ondrej Hlavaty
    34 * All rights reserved.
    45 *
     
    185186                if (kbd_dev->client_sess == NULL) {
    186187                        kbd_dev->client_sess = sess;
    187                         usb_log_debug("%s: OK\n", __FUNCTION__);
     188                        usb_log_debug("%s: OK", __FUNCTION__);
    188189                        async_answer_0(icallid, EOK);
    189190                } else {
    190                         usb_log_error("%s: console session already set\n",
     191                        usb_log_error("%s: console session already set",
    191192                           __FUNCTION__);
    192193                        async_answer_0(icallid, ELIMIT);
     
    195196        }
    196197        default:
    197                         usb_log_error("%s: Unknown method: %d.\n",
     198                        usb_log_error("%s: Unknown method: %d.",
    198199                            __FUNCTION__, (int) method);
    199200                        async_answer_0(icallid, EINVAL);
     
    226227        /* Reset the LED data. */
    227228        memset(kbd_dev->led_data, 0, kbd_dev->led_output_size * sizeof(int32_t));
    228         usb_log_debug("Creating output report:\n");
     229        usb_log_debug("Creating output report:");
    229230
    230231        usb_hid_report_field_t *field = usb_hid_report_get_sibling(
     
    266267        }
    267268
    268         usb_log_debug("Output report buffer: %s\n",
     269        usb_log_debug("Output report buffer: %s",
    269270            usb_debug_str_buffer(kbd_dev->output_buffer, kbd_dev->output_size,
    270271                0));
     
    276277            kbd_dev->output_buffer, kbd_dev->output_size);
    277278        if (rc != EOK) {
    278                 usb_log_warning("Failed to set kbd indicators.\n");
     279                usb_log_warning("Failed to set kbd indicators.");
    279280        }
    280281}
     
    289290void usb_kbd_push_ev(usb_kbd_t *kbd_dev, int type, unsigned key)
    290291{
    291         usb_log_debug2("Sending kbdev event %d/%d to the console\n", type, key);
     292        usb_log_debug2("Sending kbdev event %d/%d to the console", type, key);
    292293        if (kbd_dev->client_sess == NULL) {
    293294                usb_log_warning(
     
    301302                async_exchange_end(exch);
    302303        } else {
    303                 usb_log_warning("Failed to send key to console.\n");
     304                usb_log_warning("Failed to send key to console.");
    304305        }
    305306}
     
    328329 * An event is created only when key is pressed or released. Besides handling
    329330 * the events (usb_kbd_push_ev()), the auto-repeat fibril is notified about
    330  * key presses and releases (see usb_kbd_repeat_start() and 
     331 * key presses and releases (see usb_kbd_repeat_start() and
    331332 * usb_kbd_repeat_stop()).
    332333 *
    333334 * @param kbd_dev Keyboard device structure.
    334  * @param key_codes Parsed keyboard report - codes of currently pressed keys 
     335 * @param key_codes Parsed keyboard report - codes of currently pressed keys
    335336 *                  according to HID Usage Tables.
    336337 * @param count Number of key codes in report (size of the report).
     
    353354            kbd_dev->key_count);
    354355        if (i != (size_t) -1) {
    355                 usb_log_error("Detected phantom state.\n");
     356                usb_log_error("Detected phantom state.");
    356357                return;
    357358        }
     
    403404        ddf_dump_buffer(key_buffer, 512,
    404405            kbd_dev->keys_old, 4, kbd_dev->key_count, 0);
    405         usb_log_debug2("Stored keys %s.\n", key_buffer);
     406        usb_log_debug2("Stored keys %s.", key_buffer);
    406407}
    407408
     
    431432        usb_hid_report_path_t *path = usb_hid_report_path();
    432433        if (path == NULL) {
    433                 usb_log_error("Failed to create hid/kbd report path.\n");
     434                usb_log_error("Failed to create hid/kbd report path.");
    434435                return;
    435436        }
     
    438439           usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_KEYBOARD, 0);
    439440        if (ret != EOK) {
    440                 usb_log_error("Failed to append to hid/kbd report path.\n");
     441                usb_log_error("Failed to append to hid/kbd report path.");
    441442                return;
    442443        }
     
    452453
    453454        while (field != NULL) {
    454                 usb_log_debug2("FIELD (%p) - VALUE(%d) USAGE(%u)\n",
     455                usb_log_debug2("FIELD (%p) - VALUE(%d) USAGE(%u)",
    455456                    field, field->value, field->usage);
    456457
     
    464465                        kbd_dev->keys[i] = 0;
    465466                }
    466                 usb_log_debug2("Saved %u. key usage %d\n", i, kbd_dev->keys[i]);
     467                usb_log_debug2("Saved %u. key usage %d", i, kbd_dev->keys[i]);
    467468
    468469                ++i;
     
    502503        usb_hid_report_path_t *path = usb_hid_report_path();
    503504        if (path == NULL) {
    504                 usb_log_error("Failed to create kbd report path.\n");
     505                usb_log_error("Failed to create kbd report path.");
    505506                usb_kbd_destroy(kbd_dev);
    506507                return ENOMEM;
     
    510511            usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_KEYBOARD, 0);
    511512        if (ret != EOK) {
    512                 usb_log_error("Failed to append item to kbd report path.\n");
     513                usb_log_error("Failed to append item to kbd report path.");
    513514                usb_hid_report_path_free(path);
    514515                usb_kbd_destroy(kbd_dev);
     
    523524        usb_hid_report_path_free(path);
    524525
    525         usb_log_debug("Size of the input report: %zu\n", kbd_dev->key_count);
     526        usb_log_debug("Size of the input report: %zu", kbd_dev->key_count);
    526527
    527528        kbd_dev->keys = calloc(kbd_dev->key_count, sizeof(int32_t));
    528529        if (kbd_dev->keys == NULL) {
    529                 usb_log_error("Failed to allocate key buffer.\n");
     530                usb_log_error("Failed to allocate key buffer.");
    530531                usb_kbd_destroy(kbd_dev);
    531532                return ENOMEM;
     
    534535        kbd_dev->keys_old = calloc(kbd_dev->key_count, sizeof(int32_t));
    535536        if (kbd_dev->keys_old == NULL) {
    536                 usb_log_error("Failed to allocate old_key buffer.\n");
     537                usb_log_error("Failed to allocate old_key buffer.");
    537538                usb_kbd_destroy(kbd_dev);
    538539                return ENOMEM;
     
    544545            &kbd_dev->output_size, 0);
    545546        if (kbd_dev->output_buffer == NULL) {
    546                 usb_log_error("Error creating output report buffer.\n");
     547                usb_log_error("Error creating output report buffer.");
    547548                usb_kbd_destroy(kbd_dev);
    548549                return ENOMEM;
    549550        }
    550551
    551         usb_log_debug("Output buffer size: %zu\n", kbd_dev->output_size);
     552        usb_log_debug("Output buffer size: %zu", kbd_dev->output_size);
    552553
    553554        kbd_dev->led_path = usb_hid_report_path();
    554555        if (kbd_dev->led_path == NULL) {
    555                 usb_log_error("Failed to create kbd led report path.\n");
     556                usb_log_error("Failed to create kbd led report path.");
    556557                usb_kbd_destroy(kbd_dev);
    557558                return ENOMEM;
     
    561562            kbd_dev->led_path, USB_HIDUT_PAGE_LED, 0);
    562563        if (ret != EOK) {
    563                 usb_log_error("Failed to append to kbd/led report path.\n");
     564                usb_log_error("Failed to append to kbd/led report path.");
    564565                usb_kbd_destroy(kbd_dev);
    565566                return ret;
     
    569570            &hid_dev->report, 0, USB_HID_REPORT_TYPE_OUTPUT);
    570571
    571         usb_log_debug("Output report size (in items): %zu\n",
     572        usb_log_debug("Output report size (in items): %zu",
    572573            kbd_dev->led_output_size);
    573574
    574575        kbd_dev->led_data = calloc(kbd_dev->led_output_size, sizeof(int32_t));
    575576        if (kbd_dev->led_data == NULL) {
    576                 usb_log_error("Error creating buffer for LED output report.\n");
     577                usb_log_error("Error creating buffer for LED output report.");
    577578                usb_kbd_destroy(kbd_dev);
    578579                return ENOMEM;
     
    588589
    589590        kbd_dev->initialized = USB_KBD_STATUS_INITIALIZED;
    590         usb_log_debug("HID/KBD device structure initialized.\n");
     591        usb_log_debug("HID/KBD device structure initialized.");
    591592
    592593        return EOK;
     
    618619errno_t usb_kbd_init(usb_hid_dev_t *hid_dev, void **data)
    619620{
    620         usb_log_debug("Initializing HID/KBD structure...\n");
     621        usb_log_debug("Initializing HID/KBD structure...");
    621622
    622623        if (hid_dev == NULL) {
     
    627628
    628629        /* Create the exposed function. */
    629         usb_log_debug("Creating DDF function %s...\n", HID_KBD_FUN_NAME);
     630        usb_log_debug("Creating DDF function %s...", HID_KBD_FUN_NAME);
    630631        ddf_fun_t *fun = usb_device_ddf_fun_create(hid_dev->usb_dev,
    631632            fun_exposed, HID_KBD_FUN_NAME);
    632633        if (fun == NULL) {
    633                 usb_log_error("Could not create DDF function node.\n");
     634                usb_log_error("Could not create DDF function node.");
    634635                return ENOMEM;
    635636        }
     
    637638        usb_kbd_t *kbd_dev = ddf_fun_data_alloc(fun, sizeof(usb_kbd_t));
    638639        if (kbd_dev == NULL) {
    639                 usb_log_error("Failed to allocate KBD device structure.\n");
     640                usb_log_error("Failed to allocate KBD device structure.");
    640641                ddf_fun_destroy(fun);
    641642                return ENOMEM;
     
    644645        errno_t ret = kbd_dev_init(kbd_dev, hid_dev);
    645646        if (ret != EOK) {
    646                 usb_log_error("Failed to initialize KBD device  structure.\n");
     647                usb_log_error("Failed to initialize KBD device  structure.");
    647648                ddf_fun_destroy(fun);
    648649                return ret;
     
    655656        ret = ddf_fun_bind(fun);
    656657        if (ret != EOK) {
    657                 usb_log_error("Could not bind DDF function: %s.\n",
     658                usb_log_error("Could not bind DDF function: %s.",
    658659                    str_error(ret));
    659660                usb_kbd_destroy(kbd_dev);
     
    662663        }
    663664
    664         usb_log_debug("%s function created. Handle: %" PRIun "\n",
     665        usb_log_debug("%s function created. Handle: %" PRIun "",
    665666            HID_KBD_FUN_NAME, ddf_fun_get_handle(fun));
    666667
    667         usb_log_debug("Adding DDF function to category %s...\n",
     668        usb_log_debug("Adding DDF function to category %s...",
    668669            HID_KBD_CATEGORY_NAME);
    669670        ret = ddf_fun_add_to_category(fun, HID_KBD_CATEGORY_NAME);
     
    709710        usb_kbd_process_data(hid_dev, kbd_dev);
    710711
     712        /* Continue polling until the device is about to be removed. */
    711713        return true;
    712714}
     
    752754        if (kbd_dev->fun) {
    753755                if (ddf_fun_unbind(kbd_dev->fun) != EOK) {
    754                         usb_log_warning("Failed to unbind %s.\n",
     756                        usb_log_warning("Failed to unbind %s.",
    755757                            ddf_fun_get_name(kbd_dev->fun));
    756758                } else {
    757                         usb_log_debug2("%s unbound.\n",
     759                        usb_log_debug2("%s unbound.",
    758760                            ddf_fun_get_name(kbd_dev->fun));
    759761                        ddf_fun_destroy(kbd_dev->fun);
     
    783785
    784786        if (rc != EOK) {
    785                 usb_log_error("Failed to parse boot report descriptor: %s\n",
     787                usb_log_error("Failed to parse boot report descriptor: %s",
    786788                    str_error(rc));
    787789                return rc;
Note: See TracChangeset for help on using the changeset viewer.