Changeset 9e7cdf8 in mainline


Ignore:
Timestamp:
2011-02-04T14:05:51Z (13 years ago)
Author:
Lubos Slovak <lubos.slovak@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
8c3c756
Parents:
9097c16a
Message:

Unified debug and error messages according to ticket #52

File:
1 edited

Legend:

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

    r9097c16a r9e7cdf8  
    4949#include <usb/devreq.h>
    5050#include <usb/descriptor.h>
     51#include <usb/debug.h>
    5152#include <io/console.h>
    5253#include "hid.h"
     
    196197        }
    197198/*
    198         printf("type: %d\n", type);
    199         printf("mods: 0x%x\n", mods);
    200         printf("keycode: %u\n", key);
     199        usb_log_debug2("type: %d\n", type);
     200        usb_log_debug2("mods: 0x%x\n", mods);
     201        usb_log_debug2("keycode: %u\n", key);
    201202*/
    202203       
     
    228229        ev.c = layout[active_layout]->parse_ev(&ev);
    229230
    230         printf("Sending key %d to the console\n", ev.key);
     231        usb_log_debug("Sending key %d to the console\n", ev.key);
    231232        assert(console_callback_phone != -1);
    232233        async_msg_4(console_callback_phone, KBD_EVENT, ev.type, ev.key, ev.mods, ev.c);
     
    249250    uint8_t modifiers, void *arg)
    250251{
    251         printf("Got keys: ");
     252        usb_log_debug2("Got keys from parser: ");
    252253        unsigned i;
    253254        for (i = 0; i < count; ++i) {
    254                 printf("%d ", key_codes[i]);
     255                usb_log_debug2("%d ", key_codes[i]);
    255256                // TODO: Key press / release
    256 
    257                 // TODO: NOT WORKING
    258257                unsigned int key = usbkbd_parse_scancode(key_codes[i]);
    259258                kbd_push_ev(KEY_PRESS, key);
    260259        }
    261         printf("\n");
     260        usb_log_debug2("\n");
    262261}
    263262
     
    339338        free(descriptors);
    340339        if (rc != EOK) {
    341                 printf("Problem with parsing standard descriptors.\n");
     340                usb_log_warning("Problem with parsing standard descriptors.\n");
    342341                return rc;
    343342        }
     
    346345        rc = usbkbd_get_report_descriptor(kbd_dev);
    347346        if (rc != EOK) {
    348                 printf("Problem with parsing HID REPORT descriptor.\n");
     347                usb_log_warning("Problem with parsing REPORT descriptor.\n");
    349348                return rc;
    350349        }
     
    356355         * 1) select one configuration (lets say the first)
    357356         * 2) how many interfaces?? how to select one??
    358     *    ("The default setting for an interface is always alternate setting zero.")
     357        *    ("The default setting for an interface is always alternate setting zero.")
    359358         * 3) find endpoint which is IN and INTERRUPT (parse), save its number
    360     *    as the endpoint for polling
     359        *    as the endpoint for polling
    361360         */
    362361       
     
    370369
    371370        if (kbd_dev == NULL) {
    372                 fprintf(stderr, NAME ": No memory!\n");
     371                usb_log_fatal("No memory!\n");
    373372                return NULL;
    374373        }
     
    380379        int rc = kbd_dev->device->parent_phone = usb_drv_hc_connect_auto(dev, 0);
    381380        if (rc < 0) {
    382                 printf("Problem setting phone to HC.\n");
     381                usb_log_error("Problem setting phone to HC.\n");
    383382                goto error_leave;
    384383        }
     
    386385        rc = kbd_dev->address = usb_drv_get_my_address(dev->parent_phone, dev);
    387386        if (rc < 0) {
    388                 printf("Problem getting address of the device.\n");
     387                usb_log_error("Problem getting address of the device.\n");
    389388                goto error_leave;
    390389        }
     
    392391        // doesn't matter now that we have no address
    393392//      if (kbd_dev->address < 0) {
    394 //              fprintf(stderr, NAME ": No device address!\n");
     393//              usb_log_error("No device address!\n");
    395394//              free(kbd_dev);
    396395//              return NULL;
     
    407406        usbkbd_process_descriptors(kbd_dev);
    408407
    409 
    410 
    411408        /*
    412409         * Initialize the backing connection to the host controller.
     
    414411        rc = usb_device_connection_initialize_from_device(&kbd_dev->wire, dev);
    415412        if (rc != EOK) {
    416                 printf("Problem initializing connection to device: %s.\n",
    417                     str_error(rc));
     413                usb_log_error("Problem initializing connection to device: %s."
     414                    "\n", str_error(rc));
    418415                goto error_leave;
    419416        }
     
    425422            GUESSED_POLL_ENDPOINT, USB_TRANSFER_INTERRUPT, USB_DIRECTION_IN);
    426423        if (rc != EOK) {
    427                 printf("Failed to initialize interrupt in pipe: %s.\n",
     424                usb_log_error("Failed to initialize interrupt in pipe: %s.\n",
    428425                    str_error(rc));
    429426                goto error_leave;
     
    448445        //usb_hid_parse_report(kbd_dev->parser, buffer, actual_size, callbacks,
    449446        //    NULL);
    450         printf("Calling usb_hid_boot_keyboard_input_report() with size %zu\n",
    451             actual_size);
     447        /*usb_log_debug2("Calling usb_hid_boot_keyboard_input_report() with size"
     448            " %zu\n", actual_size);*/
    452449        //dump_buffer("bufffer: ", buffer, actual_size);
    453         int rc = usb_hid_boot_keyboard_input_report(buffer, actual_size, callbacks,
    454             NULL);
    455         if (rc != EOK) {
    456                 printf("Error in usb_hid_boot_keyboard_input_report(): %d\n", rc);
     450        int rc = usb_hid_boot_keyboard_input_report(buffer, actual_size,
     451            callbacks, NULL);
     452       
     453        if (rc != EOK) {
     454                usb_log_warning("Error in usb_hid_boot_keyboard_input_report():"
     455                    "%s\n", str_error(rc));
    457456        }
    458457}
     
    464463        size_t actual_size;
    465464
    466         printf("Polling keyboard...\n");
     465        usb_log_info("Polling keyboard...\n");
    467466
    468467        while (true) {
     
    471470                sess_rc = usb_endpoint_pipe_start_session(&kbd_dev->poll_pipe);
    472471                if (sess_rc != EOK) {
    473                         printf("Failed to start a session: %s.\n",
     472                        usb_log_warning("Failed to start a session: %s.\n",
    474473                            str_error(sess_rc));
    475474                        continue;
     
    481480
    482481                if (rc != EOK) {
    483                         printf("Error polling the keyboard: %s.\n",
     482                        usb_log_warning("Error polling the keyboard: %s.\n",
    484483                            str_error(rc));
    485484                        continue;
     
    487486
    488487                if (sess_rc != EOK) {
    489                         printf("Error closing session: %s.\n",
     488                        usb_log_warning("Error closing session: %s.\n",
    490489                            str_error(sess_rc));
    491490                        continue;
     
    497496                 */
    498497                if (actual_size == 0) {
    499                         printf("Keyboard returned NAK\n");
     498                        usb_log_debug("Keyboard returned NAK\n");
    500499                        continue;
    501500                }
     
    504503                 * TODO: Process pressed keys.
    505504                 */
    506                 printf("Calling usbkbd_process_interrupt_in()\n");
     505                usb_log_debug("Calling usbkbd_process_interrupt_in()\n");
    507506                usbkbd_process_interrupt_in(kbd_dev, buffer, actual_size);
    508507        }
     
    514513static int usbkbd_fibril_device(void *arg)
    515514{
    516         printf("!!! USB device fibril\n");
    517 
    518515        if (arg == NULL) {
    519                 printf("No device!\n");
     516                usb_log_error("No device!\n");
    520517                return -1;
    521518        }
     
    526523        usb_hid_dev_kbd_t *kbd_dev = usbkbd_init_device(dev);
    527524        if (kbd_dev == NULL) {
    528                 printf("Error while initializing device.\n");
     525                usb_log_error("Error while initializing device.\n");
    529526                return -1;
    530527        }
     
    561558        fid_t fid = fibril_create(usbkbd_fibril_device, dev);
    562559        if (fid == 0) {
    563                 printf("%s: failed to start fibril for HID device\n", NAME);
     560                usb_log_error("Failed to start fibril for HID device\n");
    564561                return ENOMEM;
    565562        }
     
    587584int main(int argc, char *argv[])
    588585{
     586        usb_log_enable(USB_LOG_LEVEL_MAX, NAME);
    589587        return driver_main(&kbd_driver);
    590588}
Note: See TracChangeset for help on using the changeset viewer.