Changeset 1d1bb0f in mainline


Ignore:
Timestamp:
2011-06-19T13:38:37Z (13 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b72efe8
Parents:
adfdbd5 (diff), 9724d7f (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.
Message:

Merge from https://code.launchpad.net/~vojtech-horky/helenos/usb

Files:
2 added
1 deleted
34 edited
36 moved

Legend:

Unmodified
Added
Removed
  • boot/arch/amd64/Makefile.inc

    radfdbd5 r1d1bb0f  
    4343        isa \
    4444        ns8250 \
    45         ehci_hcd \
     45        ehci\
    4646        ohci \
    47         uhci_hcd \
    48         uhci_rhd \
     47        uhci \
     48        uhcirh \
    4949        usbflbk \
    5050        usbhub \
  • uspace/Makefile

    radfdbd5 r1d1bb0f  
    101101        drv/test2 \
    102102        drv/test3 \
    103         drv/ehci_hcd \
     103        drv/ehci \
    104104        drv/ohci \
    105         drv/uhci_hcd \
    106         drv/uhci_rhd \
     105        drv/uhci \
     106        drv/uhcirh \
    107107        drv/usbflbk \
    108108        drv/usbhid \
  • uspace/app/mkbd/main.c

    radfdbd5 r1d1bb0f  
    5252#include <usb/hid/hiddescriptor.h>
    5353#include <usb/hid/usages/consumer.h>
     54#include <io/console.h>
     55#include <io/keycode.h>
    5456#include <assert.h>
    5557
     
    166168       
    167169        usb_hid_report_path_free(path);
     170}
     171
     172static int wait_for_quit_fibril(void *arg)
     173{
     174        console_ctrl_t *con = console_init(stdin, stdout);
     175
     176        printf("Press <ESC> to quit the application.\n");
     177
     178        while (1) {
     179                kbd_event_t ev;
     180                bool ok = console_get_kbd_event(con, &ev);
     181                if (!ok) {
     182                        printf("Connection with console broken: %s.\n",
     183                            str_error(errno));
     184                        break;
     185                }
     186
     187                if (ev.key == KC_ESCAPE) {
     188                        break;
     189                }
     190        }
     191
     192        console_done(con);
     193
     194        exit(0);
     195
     196        return EOK;
    168197}
    169198
     
    242271        }
    243272       
     273        fid_t quit_fibril = fibril_create(wait_for_quit_fibril, NULL);
     274        if (quit_fibril == 0) {
     275                printf("Failed to start extra fibril.\n");
     276                return -1;
     277        }
     278        fibril_add_ready(quit_fibril);
     279
    244280        size_t actual_size;
    245281        int event_nr;
    246        
     282
    247283        while (true) {
    248284                /** @todo Try blocking call. */
  • uspace/app/usbinfo/Makefile

    radfdbd5 r1d1bb0f  
    3131
    3232LIBS = \
     33        $(LIBUSBHID_PREFIX)/libusbhid.a \
    3334        $(LIBUSBDEV_PREFIX)/libusbdev.a \
    3435        $(LIBUSB_PREFIX)/libusb.a \
     
    3738        -I$(LIBUSB_PREFIX)/include \
    3839        -I$(LIBUSBDEV_PREFIX)/include \
     40        -I$(LIBUSBHID_PREFIX)/include \
    3941        -I$(LIBDRV_PREFIX)/include
    4042
     
    4345        dev.c \
    4446        dump.c \
     47        hid.c \
    4548        info.c \
    4649        main.c
  • uspace/app/usbinfo/main.c

    radfdbd5 r1d1bb0f  
    5656        printf("Usage: %s [options] device [device [device [ ... ]]]\n",
    5757            app_name);
    58         printf(_INDENT "The device is a devman path to the device.\n");
     58        printf(_INDENT "The device can be specified in two ways.\n");
     59        printf(_INDENT "  o Using its devman path, e.g. /hw/pci0/.../usb00_a1.\n");
     60        printf(_INDENT "  o Or using BUS.ADDR numbers as printed by lsusb.\n");
    5961
    6062        _OPTION("-h --help", "Print this help and exit.");
     
    6567        _OPTION("-s --strings", "Try to print all string descriptors.");
    6668        _OPTION("-S --status", "Get status of the device.");
     69        _OPTION("-r --hid-report", "Dump HID report descriptor.");
     70        _OPTION("-r --hid-report-usages", "Dump usages of HID report.");
    6771
    6872        printf("\n");
     
    8286        {"strings", no_argument, NULL, 's'},
    8387        {"status", no_argument, NULL, 'S'},
     88        {"hid-report", no_argument, NULL, 'r'},
     89        {"hid-report-usages", no_argument, NULL, 'R'},
    8490        {0, 0, NULL, 0}
    8591};
    86 static const char *short_options = "himtTsS";
     92static const char *short_options = "himtTsSrR";
    8793
    8894static usbinfo_action_t actions[] = {
     
    115121                .opt = 'S',
    116122                .action = dump_status,
     123                .active = false
     124        },
     125        {
     126                .opt = 'r',
     127                .action = dump_hidreport_raw,
     128                .active = false
     129        },
     130        {
     131                .opt = 'R',
     132                .action = dump_hidreport_usages,
    117133                .active = false
    118134        },
  • uspace/app/usbinfo/usbinfo.h

    radfdbd5 r1d1bb0f  
    8585void dump_strings(usbinfo_device_t *);
    8686void dump_status(usbinfo_device_t *);
     87void dump_hidreport_raw(usbinfo_device_t *);
     88void dump_hidreport_usages(usbinfo_device_t *);
    8789
    8890
  • uspace/app/vuhid/Makefile

    radfdbd5 r1d1bb0f  
    3636        $(LIBUSBHID_PREFIX)/libusbhid.a \
    3737        $(LIBUSBDEV_PREFIX)/libusbdev.a \
    38         $(LIBUSB_PREFIX)/libusb.a
     38        $(LIBUSB_PREFIX)/libusb.a \
     39        $(LIBDRV_PREFIX)/libdrv.a
    3940EXTRA_CFLAGS = \
    4041        -I$(LIBUSB_PREFIX)/include \
  • uspace/drv/ehci/Makefile

    radfdbd5 r1d1bb0f  
    3838        -I$(LIBDRV_PREFIX)/include
    3939
    40 BINARY = ehci_hcd
     40BINARY = ehci
    4141
    4242SOURCES = \
  • uspace/drv/ehci/ehci.h

    radfdbd5 r1d1bb0f  
    3838#include <usbhc_iface.h>
    3939
    40 #define NAME "ehci_hcd"
     40#define NAME "ehci"
    4141
    4242extern usbhc_iface_t ehci_hc_iface;
  • uspace/drv/ehci/hc_iface.c

    radfdbd5 r1d1bb0f  
    4545
    4646#define UNSUPPORTED(methodname) \
    47         usb_log_warning("Unsupported interface method `%s()' in %s:%d.\n", \
     47        usb_log_debug("Client called unsupported interface method " \
     48            "`%s()' in %s:%d.\n", \
    4849            methodname, __FILE__, __LINE__)
    4950
  • uspace/drv/ohci/hc.c

    radfdbd5 r1d1bb0f  
    6565            device_keeper_get_free_address(&instance->manager, USB_SPEED_FULL);
    6666        if (hub_address <= 0) {
    67                 usb_log_error("Failed(%d) to get OHCI root hub address.\n",
    68                     hub_address);
     67                usb_log_error("Failed to get OHCI root hub address: %s\n",
     68                    str_error(hub_address));
    6969                return hub_address;
    7070        }
     
    445445        /* HC is in reset (hw startup) => no other driver
    446446         * maintain reset for at least the time specified in USB spec (50 ms)*/
    447         usb_log_info("HC found in reset.\n");
     447        usb_log_debug("Host controller found in reset state.\n");
    448448        async_usleep(50000);
    449449}
     
    516516
    517517        instance->registers->control &= (C_HCFS_OPERATIONAL << C_HCFS_SHIFT);
    518         usb_log_info("OHCI HC up and running(%x).\n",
     518        usb_log_debug("OHCI HC up and running (ctl_reg=0x%x).\n",
    519519            instance->registers->control);
    520520}
  • uspace/drv/ohci/root_hub.c

    radfdbd5 r1d1bb0f  
    232232                return ENOMEM;
    233233
    234         usb_log_info("OHCI root hub with %zu ports initialized.\n",
     234        usb_log_info("Root hub (%zu ports) initialized.\n",
    235235            instance->port_count);
    236236
     
    251251        int opResult;
    252252        if (request->ep->transfer_type == USB_TRANSFER_CONTROL) {
    253                 usb_log_info("Root hub got CONTROL packet\n");
     253                usb_log_debug("Root hub got CONTROL packet\n");
    254254                opResult = process_ctrl_request(instance, request);
    255255                usb_transfer_batch_finish_error(request, opResult);
    256256        } else if (request->ep->transfer_type == USB_TRANSFER_INTERRUPT) {
    257                 usb_log_info("Root hub got INTERRUPT packet\n");
     257                usb_log_debug("Root hub got INTERRUPT packet\n");
    258258                create_interrupt_mask_in_instance(instance);
    259259                if (is_zeros(instance->interrupt_buffer,
     
    521521                case USB_DESCTYPE_HUB:
    522522                {
    523                         usb_log_debug("USB_DESCTYPE_HUB\n");
     523                        usb_log_debug2("USB_DESCTYPE_HUB\n");
    524524                        result_descriptor = instance->hub_descriptor;
    525525                        size = instance->descriptor_size;
     
    528528                case USB_DESCTYPE_DEVICE:
    529529                {
    530                         usb_log_debug("USB_DESCTYPE_DEVICE\n");
     530                        usb_log_debug2("USB_DESCTYPE_DEVICE\n");
    531531                        result_descriptor = &ohci_rh_device_descriptor;
    532532                        size = sizeof (ohci_rh_device_descriptor);
     
    535535                case USB_DESCTYPE_CONFIGURATION:
    536536                {
    537                         usb_log_debug("USB_DESCTYPE_CONFIGURATION\n");
     537                        usb_log_debug2("USB_DESCTYPE_CONFIGURATION\n");
    538538                        result_descriptor = instance->descriptors.configuration;
    539539                        size = instance->descriptors.configuration_size;
     
    542542                case USB_DESCTYPE_INTERFACE:
    543543                {
    544                         usb_log_debug("USB_DESCTYPE_INTERFACE\n");
     544                        usb_log_debug2("USB_DESCTYPE_INTERFACE\n");
    545545                        result_descriptor = &ohci_rh_iface_descriptor;
    546546                        size = sizeof (ohci_rh_iface_descriptor);
     
    549549                case USB_DESCTYPE_ENDPOINT:
    550550                {
    551                         usb_log_debug("USB_DESCTYPE_ENDPOINT\n");
     551                        usb_log_debug2("USB_DESCTYPE_ENDPOINT\n");
    552552                        result_descriptor = &ohci_rh_ep_descriptor;
    553553                        size = sizeof (ohci_rh_ep_descriptor);
     
    556556                default:
    557557                {
    558                         usb_log_debug("USB_DESCTYPE_EINVAL %d \n",
     558                        usb_log_debug2("USB_DESCTYPE_EINVAL %d \n",
    559559                            setup_request->value);
    560                         usb_log_debug("\ttype %d\n\trequest %d\n\tvalue "
     560                        usb_log_debug2("\ttype %d\n\trequest %d\n\tvalue "
    561561                            "%d\n\tindex %d\n\tlen %d\n ",
    562562                            setup_request->request_type,
     
    789789                }
    790790                if (setup_request->request_type == USB_HUB_REQ_TYPE_SET_PORT_FEATURE) {
    791                         usb_log_debug("USB_HUB_REQ_TYPE_SET_PORT_FEATURE\n");
     791                        usb_log_debug2("USB_HUB_REQ_TYPE_SET_PORT_FEATURE\n");
    792792                        return process_port_feature_clear_request(instance,
    793793                            setup_request->value,
     
    854854                return EINVAL;
    855855        }
    856         usb_log_info("CTRL packet: %s.\n",
     856        usb_log_debug("CTRL packet: %s.\n",
    857857            usb_debug_str_buffer(
    858858            (const uint8_t *) request->setup_buffer, 8, 8));
     
    864864                case USB_DEVREQ_GET_DESCRIPTOR:
    865865                case USB_DEVREQ_GET_CONFIGURATION:
    866                         usb_log_debug("Processing request with output\n");
     866                        usb_log_debug2("Processing request with output\n");
    867867                        opResult = process_request_with_output(
    868868                            instance, request);
     
    871871                case USB_DEVREQ_SET_FEATURE:
    872872                case USB_DEVREQ_SET_ADDRESS:
    873                         usb_log_debug("Processing request without "
     873                        usb_log_debug2("Processing request without "
    874874                            "additional data\n");
    875875                        opResult = process_request_without_data(
     
    878878                case USB_DEVREQ_SET_DESCRIPTOR:
    879879                case USB_DEVREQ_SET_CONFIGURATION:
    880                         usb_log_debug("Processing request with "
    881                             "input\n");
     880                        usb_log_debug2("Processing request with input\n");
    882881                        opResult = process_request_with_input(
    883882                            instance, request);
     
    885884                        break;
    886885                default:
    887                         usb_log_warning("Received unsuported request: "
    888                             "%d\n",
    889                             setup_request->request
    890                             );
     886                        usb_log_warning("Received unsupported request: %d.\n",
     887                            setup_request->request);
    891888                        opResult = ENOTSUP;
    892889        }
  • uspace/drv/uhci/Makefile

    radfdbd5 r1d1bb0f  
    3838        -I$(LIBDRV_PREFIX)/include
    3939
    40 BINARY = uhci_hcd
     40BINARY = uhci
    4141
    4242SOURCES = \
  • uspace/drv/uhci/batch.c

    radfdbd5 r1d1bb0f  
    147147            + sizeof(qh_t);
    148148        void *data_buffer = setup + setup_size;
    149         usb_target_t target =
    150             { .address = ep->address, .endpoint = ep->endpoint };
    151149        usb_transfer_batch_init(instance, ep, buffer, data_buffer, buffer_size,
    152150            setup, setup_size, func_in, func_out, arg, fun,
     
    154152
    155153        memcpy(instance->setup_buffer, setup_buffer, setup_size);
    156         usb_log_debug("Batch(%p) %d:%d memory structures ready.\n",
    157             instance, target.address, target.endpoint);
     154        usb_log_debug2("Batch %p " USB_TRANSFER_BATCH_FMT
     155            " memory structures ready.\n", instance,
     156            USB_TRANSFER_BATCH_ARGS(*instance));
    158157        return instance;
    159158}
     
    205204        return true;
    206205}
     206
     207#define LOG_BATCH_INITIALIZED(batch, name) \
     208        usb_log_debug2("Batch %p %s " USB_TRANSFER_BATCH_FMT " initialized.\n", \
     209            (batch), (name), USB_TRANSFER_BATCH_ARGS(*(batch)))
     210
    207211/*----------------------------------------------------------------------------*/
    208212/** Prepares control write transfer.
     
    219223        batch_control(instance, USB_PID_OUT, USB_PID_IN);
    220224        instance->next_step = usb_transfer_batch_call_out_and_dispose;
    221         usb_log_debug("Batch(%p) CONTROL WRITE initialized.\n", instance);
     225        LOG_BATCH_INITIALIZED(instance, "control write");
    222226}
    223227/*----------------------------------------------------------------------------*/
     
    233237        batch_control(instance, USB_PID_IN, USB_PID_OUT);
    234238        instance->next_step = usb_transfer_batch_call_in_and_dispose;
    235         usb_log_debug("Batch(%p) CONTROL READ initialized.\n", instance);
     239        LOG_BATCH_INITIALIZED(instance, "control read");
    236240}
    237241/*----------------------------------------------------------------------------*/
     
    247251        batch_data(instance, USB_PID_IN);
    248252        instance->next_step = usb_transfer_batch_call_in_and_dispose;
    249         usb_log_debug("Batch(%p) INTERRUPT IN initialized.\n", instance);
     253        LOG_BATCH_INITIALIZED(instance, "interrupt in");
    250254}
    251255/*----------------------------------------------------------------------------*/
     
    263267        batch_data(instance, USB_PID_OUT);
    264268        instance->next_step = usb_transfer_batch_call_out_and_dispose;
    265         usb_log_debug("Batch(%p) INTERRUPT OUT initialized.\n", instance);
     269        LOG_BATCH_INITIALIZED(instance, "interrupt out");
    266270}
    267271/*----------------------------------------------------------------------------*/
     
    277281        batch_data(instance, USB_PID_IN);
    278282        instance->next_step = usb_transfer_batch_call_in_and_dispose;
    279         usb_log_debug("Batch(%p) BULK IN initialized.\n", instance);
     283        LOG_BATCH_INITIALIZED(instance, "bulk in");
    280284}
    281285/*----------------------------------------------------------------------------*/
     
    293297        batch_data(instance, USB_PID_OUT);
    294298        instance->next_step = usb_transfer_batch_call_out_and_dispose;
    295         usb_log_debug("Batch(%p) BULK OUT initialized.\n", instance);
     299        LOG_BATCH_INITIALIZED(instance, "bulk out");
    296300}
    297301/*----------------------------------------------------------------------------*/
  • uspace/drv/uhci/hw_struct/transfer_descriptor.c

    radfdbd5 r1d1bb0f  
    103103        td_print_status(instance);
    104104        if (pid == USB_PID_SETUP) {
    105                 usb_log_debug("SETUP BUFFER: %s\n",
     105                usb_log_debug2("SETUP BUFFER: %s\n",
    106106                    usb_debug_str_buffer(buffer, 8, 8));
    107107        }
  • uspace/drv/uhci/iface.c

    radfdbd5 r1d1bb0f  
    6464        }
    6565
    66         usb_log_debug("%s %d:%d %zu(%zu).\n",
     66        usb_log_debug2("%s %d:%d %zu(%zu).\n",
    6767            name, target.address, target.endpoint, size, ep->max_packet_size);
    6868
     
    172172                speed = ep_speed;
    173173        }
    174         usb_log_debug("Register endpoint %d:%d %s %s(%d) %zu(%zu) %u.\n",
     174        usb_log_debug("Register endpoint %d:%d %s-%s %s %zuB %ums.\n",
    175175            address, endpoint, usb_str_transfer_type(transfer_type),
    176             usb_str_speed(speed), direction, size, max_packet_size, interval);
     176            usb_str_direction(direction), usb_str_speed(speed),
     177            max_packet_size, interval);
    177178
    178179        return usb_endpoint_manager_add_ep(&hc->ep_manager, address, endpoint,
     
    187188        hc_t *hc = fun_to_hc(fun);
    188189        assert(hc);
    189         usb_log_debug("Unregister endpoint %d:%d %d.\n",
    190             address, endpoint, direction);
     190        usb_log_debug("Unregister endpoint %d:%d %s.\n",
     191            address, endpoint, usb_str_direction(direction));
    191192        return usb_endpoint_manager_unregister_ep(&hc->ep_manager, address,
    192193            endpoint, direction);
  • uspace/drv/uhci/main.c

    radfdbd5 r1d1bb0f  
    4141#include "uhci.h"
    4242
    43 #define NAME "uhci_hcd"
     43#define NAME "uhci"
    4444
    4545static int uhci_add_device(ddf_dev_t *device);
  • uspace/drv/uhci/transfer_list.c

    radfdbd5 r1d1bb0f  
    141141        list_append(&batch->link, &instance->batch_list);
    142142
    143         usb_transfer_batch_t *first = list_get_instance(
    144             instance->batch_list.next, usb_transfer_batch_t, link);
    145         usb_log_debug("Batch(%p) added to queue %s, first is %p.\n",
    146                 batch, instance->name, first);
     143        usb_log_debug("Batch %p " USB_TRANSFER_BATCH_FMT " scheduled in queue %s.\n",
     144            batch, USB_TRANSFER_BATCH_ARGS(*batch), instance->name);
    147145        fibril_mutex_unlock(&instance->guard);
    148146}
     
    234232        /* Remove from the batch list */
    235233        list_remove(&batch->link);
    236         usb_log_debug("Batch(%p) removed (%s) from %s, next: %x.\n",
    237             batch, qpos, instance->name, batch_qh(batch)->next);
     234        usb_log_debug2("Batch %p " USB_TRANSFER_BATCH_FMT " removed (%s) "
     235            "from %s, next: %x.\n",
     236            batch, USB_TRANSFER_BATCH_ARGS(*batch),
     237            qpos, instance->name, batch_qh(batch)->next);
    238238}
    239239/**
  • uspace/drv/uhcirh/Makefile

    radfdbd5 r1d1bb0f  
    3838        -I$(LIBDRV_PREFIX)/include
    3939
    40 BINARY = uhci_rhd
     40BINARY = uhcirh
    4141
    4242SOURCES = \
  • uspace/drv/uhcirh/main.c

    radfdbd5 r1d1bb0f  
    4646#include "root_hub.h"
    4747
    48 #define NAME "uhci_rhd"
     48#define NAME "uhcirh"
    4949
    5050static int hc_get_my_registers(const ddf_dev_t *dev,
  • uspace/drv/usbhid/Makefile

    radfdbd5 r1d1bb0f  
    4343BINARY = usbhid
    4444
     45SUBDRIVER_SOURCES = \
     46        kbd/conv.c \
     47        kbd/kbddev.c \
     48        kbd/kbdrepeat.c \
     49        mouse/mousedev.c \
     50        multimedia/multimedia.c \
     51        multimedia/keymap.c
     52
    4553SOURCES = \
    4654        main.c \
    4755        usbhid.c \
    4856        subdrivers.c \
    49         kbd/conv.c \
    50         kbd/kbddev.c \
    51         kbd/kbdrepeat.c \
    5257        generic/hiddev.c \
    53         mouse/mousedev.c \
    54         multimedia/multimedia.c \
    55         multimedia/keymap.c \
    56         $(STOLEN_LAYOUT_SOURCES)
     58        $(SUBDRIVER_SOURCES)
    5759
    5860include $(USPACE_PREFIX)/Makefile.common
  • uspace/drv/usbhid/generic/hiddev.c

    radfdbd5 r1d1bb0f  
    231231/*----------------------------------------------------------------------------*/
    232232
    233 bool usb_generic_hid_polling_callback(usb_hid_dev_t *hid_dev, void *data,
    234     uint8_t *buffer, size_t buffer_size)
    235 {
    236         usb_log_debug2("usb_hid_polling_callback(%p, %p, %zu)\n",
    237             hid_dev, buffer, buffer_size);
    238         usb_debug_str_buffer(buffer, buffer_size, 0);
     233bool usb_generic_hid_polling_callback(usb_hid_dev_t *hid_dev, void *data)
     234{
    239235        return true;
    240236}
  • uspace/drv/usbhid/generic/hiddev.h

    radfdbd5 r1d1bb0f  
    5050int usb_generic_hid_init(struct usb_hid_dev *hid_dev, void **data);
    5151
    52 bool usb_generic_hid_polling_callback(struct usb_hid_dev *hid_dev, void *data,
    53     uint8_t *buffer, size_t buffer_size);
     52bool usb_generic_hid_polling_callback(struct usb_hid_dev *hid_dev, void *data);
    5453
    5554#endif // USB_HID_HIDDDEV_H_
  • uspace/drv/usbhid/kbd/kbddev.c

    radfdbd5 r1d1bb0f  
    4646#include <fibril.h>
    4747#include <fibril_synch.h>
     48
     49#include <ddf/log.h>
    4850
    4951#include <usb/usb.h>
     
    317319}
    318320
     321static size_t find_in_array_int32(int32_t val, int32_t *arr, size_t arr_size)
     322{
     323        for (size_t i = 0; i < arr_size; i++) {
     324                if (arr[i] == val) {
     325                        return i;
     326                }
     327        }
     328
     329        return (size_t) -1;
     330}
     331
    319332/*----------------------------------------------------------------------------*/
    320333/**
     
    337350{
    338351        unsigned int key;
    339         unsigned int i, j;
     352        size_t i;
    340353       
    341354        /*
     
    347360         * whole input report.
    348361         */
    349         i = 0;
    350         while (i < kbd_dev->key_count && kbd_dev->keys[i] != ERROR_ROLLOVER) {
    351                 ++i;
    352         }
    353         if (i != kbd_dev->key_count) {
    354                 usb_log_debug("Phantom state occured.\n");
    355                 // phantom state, do nothing
     362        i = find_in_array_int32(ERROR_ROLLOVER, kbd_dev->keys,
     363            kbd_dev->key_count);
     364        if (i != (size_t) -1) {
     365                usb_log_debug("Detected phantom state.\n");
    356366                return;
    357367        }
    358368       
    359369        /*
    360          * 1) Key releases
    361          */
    362         for (j = 0; j < kbd_dev->key_count; ++j) {
    363                 // try to find the old key in the new key list
    364                 i = 0;
    365                 while (i < kbd_dev->key_count
    366                     && kbd_dev->keys[i] != kbd_dev->keys_old[j]) {
    367                         ++i;
    368                 }
    369                
    370                 if (i == kbd_dev->key_count) {
    371                         // not found, i.e. the key was released
    372                         key = usbhid_parse_scancode(kbd_dev->keys_old[j]);
     370         * Key releases
     371         */
     372        for (i = 0; i < kbd_dev->key_count; i++) {
     373                int32_t old_key = kbd_dev->keys_old[i];
     374                /* Find the old key among currently pressed keys. */
     375                size_t pos = find_in_array_int32(old_key, kbd_dev->keys,
     376                    kbd_dev->key_count);
     377                /* If the key was not found, we need to signal release. */
     378                if (pos == (size_t) -1) {
     379                        key = usbhid_parse_scancode(old_key);
    373380                        if (!usb_kbd_is_lock(key)) {
    374381                                usb_kbd_repeat_stop(kbd_dev, key);
    375382                        }
    376383                        usb_kbd_push_ev(hid_dev, kbd_dev, KEY_RELEASE, key);
    377                         usb_log_debug2("Key released: %d\n", key);
    378                 } else {
    379                         // found, nothing happens
    380                 }
    381         }
    382        
    383         /*
    384          * 1) Key presses
     384                        usb_log_debug2("Key released: %u "
     385                            "(USB code %" PRIu32 ")\n", key, old_key);
     386                }
     387        }
     388       
     389        /*
     390         * Key presses
    385391         */
    386392        for (i = 0; i < kbd_dev->key_count; ++i) {
    387                 // try to find the new key in the old key list
    388                 j = 0;
    389                 while (j < kbd_dev->key_count
    390                     && kbd_dev->keys_old[j] != kbd_dev->keys[i]) {
    391                         ++j;
    392                 }
    393                
    394                 if (j == kbd_dev->key_count) {
    395                         // not found, i.e. new key pressed
     393                int32_t new_key = kbd_dev->keys[i];
     394                /* Find the new key among already pressed keys. */
     395                size_t pos = find_in_array_int32(new_key, kbd_dev->keys_old,
     396                    kbd_dev->key_count);
     397                /* If the key was not found, we need to signal press. */
     398                if (pos == (size_t) -1) {
    396399                        key = usbhid_parse_scancode(kbd_dev->keys[i]);
    397                         usb_log_debug2("Key pressed: %d (keycode: %d)\n", key,
    398                             kbd_dev->keys[i]);
    399400                        if (!usb_kbd_is_lock(key)) {
    400401                                usb_kbd_repeat_start(kbd_dev, key);
    401402                        }
    402403                        usb_kbd_push_ev(hid_dev, kbd_dev, KEY_PRESS, key);
    403                 } else {
    404                         // found, nothing happens
     404                        usb_log_debug2("Key pressed: %u "
     405                            "(USB code %" PRIu32 ")\n", key, new_key);
    405406                }
    406407        }
     
    408409        memcpy(kbd_dev->keys_old, kbd_dev->keys, kbd_dev->key_count * 4);
    409410       
    410         usb_log_debug2("New stored keys: ");
    411         for (i = 0; i < kbd_dev->key_count; ++i) {
    412                 usb_log_debug2("%d ", kbd_dev->keys_old[i]);
    413         }
    414         usb_log_debug2("\n");
     411        char key_buffer[512];
     412        ddf_dump_buffer(key_buffer, 512,
     413            kbd_dev->keys_old, 4, kbd_dev->key_count, 0);
     414        usb_log_debug2("Stored keys %s.\n", key_buffer);
    415415}
    416416
     
    434434 *     usb_hid_parse_report().
    435435 */
    436 static void usb_kbd_process_data(usb_hid_dev_t *hid_dev, usb_kbd_t *kbd_dev,
    437                                  uint8_t *buffer, size_t actual_size)
     436static void usb_kbd_process_data(usb_hid_dev_t *hid_dev, usb_kbd_t *kbd_dev)
    438437{
    439438        assert(hid_dev->report != NULL);
    440439        assert(hid_dev != NULL);
    441440        assert(kbd_dev != NULL);
    442 
    443         usb_log_debug("Calling usb_hid_parse_report() with "
    444             "buffer %s\n", usb_debug_str_buffer(buffer, actual_size, 0));
    445441       
    446442        usb_hid_report_path_t *path = usb_hid_report_path();
    447443        usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_KEYBOARD, 0);
    448444
    449         uint8_t report_id;
    450         int rc = usb_hid_parse_report(hid_dev->report, buffer, actual_size,
    451             &report_id);
    452        
    453         if (rc != EOK) {
    454                 usb_log_warning("Error in usb_hid_parse_report():"
    455                     "%s\n", str_error(rc));
    456         }
    457        
    458         usb_hid_report_path_set_report_id (path, report_id);
     445        usb_hid_report_path_set_report_id (path, hid_dev->report_id);
    459446       
    460447        // fill in the currently pressed keys
     
    756743/*----------------------------------------------------------------------------*/
    757744
    758 bool usb_kbd_polling_callback(usb_hid_dev_t *hid_dev, void *data,
    759      uint8_t *buffer, size_t buffer_size)
    760 {
    761         if (hid_dev == NULL || buffer == NULL || data == NULL) {
     745bool usb_kbd_polling_callback(usb_hid_dev_t *hid_dev, void *data)
     746{
     747        if (hid_dev == NULL/* || buffer == NULL*/ || data == NULL) {
    762748                // do not continue polling (???)
    763749                return false;
     
    768754       
    769755        // TODO: add return value from this function
    770         usb_kbd_process_data(hid_dev, kbd_dev, buffer, buffer_size);
     756        usb_kbd_process_data(hid_dev, kbd_dev);
    771757       
    772758        return true;
     
    804790        if ((*kbd_dev)->repeat_mtx != NULL) {
    805791                //assert(!fibril_mutex_is_locked((*kbd_dev)->repeat_mtx));
     792                // FIXME - the fibril_mutex_is_locked may not cause
     793                // fibril scheduling
    806794                while (fibril_mutex_is_locked((*kbd_dev)->repeat_mtx)) {}
    807795                free((*kbd_dev)->repeat_mtx);
  • uspace/drv/usbhid/kbd/kbddev.h

    radfdbd5 r1d1bb0f  
    125125int usb_kbd_init(struct usb_hid_dev *hid_dev, void **data);
    126126
    127 bool usb_kbd_polling_callback(struct usb_hid_dev *hid_dev, void *data,
    128                               uint8_t *buffer, size_t buffer_size);
     127bool usb_kbd_polling_callback(struct usb_hid_dev *hid_dev, void *data);
    129128
    130129int usb_kbd_is_initialized(const usb_kbd_t *kbd_dev);
  • uspace/drv/usbhid/kbd/kbdrepeat.c

    radfdbd5 r1d1bb0f  
    9797                                delay = kbd->repeat.delay_between;
    9898                        } else {
    99                                 usb_log_debug("New key to repeat: %u.\n",
     99                                usb_log_debug2("New key to repeat: %u.\n",
    100100                                    kbd->repeat.key_new);
    101101                                kbd->repeat.key_repeated = kbd->repeat.key_new;
     
    104104                } else {
    105105                        if (kbd->repeat.key_repeated > 0) {
    106                                 usb_log_debug("Stopping to repeat key: %u.\n",
     106                                usb_log_debug2("Stopping to repeat key: %u.\n",
    107107                                    kbd->repeat.key_repeated);
    108108                                kbd->repeat.key_repeated = 0;
  • uspace/drv/usbhid/mouse/mousedev.c

    radfdbd5 r1d1bb0f  
    5252#include "mousedev.h"
    5353#include "../usbhid.h"
     54
     55/** Number of simulated arrow-key presses for singel wheel step. */
     56#define ARROWS_PER_SINGLE_WHEEL 3
    5457
    5558// FIXME: remove this header
     
    201204static void usb_mouse_send_wheel(const usb_mouse_t *mouse_dev, int wheel)
    202205{
    203         kbd_event_t ev;
    204        
    205         ev.type = KEY_PRESS;
    206         ev.key = (wheel > 0) ? KC_UP : (wheel < 0) ? KC_DOWN : 0;
    207         ev.mods = 0;
    208         ev.c = 0;
     206        unsigned int key = (wheel > 0) ? KC_UP : KC_DOWN;
    209207
    210208        if (mouse_dev->wheel_phone < 0) {
    211209                usb_log_warning(
    212                     "Connection to console not ready, key discarded.\n");
     210                    "Connection to console not ready, wheel roll discarded.\n");
    213211                return;
    214212        }
    215213       
    216         int count = (wheel < 0) ? -wheel : wheel;
     214        int count = ((wheel < 0) ? -wheel : wheel) * ARROWS_PER_SINGLE_WHEEL;
    217215        int i;
    218216       
    219         for (i = 0; i < count * 3; ++i) {
    220                 usb_log_debug2("Sending key %d to the console\n", ev.key);
    221                 async_obsolete_msg_4(mouse_dev->wheel_phone, KBDEV_EVENT, ev.type,
    222                     ev.key, ev.mods, ev.c);
    223                 // send key release right away
    224                 async_obsolete_msg_4(mouse_dev->wheel_phone, KBDEV_EVENT, KEY_RELEASE,
    225                     ev.key, ev.mods, ev.c);
    226         }
    227 }
    228 
    229 /*----------------------------------------------------------------------------*/
    230 
    231 static bool usb_mouse_process_report(usb_hid_dev_t *hid_dev,
    232                                      usb_mouse_t *mouse_dev, uint8_t *buffer,
    233                                      size_t buffer_size)
     217        for (i = 0; i < count; i++) {
     218                /* Send arrow press and release. */
     219                usb_log_debug2("Sending key %d to the console\n", key);
     220                async_obsolete_msg_4(mouse_dev->wheel_phone, KBDEV_EVENT,
     221                    KEY_PRESS, key, 0, 0);
     222                async_obsolete_msg_4(mouse_dev->wheel_phone, KBDEV_EVENT,
     223                    KEY_RELEASE, key, 0, 0);
     224        }
     225}
     226
     227/*----------------------------------------------------------------------------*/
     228
     229static int get_mouse_axis_move_value(uint8_t rid, usb_hid_report_t *report,
     230    int32_t usage)
     231{
     232        int result = 0;
     233
     234        usb_hid_report_path_t *path = usb_hid_report_path();
     235        usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_GENERIC_DESKTOP,
     236            usage);
     237
     238        usb_hid_report_path_set_report_id(path, rid);
     239
     240        usb_hid_report_field_t *field = usb_hid_report_get_sibling(
     241            report, NULL, path, USB_HID_PATH_COMPARE_END,
     242            USB_HID_REPORT_TYPE_INPUT);
     243
     244        if (field != NULL) {
     245                result = field->value;
     246        }
     247
     248        usb_hid_report_path_free(path);
     249
     250        return result;
     251}
     252
     253static bool usb_mouse_process_report(usb_hid_dev_t *hid_dev,
     254    usb_mouse_t *mouse_dev)
    234255{
    235256        assert(mouse_dev != NULL);
    236        
    237         usb_log_debug2("got buffer: %s.\n",
    238             usb_debug_str_buffer(buffer, buffer_size, 0));
    239257       
    240258        if (mouse_dev->mouse_phone < 0) {
     
    243261        }
    244262
    245         /*
    246          * parse the input report
    247          */
    248        
    249         usb_log_debug(NAME " Calling usb_hid_parse_report() with "
    250             "buffer %s\n", usb_debug_str_buffer(buffer, buffer_size, 0));
    251        
    252         uint8_t report_id;
    253        
    254         int rc = usb_hid_parse_report(hid_dev->report, buffer, buffer_size,
    255             &report_id);
    256        
    257         if (rc != EOK) {
    258                 usb_log_warning(NAME "Error in usb_hid_parse_report(): %s\n",
    259                     str_error(rc));
    260                 return true;
    261         }
    262        
    263         /*
    264          * X
    265          */
    266         int shift_x = 0;
    267        
    268         usb_hid_report_path_t *path = usb_hid_report_path();
    269         usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_GENERIC_DESKTOP,
    270             USB_HIDUT_USAGE_GENERIC_DESKTOP_X);
    271 
    272         usb_hid_report_path_set_report_id(path, report_id);
    273 
    274         usb_hid_report_field_t *field = usb_hid_report_get_sibling(
    275             hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END,
    276             USB_HID_REPORT_TYPE_INPUT);
    277 
    278         if (field != NULL) {
    279                 usb_log_debug(NAME " VALUE(%X) USAGE(%X)\n", field->value,
    280                     field->usage);
    281                 shift_x = field->value;
    282         }
    283 
    284         usb_hid_report_path_free(path);
    285        
    286         /*
    287          * Y
    288          */
    289         int shift_y = 0;
    290        
    291         path = usb_hid_report_path();
    292         usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_GENERIC_DESKTOP,
    293             USB_HIDUT_USAGE_GENERIC_DESKTOP_Y);
    294 
    295         usb_hid_report_path_set_report_id(path, report_id);
    296 
    297         field = usb_hid_report_get_sibling(
    298             hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END,
    299             USB_HID_REPORT_TYPE_INPUT);
    300 
    301         if (field != NULL) {
    302                 usb_log_debug(NAME " VALUE(%X) USAGE(%X)\n", field->value,
    303                     field->usage);
    304                 shift_y = field->value;
    305         }
    306 
    307         usb_hid_report_path_free(path);
    308        
     263        int shift_x = get_mouse_axis_move_value(hid_dev->report_id,
     264            hid_dev->report, USB_HIDUT_USAGE_GENERIC_DESKTOP_X);
     265        int shift_y = get_mouse_axis_move_value(hid_dev->report_id,
     266            hid_dev->report, USB_HIDUT_USAGE_GENERIC_DESKTOP_Y);
     267        int wheel = get_mouse_axis_move_value(hid_dev->report_id,
     268            hid_dev->report, USB_HIDUT_USAGE_GENERIC_DESKTOP_WHEEL);
     269
    309270        if ((shift_x != 0) || (shift_y != 0)) {
    310271                async_obsolete_req_2_0(mouse_dev->mouse_phone,
    311272                    MEVENT_MOVE, shift_x, shift_y);
    312273        }
    313        
    314         /*
    315          * Wheel
    316          */
    317         int wheel = 0;
    318        
    319         path = usb_hid_report_path();
    320         usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_GENERIC_DESKTOP,
    321             USB_HIDUT_USAGE_GENERIC_DESKTOP_WHEEL);
    322 
    323         usb_hid_report_path_set_report_id(path, report_id);
    324        
    325         field = usb_hid_report_get_sibling(
    326             hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END,
    327             USB_HID_REPORT_TYPE_INPUT);
    328 
    329         if (field != NULL) {
    330                 usb_log_debug(NAME " VALUE(%X) USAGE(%X)\n", field->value,
    331                     field->usage);
    332                 wheel = field->value;
    333         }
    334 
    335         usb_hid_report_path_free(path);
    336        
    337         // send arrow up for positive direction and arrow down for negative
    338         // direction; three arrows for difference of 1
    339         usb_mouse_send_wheel(mouse_dev, wheel);
    340        
     274
     275        if (wheel != 0) {
     276                usb_mouse_send_wheel(mouse_dev, wheel);
     277        }
    341278       
    342279        /*
    343280         * Buttons
    344281         */
    345         path = usb_hid_report_path();
     282        usb_hid_report_path_t *path = usb_hid_report_path();
    346283        usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_BUTTON, 0);
    347         usb_hid_report_path_set_report_id(path, report_id);
    348        
    349         field = usb_hid_report_get_sibling(
     284        usb_hid_report_path_set_report_id(path, hid_dev->report_id);
     285       
     286        usb_hid_report_field_t *field = usb_hid_report_get_sibling(
    350287            hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END
    351288            | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,
     
    353290
    354291        while (field != NULL) {
    355                 usb_log_debug(NAME " VALUE(%X) USAGE(%X)\n", field->value,
     292                usb_log_debug2(NAME " VALUE(%X) USAGE(%X)\n", field->value,
    356293                    field->usage);
    357294               
     
    510447/*----------------------------------------------------------------------------*/
    511448
    512 bool usb_mouse_polling_callback(usb_hid_dev_t *hid_dev, void *data,
    513      uint8_t *buffer, size_t buffer_size)
    514 {
    515         usb_log_debug("usb_mouse_polling_callback()\n");
    516         usb_debug_str_buffer(buffer, buffer_size, 0);
    517        
     449bool usb_mouse_polling_callback(usb_hid_dev_t *hid_dev, void *data)
     450{
    518451        if (hid_dev == NULL || data == NULL) {
    519452                usb_log_error("Missing argument to the mouse polling callback."
     
    524457        usb_mouse_t *mouse_dev = (usb_mouse_t *)data;
    525458               
    526         return usb_mouse_process_report(hid_dev, mouse_dev, buffer,
    527                                         buffer_size);
     459        return usb_mouse_process_report(hid_dev, mouse_dev);
    528460}
    529461
  • uspace/drv/usbhid/mouse/mousedev.h

    radfdbd5 r1d1bb0f  
    6565int usb_mouse_init(struct usb_hid_dev *hid_dev, void **data);
    6666
    67 bool usb_mouse_polling_callback(struct usb_hid_dev *hid_dev, void *data,
    68     uint8_t *buffer, size_t buffer_size);
     67bool usb_mouse_polling_callback(struct usb_hid_dev *hid_dev, void *data);
    6968
    7069void usb_mouse_deinit(struct usb_hid_dev *hid_dev, void *data);
  • uspace/drv/usbhid/multimedia/multimedia.c

    radfdbd5 r1d1bb0f  
    9494       
    9595        usb_multimedia_t *multim_dev = (usb_multimedia_t *)fun->driver_data;
    96         //usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data;
    9796       
    9897        if (multim_dev == NULL) {
     
    274273/*----------------------------------------------------------------------------*/
    275274
    276 bool usb_multimedia_polling_callback(struct usb_hid_dev *hid_dev, void *data,
    277     uint8_t *buffer, size_t buffer_size)
     275bool usb_multimedia_polling_callback(struct usb_hid_dev *hid_dev, void *data)
    278276{
    279277        // TODO: checks
    280         if (hid_dev == NULL || data == NULL || buffer == NULL) {
     278        if (hid_dev == NULL || data == NULL) {
    281279                return false;
    282280        }
    283        
    284         usb_log_debug(NAME " usb_lgtch_polling_callback(%p, %p, %zu)\n",
    285             hid_dev, buffer, buffer_size);
    286        
     281
    287282        usb_multimedia_t *multim_dev = (usb_multimedia_t *)data;
    288 
    289         usb_log_debug(NAME " Calling usb_hid_parse_report() with "
    290             "buffer %s\n", usb_debug_str_buffer(buffer, buffer_size, 0));
    291283       
    292284        usb_hid_report_path_t *path = usb_hid_report_path();
    293285        usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_CONSUMER, 0);
    294286
    295         uint8_t report_id;
    296        
    297         int rc = usb_hid_parse_report(hid_dev->report, buffer, buffer_size,
    298             &report_id);
    299        
    300         if (rc != EOK) {
    301                 usb_log_warning(NAME "Error in usb_hid_parse_report(): %s\n",
    302                     str_error(rc));
    303                 return true;
    304         }
    305        
    306         usb_hid_report_path_set_report_id(path, report_id);
     287        usb_hid_report_path_set_report_id(path, hid_dev->report_id);
    307288
    308289        usb_hid_report_field_t *field = usb_hid_report_get_sibling(
  • uspace/drv/usbhid/multimedia/multimedia.h

    radfdbd5 r1d1bb0f  
    4747void usb_multimedia_deinit(struct usb_hid_dev *hid_dev, void *data);
    4848
    49 bool usb_multimedia_polling_callback(struct usb_hid_dev *hid_dev, void *data,
    50     uint8_t *buffer, size_t buffer_size);
     49bool usb_multimedia_polling_callback(struct usb_hid_dev *hid_dev, void *data);
    5150
    5251/*----------------------------------------------------------------------------*/
  • uspace/drv/usbhid/subdrivers.h

    radfdbd5 r1d1bb0f  
    4949/*----------------------------------------------------------------------------*/
    5050
    51 /* TODO: This mapping must contain some other information to get the proper
    52  *       interface.
     51/** Structure representing the mapping between device requirements and the
     52 *  subdriver supposed to handle this device.
     53 *
     54 * By filling in this structure and adding it to the usb_hid_subdrivers array,
     55 * a new subdriver mapping will be created and used by the HID driver when it
     56 * searches for appropriate subdrivers for a device.
    5357 */
    5458typedef struct usb_hid_subdriver_mapping {
     59        /** Usage path that the device's Input reports must contain.
     60         *
     61         * It is an array of pairs <usage_page, usage>, terminated by a <0, 0>
     62         * pair. If you do not wish to specify the device in this way, set this
     63         * to NULL.
     64         */
    5565        const usb_hid_subdriver_usage_t *usage_path;
     66       
     67        /** Report ID for which the path should apply. */
    5668        int report_id;
     69       
     70        /** Compare type for the Usage path. */
    5771        int compare;
     72       
     73        /** Vendor ID (set to -1 if not specified). */
    5874        int vendor_id;
     75       
     76        /** Product ID (set to -1 if not specified). */
    5977        int product_id;
     78       
     79        /** Subdriver for controlling this device. */
    6080        usb_hid_subdriver_t subdriver;
    6181} usb_hid_subdriver_mapping_t;
  • uspace/drv/usbhid/usbhid.c

    radfdbd5 r1d1bb0f  
    572572       
    573573        assert(hid_dev->input_report != NULL);
    574         usb_log_debug("Max input report size: %zu, buffer size: %zu\n",
    575             hid_dev->max_input_report_size, buffer_size);
     574        usb_log_debug("New data [%zu/%zu]: %s\n", buffer_size,
     575            hid_dev->max_input_report_size,
     576            usb_debug_str_buffer(buffer, buffer_size, 0));
    576577
    577578        if (hid_dev->max_input_report_size >= buffer_size) {
     
    582583        }
    583584       
     585        // parse the input report
     586       
     587        int rc = usb_hid_parse_report(hid_dev->report, buffer, buffer_size,
     588            &hid_dev->report_id);
     589       
     590        if (rc != EOK) {
     591                usb_log_warning("Error in usb_hid_parse_report():"
     592                    "%s\n", str_error(rc));
     593        }       
     594       
    584595        bool cont = false;
    585596       
     
    588599                if (hid_dev->subdrivers[i].poll != NULL
    589600                    && hid_dev->subdrivers[i].poll(hid_dev,
    590                         hid_dev->subdrivers[i].data, buffer, buffer_size)) {
     601                        hid_dev->subdrivers[i].data)) {
    591602                        cont = true;
    592603                }
  • uspace/drv/usbhid/usbhid.h

    radfdbd5 r1d1bb0f  
    4646#include <bool.h>
    4747
    48 struct usb_hid_dev;
     48typedef struct usb_hid_dev usb_hid_dev_t;
     49typedef struct usb_hid_subdriver usb_hid_subdriver_t;
    4950
    50 typedef int (*usb_hid_driver_init_t)(struct usb_hid_dev *, void **data);
    51 typedef void (*usb_hid_driver_deinit_t)(struct usb_hid_dev *, void *data);
    52 typedef bool (*usb_hid_driver_poll)(struct usb_hid_dev *, void *data, uint8_t *,
    53                                     size_t);
    54 typedef int (*usb_hid_driver_poll_ended)(struct usb_hid_dev *, void *data,
    55                                          bool reason);
     51/** Subdriver initialization callback.
     52 *
     53 * @param dev Backing USB HID device.
     54 * @param data Custom subdriver data (pointer where to store them).
     55 * @return Error code.
     56 */
     57typedef int (*usb_hid_driver_init_t)(usb_hid_dev_t *dev, void **data);
    5658
    57 typedef struct usb_hid_subdriver {     
     59/** Subdriver deinitialization callback.
     60 *
     61 * @param dev Backing USB HID device.
     62 * @param data Custom subdriver data.
     63 */
     64typedef void (*usb_hid_driver_deinit_t)(usb_hid_dev_t *dev, void *data);
     65
     66/** Subdriver callback on data from device.
     67 *
     68 * @param dev Backing USB HID device.
     69 * @param data Custom subdriver data.
     70 * @return Whether to continue polling (typically true always).
     71 */
     72typedef bool (*usb_hid_driver_poll_t)(usb_hid_dev_t *dev, void *data);
     73
     74/** Subdriver callback after communication with the device ceased.
     75 *
     76 * @param dev Backing USB HID device.
     77 * @param data Custom subdriver data.
     78 * @param ended_due_to_errors Whether communication ended due to errors in
     79 *      communication (true) or deliberately by driver (false).
     80 */
     81typedef void (*usb_hid_driver_poll_ended_t)(usb_hid_dev_t *dev, void *data,
     82    bool ended_due_to_errors);
     83
     84struct usb_hid_subdriver {
    5885        /** Function to be called when initializing HID device. */
    5986        usb_hid_driver_init_t init;
     
    6188        usb_hid_driver_deinit_t deinit;
    6289        /** Function to be called when data arrives from the device. */
    63         usb_hid_driver_poll poll;
     90        usb_hid_driver_poll_t poll;
    6491        /** Function to be called when polling ends. */
    65         usb_hid_driver_poll_ended poll_end;
     92        usb_hid_driver_poll_ended_t poll_end;
    6693        /** Arbitrary data needed by the subdriver. */
    6794        void *data;
    68 } usb_hid_subdriver_t;
     95};
    6996
    7097/*----------------------------------------------------------------------------*/
     
    7299 * Structure for holding general HID device data.
    73100 */
    74 typedef struct usb_hid_dev {
     101struct usb_hid_dev {
    75102        /** Structure holding generic USB device information. */
    76103        usb_device_t *usb_dev;
     
    94121        usb_hid_report_t *report;
    95122       
     123        uint8_t report_id;
     124       
    96125        uint8_t *input_report;
    97126       
     
    100129       
    101130        int report_nr;
    102 } usb_hid_dev_t;
     131};
    103132
    104133/*----------------------------------------------------------------------------*/
  • uspace/drv/usbhub/ports.c

    radfdbd5 r1d1bb0f  
    140140                usb_hub_port_reset_completed(hub, port, status);
    141141        }
    142         usb_log_debug("Status x%x : %d\n ", status, status);
     142        usb_log_debug("Port %d status 0x%08" PRIx32 "\n", (int) port, status);
    143143
    144144        usb_port_status_set_bit(
  • uspace/lib/c/generic/str.c

    radfdbd5 r1d1bb0f  
    540540
    541541        dstr_size = str_size(dest);
     542        if (dstr_size >= size) {
     543                return;
     544        }
    542545        str_cpy(dest + dstr_size, size - dstr_size, src);
    543546}
  • uspace/lib/drv/Makefile

    radfdbd5 r1d1bb0f  
    3636        generic/dev_iface.c \
    3737        generic/log.c \
     38        generic/logbuf.c \
    3839        generic/remote_hw_res.c \
    3940        generic/remote_char_dev.c \
  • uspace/lib/drv/include/ddf/log.h

    radfdbd5 r1d1bb0f  
    3939extern void ddf_msg(log_level_t, const char *, ...);
    4040
     41extern void ddf_dump_buffer(char *, size_t, const void *, size_t, size_t,
     42    size_t);
     43
    4144#endif
    4245
  • uspace/lib/usb/include/usb/usb.h

    radfdbd5 r1d1bb0f  
    6969        USB_DIRECTION_BOTH
    7070} usb_direction_t;
     71
     72const char *usb_str_direction(usb_direction_t);
    7173
    7274/** USB speeds. */
  • uspace/lib/usb/src/debug.c

    radfdbd5 r1d1bb0f  
    3838#include <stdlib.h>
    3939#include <stdio.h>
     40#include <ddf/log.h>
    4041#include <usb/debug.h>
    4142
     
    6768                if (rc > 0) {
    6869                        log_stream = fopen(fname, "w");
     70                        if (log_stream != NULL) {
     71                                setvbuf(log_stream, NULL, _IOFBF, BUFSIZ);
     72                        }
    6973                        free(fname);
    7074                }
     
    193197        bzero(buffer_dump[buffer_dump_index], BUFFER_DUMP_LEN);
    194198
    195         if (buffer == NULL) {
    196                 return "(null)";
    197         }
    198         if (size == 0) {
    199                 return "(empty)";
    200         }
    201         if ((dumped_size == 0) || (dumped_size > size)) {
    202                 dumped_size = size;
    203         }
    204 
    205         /* How many bytes are available in the output buffer. */
    206         size_t buffer_remaining_size = BUFFER_DUMP_LEN - 1 - REMAINDER_STR_LEN;
    207         char *it = buffer_dump[buffer_dump_index];
    208 
    209         size_t index = 0;
    210 
    211         while (index < size) {
    212                 /* Determine space before the number. */
    213                 const char *space_before;
    214                 if (index == 0) {
    215                         space_before = "";
    216                 } else if ((index % BUFFER_DUMP_GROUP_SIZE) == 0) {
    217                         space_before = "  ";
    218                 } else {
    219                         space_before = " ";
    220                 }
    221 
    222                 /*
    223                  * Add the byte as a hexadecimal number plus the space.
    224                  * We do it into temporary buffer to ensure that always
    225                  * the whole byte is printed.
    226                  */
    227                 int val = buffer[index];
    228                 char current_byte[16];
    229                 int printed = snprintf(current_byte, 16,
    230                     "%s%02x", space_before, val);
    231                 if (printed < 0) {
    232                         break;
    233                 }
    234 
    235                 if ((size_t) printed > buffer_remaining_size) {
    236                         break;
    237                 }
    238 
    239                 /* We can safely add 1, because space for end 0 is reserved. */
    240                 str_append(it, buffer_remaining_size + 1, current_byte);
    241 
    242                 buffer_remaining_size -= printed;
    243                 /* Point at the terminator 0. */
    244                 it += printed;
    245                 index++;
    246 
    247                 if (index >= dumped_size) {
    248                         break;
    249                 }
    250         }
    251 
    252         /* Add how many bytes were not printed. */
    253         if (index < size) {
    254                 snprintf(it, REMAINDER_STR_LEN,
    255                     REMAINDER_STR_FMT, size - index);
    256         }
     199        /* Do the actual dump. */
     200        ddf_dump_buffer(buffer_dump[buffer_dump_index], BUFFER_DUMP_LEN,
     201            buffer, 1, size, dumped_size);
    257202
    258203        /* Next time, use the other buffer. */
  • uspace/lib/usb/src/hc.c

    radfdbd5 r1d1bb0f  
    9898                return EBUSY;
    9999       
    100         async_sess_t *sess = devman_device_connect(EXCHANGE_SERIALIZE,
     100        async_sess_t *sess = devman_device_connect(EXCHANGE_ATOMIC,
    101101            connection->hc_handle, 0);
    102102        if (!sess)
     
    177177{
    178178        async_sess_t *parent_sess =
    179             devman_parent_device_connect(EXCHANGE_SERIALIZE, dev_handle,
     179            devman_parent_device_connect(EXCHANGE_ATOMIC, dev_handle,
    180180            IPC_FLAG_BLOCKING);
    181181        if (!parent_sess)
     
    241241{
    242242        async_sess_t *parent_sess =
    243             devman_parent_device_connect(EXCHANGE_SERIALIZE, device_handle,
     243            devman_parent_device_connect(EXCHANGE_ATOMIC, device_handle,
    244244            IPC_FLAG_BLOCKING);
    245245        if (!parent_sess)
  • uspace/lib/usb/src/usb.c

    radfdbd5 r1d1bb0f  
    5858};
    5959
     60static const char *str_direction[] = {
     61        "in",
     62        "out",
     63        "both"
     64};
     65
    6066/** String representation for USB transfer type.
    6167 *
     
    8490}
    8591
     92/** String representation of USB direction.
     93 *
     94 * @param d The direction.
     95 * @return Direction as a string (in English).
     96 */
     97const char *usb_str_direction(usb_direction_t d)
     98{
     99        if (d >= ARR_SIZE(str_direction)) {
     100                return "invalid";
     101        }
     102        return str_direction[d];
     103}
     104
    86105/** String representation of USB speed.
    87106 *
  • uspace/lib/usbdev/src/pipes.c

    radfdbd5 r1d1bb0f  
    8181{
    8282        async_sess_t *parent_sess =
    83             devman_parent_device_connect(EXCHANGE_SERIALIZE, device->handle,
     83            devman_parent_device_connect(EXCHANGE_ATOMIC, device->handle,
    8484            IPC_FLAG_BLOCKING);
    8585        if (!parent_sess)
     
    122122       
    123123        async_sess_t *parent_sess =
    124             devman_parent_device_connect(EXCHANGE_SERIALIZE, dev->handle,
     124            devman_parent_device_connect(EXCHANGE_ATOMIC, dev->handle,
    125125            IPC_FLAG_BLOCKING);
    126126        if (!parent_sess)
  • uspace/lib/usbhid/src/hidreq.c

    radfdbd5 r1d1bb0f  
    8282        value |= (type << 8);
    8383
    84         usb_log_debug("Sending Set_Report request to the device.\n");
     84        usb_log_debug("Sending Set Report request to the device.\n");
    8585       
    8686        rc = usb_control_request_set(ctrl_pipe,
     
    8989
    9090        if (rc != EOK) {
    91                 usb_log_warning("Error sending output report to the keyboard: "
    92                     "%s.\n", str_error(rc));
     91                usb_log_warning("Error sending Set Report request to the "
     92                    "device: %s.\n", str_error(rc));
    9393                return rc;
    9494        }
     
    129129        int rc;
    130130
    131         usb_log_debug("Sending Set_Protocol request to the device ("
     131        usb_log_debug("Sending Set Protocol request to the device ("
    132132            "protocol: %d, iface: %d).\n", protocol, iface_no);
    133133       
     
    137137
    138138        if (rc != EOK) {
    139                 usb_log_warning("Error sending output report to the keyboard: "
    140                     "%s.\n", str_error(rc));
     139                usb_log_warning("Error sending Set Protocol request to the "
     140                    "device: %s.\n", str_error(rc));
    141141                return rc;
    142142        }
     
    177177        int rc;
    178178
    179         usb_log_debug("Sending Set_Idle request to the device ("
     179        usb_log_debug("Sending Set Idle request to the device ("
    180180            "duration: %u, iface: %d).\n", duration, iface_no);
    181181       
     
    187187
    188188        if (rc != EOK) {
    189                 usb_log_warning("Error sending output report to the keyboard: "
     189                usb_log_warning("Error sending Set Idle request to the device: "
    190190                    "%s.\n", str_error(rc));
    191191                return rc;
     
    235235        value |= (type << 8);
    236236       
    237         usb_log_debug("Sending Get_Report request to the device.\n");
     237        usb_log_debug("Sending Get Report request to the device.\n");
    238238       
    239239        rc = usb_control_request_get(ctrl_pipe,
     
    243243
    244244        if (rc != EOK) {
    245                 usb_log_warning("Error sending output report to the keyboard: "
     245                usb_log_warning("Error sending Get Report request to the device: "
    246246                    "%s.\n", str_error(rc));
    247247                return rc;
     
    283283        int rc;
    284284
    285         usb_log_debug("Sending Get_Protocol request to the device ("
     285        usb_log_debug("Sending Get Protocol request to the device ("
    286286            "iface: %d).\n", iface_no);
    287287       
     
    294294
    295295        if (rc != EOK) {
    296                 usb_log_warning("Error sending output report to the keyboard: "
    297                     "%s.\n", str_error(rc));
     296                usb_log_warning("Error sending Get Protocol request to the "
     297                    "device: %s.\n", str_error(rc));
    298298                return rc;
    299299        }
     
    344344        int rc;
    345345
    346         usb_log_debug("Sending Get_Idle request to the device ("
     346        usb_log_debug("Sending Get Idle request to the device ("
    347347            "iface: %d).\n", iface_no);
    348348       
     
    357357
    358358        if (rc != EOK) {
    359                 usb_log_warning("Error sending output report to the keyboard: "
     359                usb_log_warning("Error sending Get Idle request to the device: "
    360360                    "%s.\n", str_error(rc));
    361361                return rc;
  • uspace/lib/usbhost/include/usb/host/batch.h

    radfdbd5 r1d1bb0f  
    6161};
    6262
     63/** Printf formatting string for dumping usb_transfer_batch_t. */
     64#define USB_TRANSFER_BATCH_FMT "[%d:%d %s %s-%s %zuB/%zu]"
     65
     66/** Printf arguments for dumping usb_transfer_batch_t.
     67 * @param batch USB transfer batch to be dumped.
     68 */
     69#define USB_TRANSFER_BATCH_ARGS(batch) \
     70        (batch).ep->address, (batch).ep->endpoint, \
     71        usb_str_speed((batch).ep->speed), \
     72        usb_str_transfer_type_short((batch).ep->transfer_type), \
     73        usb_str_direction((batch).ep->direction), \
     74        (batch).buffer_size, (batch).ep->max_packet_size
     75
     76
    6377void usb_transfer_batch_init(
    6478    usb_transfer_batch_t *instance,
  • uspace/lib/usbhost/src/batch.c

    radfdbd5 r1d1bb0f  
    128128        memcpy(instance->buffer, instance->data_buffer, instance->buffer_size);
    129129
    130         usb_log_debug("Batch(%p) done (T%d.%d, %s %s in, %zuB): %s (%d).\n",
    131             instance, instance->ep->address, instance->ep->endpoint,
    132             usb_str_speed(instance->ep->speed),
    133             usb_str_transfer_type_short(instance->ep->transfer_type),
    134             instance->transfered_size, str_error(instance->error),
    135             instance->error);
     130        usb_log_debug("Batch %p " USB_TRANSFER_BATCH_FMT " completed (%zuB): %s.\n",
     131            instance, USB_TRANSFER_BATCH_ARGS(*instance),
     132            instance->transfered_size, str_error(instance->error));
    136133
    137134        instance->callback_in(instance->fun, instance->error,
     
    148145        assert(instance->callback_out);
    149146
    150         usb_log_debug("Batch(%p) done (T%d.%d, %s %s out): %s (%d).\n",
    151             instance, instance->ep->address, instance->ep->endpoint,
    152             usb_str_speed(instance->ep->speed),
    153             usb_str_transfer_type_short(instance->ep->transfer_type),
    154             str_error(instance->error), instance->error);
     147        usb_log_debug("Batch %p " USB_TRANSFER_BATCH_FMT " completed: %s.\n",
     148            instance, USB_TRANSFER_BATCH_ARGS(*instance),
     149            str_error(instance->error));
    155150
    156151        instance->callback_out(instance->fun,
     
    165160{
    166161        assert(instance);
    167         usb_log_debug("Batch(%p) disposing.\n", instance);
     162        usb_log_debug2("Batch %p " USB_TRANSFER_BATCH_FMT " disposing.\n",
     163            instance, USB_TRANSFER_BATCH_ARGS(*instance));
    168164        if (instance->private_data) {
    169165                assert(instance->private_data_dtor);
Note: See TracChangeset for help on using the changeset viewer.