Changeset 400735e in mainline


Ignore:
Timestamp:
2011-05-28T14:30:58Z (13 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
3fb5a3e
Parents:
e8f826b (diff), 48141f0 (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 development/ changes

Files:
1 added
1 deleted
55 edited
1 moved

Legend:

Unmodified
Added
Removed
  • HelenOS.config

    re8f826b r400735e  
    570570
    571571% USB release build (less logging)
    572 ! CONFIG_USB_RELEASE_BUILD (n/y)
     572! CONFIG_USB_RELEASE_BUILD (y/n)
    573573
    574574% Start virtual USB host controller
     
    576576
    577577% Polling UHCI & OHCI (no interrupts)
    578 ! [PLATFORM=ia32|PLATFORM=amd64] CONFIG_USBHC_NO_INTERRUPTS (y/n)
     578! [PLATFORM=ia32|PLATFORM=amd64] CONFIG_USBHC_NO_INTERRUPTS (n/y)
    579579
    580580% Run devman in kconsole (not recommended)
  • uspace/app/mkbd/Makefile

    re8f826b r400735e  
    3131
    3232LIBS = \
     33        $(LIBUSBHID_PREFIX)/libusbhid.a \
    3334        $(LIBUSBDEV_PREFIX)/libusbdev.a \
    3435        $(LIBUSB_PREFIX)/libusb.a \
    35         $(LIBDRV_PREFIX)/libdrv.a
     36        $(LIBDRV_PREFIX)/libdrv.a 
    3637EXTRA_CFLAGS = \
    3738        -I$(LIBUSB_PREFIX)/include \
    3839        -I$(LIBUSBDEV_PREFIX)/include \
    39         -I$(LIBDRV_PREFIX)/include
     40        -I$(LIBDRV_PREFIX)/include \
     41        -I$(LIBUSBHID_PREFIX)/include
    4042
    4143SOURCES = \
  • uspace/app/mkbd/main.c

    re8f826b r400735e  
    4545#include <devmap.h>
    4646#include <usb/dev/hub.h>
    47 #include <usb/hc.h>
     47//#include <usb/host.h>
     48//#include <usb/driver.h>
     49#include <usb/hid/iface.h>
    4850#include <usb/dev/pipes.h>
     51#include <async.h>
     52#include <usb/hid/usages/core.h>
     53#include <usb/hid/hidparser.h>
     54#include <usb/hid/hiddescriptor.h>
     55#include <usb/hid/usages/consumer.h>
     56#include <assert.h>
    4957
    5058#define NAME "mkbd"
     
    5260static int dev_phone = -1;
    5361
    54 //static void print_found_hc(size_t class_index, const char *path)
    55 //{
    56 //      // printf(NAME ": host controller %zu is `%s'.\n", class_index, path);
    57 //      printf("Bus %02zu: %s\n", class_index, path);
    58 //}
    59 //static void print_found_dev(usb_address_t addr, const char *path)
    60 //{
    61 //      // printf(NAME ":     device with address %d is `%s'.\n", addr, path);
    62 //      printf("  Device %02d: %s\n", addr, path);
    63 //}
    64 
    65 //static void print_hc_devices(devman_handle_t hc_handle)
    66 //{
    67 //      int rc;
    68 //      usb_hc_connection_t conn;
    69 
    70 //      usb_hc_connection_initialize(&conn, hc_handle);
    71 //      rc = usb_hc_connection_open(&conn);
    72 //      if (rc != EOK) {
    73 //              printf(NAME ": failed to connect to HC: %s.\n",
    74 //                  str_error(rc));
    75 //              return;
     62static int initialize_report_parser(int dev_phone, usb_hid_report_t **report)
     63{
     64        *report = (usb_hid_report_t *)malloc(sizeof(usb_hid_report_t));
     65        if (*report == NULL) {
     66                return ENOMEM;
     67        }
     68       
     69        int rc = usb_hid_report_init(*report);
     70        if (rc != EOK) {
     71                usb_hid_free_report(*report);
     72                *report = NULL;
     73                printf("usb_hid_report_init() failed.\n");
     74                return rc;
     75        }
     76       
     77        // get the report descriptor length from the device
     78        size_t report_desc_size;
     79        rc = usbhid_dev_get_report_descriptor_length(
     80            dev_phone, &report_desc_size);
     81        if (rc != EOK) {
     82                usb_hid_free_report(*report);
     83                *report = NULL;
     84                printf("usbhid_dev_get_report_descriptor_length() failed.\n");
     85                return rc;
     86        }
     87       
     88        if (report_desc_size == 0) {
     89                usb_hid_free_report(*report);
     90                *report = NULL;
     91                printf("usbhid_dev_get_report_descriptor_length() returned 0.\n");
     92                return EINVAL;  // TODO: other error code?
     93        }
     94       
     95        uint8_t *desc = (uint8_t *)malloc(report_desc_size);
     96        if (desc == NULL) {
     97                usb_hid_free_report(*report);
     98                *report = NULL;
     99                return ENOMEM;
     100        }
     101       
     102        // get the report descriptor from the device
     103        size_t actual_size;
     104        rc = usbhid_dev_get_report_descriptor(dev_phone, desc, report_desc_size,
     105            &actual_size);
     106        if (rc != EOK) {
     107                usb_hid_free_report(*report);
     108                *report = NULL;
     109                free(desc);
     110                printf("usbhid_dev_get_report_descriptor() failed.\n");
     111                return rc;
     112        }
     113       
     114        if (actual_size != report_desc_size) {
     115                usb_hid_free_report(*report);
     116                *report = NULL;
     117                free(desc);
     118                printf("usbhid_dev_get_report_descriptor() returned wrong size:"
     119                    " %zu, expected: %zu.\n", actual_size, report_desc_size);
     120                return EINVAL;  // TODO: other error code?
     121        }
     122       
     123        // initialize the report parser
     124       
     125        rc = usb_hid_parse_report_descriptor(*report, desc, report_desc_size);
     126        free(desc);
     127       
     128        if (rc != EOK) {
     129                free(desc);
     130                printf("usb_hid_parse_report_descriptor() failed.\n");
     131                return rc;
     132        }
     133       
     134        return EOK;
     135}
     136
     137static void print_key(uint8_t *buffer, size_t size, usb_hid_report_t *report)
     138{
     139        assert(buffer != NULL);
     140        assert(report != NULL);
     141       
     142//      printf("Calling usb_hid_parse_report() with size %zu and "
     143//          "buffer: \n", size);
     144//      for (size_t i = 0; i < size; ++i) {
     145//              printf(" %X ", buffer[i]);
    76146//      }
    77 //      usb_address_t addr;
    78 //      for (addr = 1; addr < 5; addr++) {
    79 //              devman_handle_t dev_handle;
    80 //              rc = usb_hc_get_handle_by_address(&conn, addr, &dev_handle);
    81 //              if (rc != EOK) {
    82 //                      continue;
    83 //              }
    84 //              char path[MAX_PATH_LENGTH];
    85 //              rc = devman_get_device_path(dev_handle, path, MAX_PATH_LENGTH);
    86 //              if (rc != EOK) {
    87 //                      continue;
    88 //              }
    89 //              print_found_dev(addr, path);
    90 //      }
    91 //      usb_hc_connection_close(&conn);
    92 //}
    93 
    94 static bool try_parse_class_and_address(const char *path,
    95     devman_handle_t *out_hc_handle, usb_address_t *out_device_address)
    96 {
    97         size_t class_index;
    98         size_t address;
    99         int rc;
    100         char *ptr;
    101 
    102         rc = str_size_t(path, &ptr, 10, false, &class_index);
    103         if (rc != EOK) {
    104                 return false;
    105         }
    106         if ((*ptr == ':') || (*ptr == '.')) {
    107                 ptr++;
    108         } else {
    109                 return false;
    110         }
    111         rc = str_size_t(ptr, NULL, 10, true, &address);
    112         if (rc != EOK) {
    113                 return false;
    114         }
    115         rc = usb_ddf_get_hc_handle_by_class(class_index, out_hc_handle);
    116         if (rc != EOK) {
    117                 return false;
    118         }
    119         if (out_device_address != NULL) {
    120                 *out_device_address = (usb_address_t) address;
    121         }
    122         return true;
     147//      printf("\n");
     148       
     149        uint8_t report_id;
     150        int rc = usb_hid_parse_report(report, buffer, size, &report_id);
     151        if (rc != EOK) {
     152//              printf("Error parsing report: %s\n", str_error(rc));
     153                return;
     154        }
     155       
     156        usb_hid_report_path_t *path = usb_hid_report_path();
     157        if (path == NULL) {
     158                return;
     159        }
     160       
     161        usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_CONSUMER, 0);
     162       
     163        usb_hid_report_path_set_report_id(path, report_id);
     164
     165        usb_hid_report_field_t *field = usb_hid_report_get_sibling(
     166            report, NULL, path, USB_HID_PATH_COMPARE_END
     167            | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,
     168            USB_HID_REPORT_TYPE_INPUT);
     169       
     170//      printf("Field: %p\n", field);
     171       
     172        while (field != NULL) {
     173//              printf("Field usage: %u, field value: %d\n", field->usage,
     174//                  field->value);
     175                if (field->value != 0) {
     176                        const char *key_str =
     177                            usbhid_multimedia_usage_to_str(field->usage);
     178                        printf("Pressed key: %s\n", key_str);
     179                }
     180               
     181                field = usb_hid_report_get_sibling(
     182                    report, field, path, USB_HID_PATH_COMPARE_END
     183                    | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,
     184                    USB_HID_REPORT_TYPE_INPUT);
     185//              printf("Next field: %p\n", field);
     186        }
     187       
     188        usb_hid_report_path_free(path);
    123189}
    124190
    125 static bool resolve_hc_handle_and_dev_addr(const char *devpath,
    126     devman_handle_t *out_hc_handle, usb_address_t *out_device_address)
    127 {
    128         int rc;
    129 
    130         /* Hack for QEMU to save-up on typing ;-). */
    131         if (str_cmp(devpath, "qemu") == 0) {
    132                 devpath = "/hw/pci0/00:01.2/uhci-rh/usb00_a1";
    133         }
    134 
    135         /* Hack for virtual keyboard. */
    136         if (str_cmp(devpath, "virt") == 0) {
    137                 devpath = "/virt/usbhc/usb00_a1/usb00_a2";
    138         }
    139 
    140         if (try_parse_class_and_address(devpath,
    141             out_hc_handle, out_device_address)) {
    142                 return true;
    143         }
    144 
    145         char *path = str_dup(devpath);
    146         if (path == NULL) {
    147                 return ENOMEM;
    148         }
    149 
    150         devman_handle_t hc = 0;
    151         bool hc_found = false;
    152         usb_address_t addr = 0;
    153         bool addr_found = false;
    154 
    155         /* Remove suffixes and hope that we will encounter device node. */
    156         while (str_length(path) > 0) {
    157                 /* Get device handle first. */
    158                 devman_handle_t dev_handle;
    159                 rc = devman_device_get_handle(path, &dev_handle, 0);
    160                 if (rc != EOK) {
    161                         free(path);
    162                         return false;
    163                 }
    164 
    165                 /* Try to find its host controller. */
    166                 if (!hc_found) {
    167                         rc = usb_hc_find(dev_handle, &hc);
    168                         if (rc == EOK) {
    169                                 hc_found = true;
    170                         }
    171                 }
    172                 /* Try to get its address. */
    173                 if (!addr_found) {
    174                         addr = usb_hc_get_address_by_handle(dev_handle);
    175                         if (addr >= 0) {
    176                                 addr_found = true;
    177                         }
    178                 }
    179 
    180                 /* Speed-up. */
    181                 if (hc_found && addr_found) {
    182                         break;
    183                 }
    184 
    185                 /* Remove the last suffix. */
    186                 char *slash_pos = str_rchr(path, '/');
    187                 if (slash_pos != NULL) {
    188                         *slash_pos = 0;
    189                 }
    190         }
    191 
    192         free(path);
    193 
    194         if (hc_found && addr_found) {
    195                 if (out_hc_handle != NULL) {
    196                         *out_hc_handle = hc;
    197                 }
    198                 if (out_device_address != NULL) {
    199                         *out_device_address = addr;
    200                 }
    201                 return true;
    202         } else {
    203                 return false;
    204         }
    205 }
     191#define MAX_PATH_LENGTH 1024
    206192
    207193static void print_usage(char *app_name)
     
    209195#define _INDENT "      "
    210196
    211         printf(NAME ": Print out what multimedia keys were pressed.\n\n");
    212         printf("Usage: %s device\n", app_name);
    213         printf(_INDENT "The device is a devman path to the device.\n");
     197       printf(NAME ": Print out what multimedia keys were pressed.\n\n");
     198       printf("Usage: %s device\n", app_name);
     199       printf(_INDENT "The device is a devman path to the device.\n");
    214200
    215201#undef _OPTION
     
    219205int main(int argc, char *argv[])
    220206{
     207        int act_event = -1;
    221208       
    222209        if (argc <= 1) {
     
    226213       
    227214        char *devpath = argv[1];
    228 
    229         /* The initialization is here only to make compiler happy. */
    230         devman_handle_t hc_handle = 0;
    231         usb_address_t dev_addr = 0;
    232         bool found = resolve_hc_handle_and_dev_addr(devpath,
    233             &hc_handle, &dev_addr);
    234         if (!found) {
    235                 fprintf(stderr, NAME ": device `%s' not found "
    236                     "or not of USB kind. Exiting.\n", devpath);
    237                 return -1;
    238         }
     215        //const char *devpath = "/hw/pci0/00:06.0/ohci-rh/usb00_a2/HID1/hid";
    239216       
    240217        int rc;
    241         usb_hc_connection_t conn;
    242 
    243         usb_hc_connection_initialize(&conn, hc_handle);
    244         rc = usb_hc_connection_open(&conn);
    245         if (rc != EOK) {
    246                 printf(NAME ": failed to connect to HC: %s.\n",
     218       
     219        devman_handle_t dev_handle = 0;
     220        rc = devman_device_get_handle(devpath, &dev_handle, 0);
     221        if (rc != EOK) {
     222                printf("Failed to get handle from devman: %s.\n",
    247223                    str_error(rc));
    248                 return -1;
    249         }
    250         usb_address_t addr = 0;
    251 
    252         devman_handle_t dev_handle;
    253         rc = usb_hc_get_handle_by_address(&conn, addr, &dev_handle);
    254         if (rc != EOK) {
    255                 printf(NAME ": failed getting handle to the device: %s.\n",
    256                        str_error(rc));
    257                 return -1;
    258         }
    259 
    260         usb_hc_connection_close(&conn);
     224                return rc;
     225        }
    261226       
    262227        rc = devman_device_connect(dev_handle, 0);
    263228        if (rc < 0) {
    264                 printf(NAME ": failed to connect to the device: %s.\n",
    265                        str_error(rc));
    266                 return -1;
     229                printf(NAME ": failed to connect to the device (handle %"
     230                       PRIun "): %s.\n", dev_handle, str_error(rc));
     231                return rc;
    267232        }
    268233       
    269234        dev_phone = rc;
    270         printf("Got phone to the device: %d\n", dev_phone);
    271        
    272        
    273 //      size_t class_index = 0;
    274 //      size_t failed_attempts = 0;
    275 
    276 //      while (failed_attempts < MAX_FAILED_ATTEMPTS) {
    277 //              class_index++;
    278 //              devman_handle_t hc_handle = 0;
    279 //              int rc = usb_ddf_get_hc_handle_by_class(class_index, &hc_handle);
    280 //              if (rc != EOK) {
    281 //                      failed_attempts++;
    282 //                      continue;
    283 //              }
    284 //              char path[MAX_PATH_LENGTH];
    285 //              rc = devman_get_device_path(hc_handle, path, MAX_PATH_LENGTH);
    286 //              if (rc != EOK) {
    287 //                      continue;
    288 //              }
    289 //              print_found_hc(class_index, path);
    290 //              print_hc_devices(hc_handle);
    291 //      }
     235//      printf("Got phone to the device: %d\n", dev_phone);
     236       
     237        char path[MAX_PATH_LENGTH];
     238        rc = devman_get_device_path(dev_handle, path, MAX_PATH_LENGTH);
     239        if (rc != EOK) {
     240                return ENOMEM;
     241        }
     242       
     243        printf("Device path: %s\n", path);
     244       
     245       
     246        usb_hid_report_t *report = NULL;
     247        rc = initialize_report_parser(dev_phone, &report);
     248        if (rc != EOK) {
     249                printf("Failed to initialize report parser: %s\n",
     250                    str_error(rc));
     251                return rc;
     252        }
     253       
     254        assert(report != NULL);
     255       
     256        size_t size;
     257        rc = usbhid_dev_get_event_length(dev_phone, &size);
     258        if (rc != EOK) {
     259                printf("Failed to get event length: %s.\n", str_error(rc));
     260                return rc;
     261        }
     262       
     263//      printf("Event length: %zu\n", size);
     264        uint8_t *event = (uint8_t *)malloc(size);
     265        if (event == NULL) {
     266                // hangup phone?
     267                return ENOMEM;
     268        }
     269       
     270//      printf("Event length: %zu\n", size);
     271       
     272        size_t actual_size;
     273        int event_nr;
     274       
     275        while (1) {
     276                // get event from the driver
     277//              printf("Getting event from the driver.\n");
     278               
     279                /** @todo Try blocking call. */
     280                rc = usbhid_dev_get_event(dev_phone, event, size, &actual_size,
     281                    &event_nr, 0);
     282                if (rc != EOK) {
     283                        // hangup phone?
     284                        printf("Error in getting event from the HID driver:"
     285                            "%s.\n", str_error(rc));
     286                        break;
     287                }
     288               
     289//              printf("Got buffer: %p, size: %zu, max size: %zu\n", event,
     290//                  actual_size, size);
     291               
     292//              printf("Event number: %d, my actual event: %d\n", event_nr,
     293//                  act_event);
     294                if (event_nr > act_event) {
     295                        print_key(event, size, report);
     296                        act_event = event_nr;
     297                }
     298               
     299                async_usleep(10000);
     300        }
    292301       
    293302        return 0;
  • uspace/drv/ohci/hc.c

    re8f826b r400735e  
    343343{
    344344        assert(instance);
    345         usb_log_debug("OHCI(%p) interrupt: %x.\n", instance, status);
    346345        if ((status & ~I_SF) == 0) /* ignore sof status */
    347346                return;
     347        usb_log_debug2("OHCI(%p) interrupt: %x.\n", instance, status);
    348348        if (status & I_RHSC)
    349349                rh_interrupt(&instance->rh);
     
    565565        bzero(&instance->rh, sizeof(instance->rh));
    566566        /* Init queues */
    567         hc_init_transfer_lists(instance);
     567        const int ret = hc_init_transfer_lists(instance);
     568        if (ret != EOK) {
     569                return ret;
     570        }
    568571
    569572        /*Init HCCA */
  • uspace/drv/ohci/root_hub.c

    re8f826b r400735e  
    6161        .vendor_id = 0x16db,
    6262        .product_id = 0x0001,
    63         /// \TODO these values migt be different
    6463        .str_serial_number = 0,
    6564        .usb_spec_version = 0x110,
     
    119118static const uint32_t hub_clear_feature_by_writing_one_mask =
    120119   RHS_CLEAR_PORT_POWER;
    121    // 1 << USB_HUB_FEATURE_C_HUB_LOCAL_POWER;
    122120
    123121/**
     
    127125    RHS_LPSC_FLAG |
    128126    RHS_OCIC_FLAG;
    129     //(1 << USB_HUB_FEATURE_C_HUB_OVER_CURRENT) |
    130     //(1 << USB_HUB_FEATURE_C_HUB_LOCAL_POWER);
    131127
    132128/**
     
    135131static const uint32_t hub_set_feature_direct_mask =
    136132    RHS_SET_PORT_POWER;
    137     //(1 << USB_HUB_FEATURE_C_HUB_OVER_CURRENT);
    138133
    139134/**
     
    160155    RHPS_PRSC_FLAG;
    161156
    162 /*
    163 
    164     (1 << USB_HUB_FEATURE_PORT_CONNECTION) |
    165     (1 << USB_HUB_FEATURE_PORT_SUSPEND) |
    166     (1 << USB_HUB_FEATURE_PORT_OVER_CURRENT) |
    167     (1 << USB_HUB_FEATURE_PORT_POWER) |
    168     (1 << USB_HUB_FEATURE_C_PORT_CONNECTION) |
    169     (1 << USB_HUB_FEATURE_C_PORT_ENABLE) |
    170     (1 << USB_HUB_FEATURE_C_PORT_SUSPEND) |
    171     (1 << USB_HUB_FEATURE_C_PORT_OVER_CURRENT) |
    172     (1 << USB_HUB_FEATURE_C_PORT_RESET);
    173  */
    174157//note that USB_HUB_FEATURE_PORT_POWER bit is translated into
    175158//USB_HUB_FEATURE_PORT_LOW_SPEED for port set feature request
     
    179162 */
    180163static const uint32_t port_status_change_mask = RHPS_CHANGE_WC_MASK;
    181 /*    (1 << USB_HUB_FEATURE_C_PORT_CONNECTION) |
    182     (1 << USB_HUB_FEATURE_C_PORT_ENABLE) |
    183     (1 << USB_HUB_FEATURE_C_PORT_OVER_CURRENT) |
    184     (1 << USB_HUB_FEATURE_C_PORT_RESET) |
    185     (1 << USB_HUB_FEATURE_C_PORT_SUSPEND);
    186 */
    187164
    188165static int create_serialized_hub_descriptor(rh_t *instance);
     
    420397 * create answer to port status_request
    421398 *
    422  * Copy content of corresponding port status register to answer buffer.
     399 * Copy content of corresponding port status register to answer buffer. The
     400 * format of the port status register and port status data is the same (
     401 * see OHCI root hub and USB hub documentation).
    423402 *
    424403 * @param instance root hub instance
     
    431410        if (port < 1 || port > instance->port_count)
    432411                return EINVAL;
    433         uint32_t * uint32_buffer = (uint32_t*) request->data_buffer;
    434412        request->transfered_size = 4;
    435         uint32_buffer[0] = instance->registers->rh_port_status[port - 1];
     413        uint32_t data = instance->registers->rh_port_status[port - 1];
     414        memcpy(request->data_buffer,&data,4);
    436415#if 0
    437416        int i;
     
    450429 * create answer to port status_request
    451430 *
    452  * Copy content of hub status register to answer buffer.
     431 * This copies flags in hub status register into the buffer. The format of the
     432 * status register and status message is the same, according to USB hub
     433 * specification and OHCI root hub specification.
    453434 *
    454435 * @param instance root hub instance
     
    458439static int process_get_hub_status_request(rh_t *instance,
    459440    usb_transfer_batch_t * request) {
    460         uint32_t * uint32_buffer = (uint32_t*) request->data_buffer;
     441        //uint32_t * uint32_buffer = (uint32_t*) request->data_buffer;
    461442        request->transfered_size = 4;
    462443        //bits, 0,1,16,17
    463444        uint32_t mask = 1 | (1 << 1) | (1 << 16) | (1 << 17);
    464         uint32_buffer[0] = mask & instance->registers->rh_status;
     445        uint32_t data = mask & instance->registers->rh_status;
     446        //uint32_buffer[0] = mask & instance->registers->rh_status;
     447        memcpy(request->data_buffer,&data,4);
    465448
    466449        return EOK;
     
    516499            | (1 << (USB_HUB_FEATURE_C_HUB_OVER_CURRENT + 16));
    517500        bzero(bitmap, instance->interrupt_mask_size);
    518         if (instance->registers->rh_status & mask) {
     501        if ((instance->registers->rh_status & mask) !=0 ) {
    519502                bitmap[0] = 1;
    520503        }
     
    522505        mask = port_status_change_mask;
    523506        for (port = 1; port <= instance->port_count; ++port) {
    524                 if (mask & instance->registers->rh_port_status[port - 1]) {
     507                if ((mask & instance->registers->rh_port_status[port - 1]) != 0) {
    525508
    526509                        bitmap[(port) / 8] += 1 << (port % 8);
  • uspace/drv/uhci-hcd/Makefile

    re8f826b r400735e  
    4848        root_hub.c \
    4949        hw_struct/transfer_descriptor.c \
    50         utils/slab.c \
    5150        pci.c \
    5251        batch.c
  • uspace/drv/uhci-hcd/batch.h

    re8f826b r400735e  
    3535#define DRV_UHCI_BATCH_H
    3636
    37 #include <usbhc_iface.h>
    38 #include <usb/usb.h>
    39 #include <usb/host/device_keeper.h>
    40 #include <usb/host/endpoint.h>
    4137#include <usb/host/batch.h>
    4238
  • uspace/drv/uhci-hcd/hc.c

    re8f826b r400735e  
    3939#include <usb/debug.h>
    4040#include <usb/usb.h>
    41 #include <usb/ddfiface.h>
    42 #include <usb_iface.h>
    4341
    4442#include "hc.h"
     
    8583        /* allow access to hc control registers */
    8684        regs_t *io;
    87         ret = pio_enable(regs, reg_size, (void**)&io);
     85        ret = pio_enable(regs, reg_size, (void **)&io);
    8886        CHECK_RET_RETURN(ret,
    8987            "Failed(%d) to gain access to registers at %p: %s.\n",
     
    143141        }
    144142
    145         uint16_t status = pio_read_16(&registers->usbcmd);
     143        const uint16_t status = pio_read_16(&registers->usbcmd);
    146144        if (status != 0)
    147145                usb_log_warning("Previous command value: %x.\n", status);
     
    212210        /* Init USB frame list page*/
    213211        instance->frame_list = get_page();
    214         ret = instance ? EOK : ENOMEM;
     212        ret = instance->frame_list ? EOK : ENOMEM;
    215213        CHECK_RET_RETURN(ret, "Failed to get frame list page.\n");
    216214        usb_log_debug("Initialized frame list at %p.\n", instance->frame_list);
     
    277275                &instance->transfers_control_slow);
    278276
    279         /*FSBR*/
     277        /*FSBR, This feature is not needed (adds no benefit) and is supposedly
     278         * buggy on certain hw, enable at your own risk. */
    280279#ifdef FSBR
    281280        transfer_list_set_next(&instance->transfers_bulk_full,
     
    428427                }
    429428
    430                 uintptr_t frame_list =
     429                const uintptr_t frame_list =
    431430                    pio_read_32(&instance->registers->flbaseadd) & ~0xfff;
    432431                if (frame_list != addr_to_phys(instance->frame_list)) {
  • uspace/drv/uhci-hcd/hc.h

    re8f826b r400735e  
    3737
    3838#include <fibril.h>
    39 #include <fibril_synch.h>
    40 #include <adt/list.h>
    4139#include <ddi.h>
    4240
    43 #include <usbhc_iface.h>
    4441#include <usb/host/device_keeper.h>
    4542#include <usb/host/usb_endpoint_manager.h>
     43#include <usb/host/batch.h>
    4644
    47 #include "batch.h"
    4845#include "transfer_list.h"
    4946
     
    154151 */
    155152static inline hc_t * fun_to_hc(ddf_fun_t *fun)
    156         { return (hc_t*)fun->driver_data; }
     153{
     154        assert(fun);
     155        return fun->driver_data;
     156}
    157157#endif
    158158/**
  • uspace/drv/uhci-hcd/iface.c

    re8f826b r400735e  
    3939
    4040#include "iface.h"
     41#include "batch.h"
    4142#include "hc.h"
    4243
     
    122123        return EOK;
    123124}
    124 
     125/*----------------------------------------------------------------------------*/
    125126/** Find device handle by address interface function.
    126127 *
     
    136137        hc_t *hc = fun_to_hc(fun);
    137138        assert(hc);
    138         bool found =
     139        const bool found =
    139140            usb_device_keeper_find_by_address(&hc->manager, address, handle);
    140141        return found ? EOK : ENOENT;
    141142}
    142 
    143143/*----------------------------------------------------------------------------*/
    144144/** Release address interface function
     
    164164    size_t max_packet_size, unsigned int interval)
    165165{
     166        assert(fun);
    166167        hc_t *hc = fun_to_hc(fun);
    167168        assert(hc);
     
    183184    usb_endpoint_t endpoint, usb_direction_t direction)
    184185{
     186        assert(fun);
    185187        hc_t *hc = fun_to_hc(fun);
    186188        assert(hc);
     
    211213        if (ret != EOK)
    212214                return ret;
     215        assert(batch);
     216        assert(hc);
    213217        batch_interrupt_out(batch);
    214218        ret = hc_schedule(hc, batch);
     
    239243        if (ret != EOK)
    240244                return ret;
     245        assert(batch);
     246        assert(hc);
    241247        batch_interrupt_in(batch);
    242248        ret = hc_schedule(hc, batch);
     
    267273        if (ret != EOK)
    268274                return ret;
     275        assert(batch);
     276        assert(hc);
    269277        batch_bulk_out(batch);
    270278        ret = hc_schedule(hc, batch);
     
    295303        if (ret != EOK)
    296304                return ret;
     305        assert(batch);
     306        assert(hc);
    297307        batch_bulk_in(batch);
    298308        ret = hc_schedule(hc, batch);
     
    327337        if (ret != EOK)
    328338                return ret;
     339        assert(batch);
     340        assert(hc);
    329341        usb_endpoint_manager_reset_if_need(&hc->ep_manager, target, setup_data);
    330342        batch_control_write(batch);
     
    360372        if (ret != EOK)
    361373                return ret;
     374        assert(batch);
     375        assert(hc);
    362376        batch_control_read(batch);
    363377        ret = hc_schedule(hc, batch);
  • uspace/drv/uhci-hcd/pci.c

    re8f826b r400735e  
    5252 * @return Error code.
    5353 */
    54 int pci_get_my_registers(ddf_dev_t *dev,
     54int pci_get_my_registers(const ddf_dev_t *dev,
    5555    uintptr_t *io_reg_address, size_t *io_reg_size, int *irq_no)
    5656{
    57         assert(dev != NULL);
     57        assert(dev);
     58        assert(io_reg_address);
     59        assert(io_reg_size);
     60        assert(irq_no);
    5861
    5962        int parent_phone =
     
    6669        int rc = hw_res_get_resource_list(parent_phone, &hw_resources);
    6770        if (rc != EOK) {
    68                 goto leave;
     71                async_hangup(parent_phone);
     72                return rc;
    6973        }
    7074
     
    7882        size_t i;
    7983        for (i = 0; i < hw_resources.count; i++) {
    80                 hw_resource_t *res = &hw_resources.resources[i];
     84                const hw_resource_t *res = &hw_resources.resources[i];
    8185                switch (res->type)
    8286                {
     
    99103                }
    100104        }
     105        async_hangup(parent_phone);
    101106
    102         if (!io_found || !irq_found) {
    103                 rc = ENOENT;
    104                 goto leave;
    105         }
     107        if (!io_found || !irq_found)
     108                return ENOENT;
    106109
    107110        *io_reg_address = io_address;
     
    109112        *irq_no = irq;
    110113
    111         rc = EOK;
    112 leave:
    113         async_hangup(parent_phone);
    114         return rc;
     114        return EOK;
    115115}
    116116/*----------------------------------------------------------------------------*/
     
    120120 * @return Error code.
    121121 */
    122 int pci_enable_interrupts(ddf_dev_t *device)
     122int pci_enable_interrupts(const ddf_dev_t *device)
    123123{
    124         int parent_phone = devman_parent_device_connect(device->handle,
    125             IPC_FLAG_BLOCKING);
    126         bool enabled = hw_res_enable_interrupt(parent_phone);
     124        const int parent_phone =
     125            devman_parent_device_connect(device->handle, IPC_FLAG_BLOCKING);
     126        if (parent_phone < 0) {
     127                return parent_phone;
     128        }
     129        const bool enabled = hw_res_enable_interrupt(parent_phone);
    127130        async_hangup(parent_phone);
    128131        return enabled ? EOK : EIO;
     
    134137 * @return Error code.
    135138 */
    136 int pci_disable_legacy(ddf_dev_t *device)
     139int pci_disable_legacy(const ddf_dev_t *device)
    137140{
    138141        assert(device);
    139         int parent_phone =
     142        const int parent_phone =
    140143            devman_parent_device_connect(device->handle, IPC_FLAG_BLOCKING);
    141144        if (parent_phone < 0) {
     
    145148        /* See UHCI design guide for these values p.45,
    146149         * write all WC bits in USB legacy register */
    147         sysarg_t address = 0xc0;
    148         sysarg_t value = 0xaf00;
     150        const sysarg_t address = 0xc0;
     151        const sysarg_t value = 0xaf00;
    149152
    150         int rc = async_req_3_0(parent_phone, DEV_IFACE_ID(PCI_DEV_IFACE),
     153        const int rc = async_req_3_0(parent_phone, DEV_IFACE_ID(PCI_DEV_IFACE),
    151154            IPC_M_CONFIG_SPACE_WRITE_16, address, value);
    152155        async_hangup(parent_phone);
  • uspace/drv/uhci-hcd/pci.h

    re8f826b r400735e  
    3838#include <ddf/driver.h>
    3939
    40 int pci_get_my_registers(ddf_dev_t *, uintptr_t *, size_t *, int *);
    41 int pci_enable_interrupts(ddf_dev_t *);
    42 int pci_disable_legacy(ddf_dev_t *);
     40int pci_get_my_registers(const ddf_dev_t *, uintptr_t *, size_t *, int *);
     41int pci_enable_interrupts(const ddf_dev_t *);
     42int pci_disable_legacy(const ddf_dev_t *);
    4343
    4444#endif
  • uspace/drv/uhci-hcd/root_hub.c

    re8f826b r400735e  
    6060                return ret;
    6161        }
     62        assert(match_str);
    6263
    6364        ret = ddf_fun_add_match_id(fun, match_str, 100);
  • uspace/drv/uhci-hcd/root_hub.h

    re8f826b r400735e  
    4343        /** List of resources available to the root hub. */
    4444        hw_resource_list_t resource_list;
    45         /** The only resource in the above list */
     45        /** The only resource in the RH resource list */
    4646        hw_resource_t io_regs;
    4747} rh_t;
  • uspace/drv/uhci-hcd/transfer_list.c

    re8f826b r400735e  
    3636#include <arch/barrier.h>
    3737
     38
    3839#include "transfer_list.h"
     40#include "batch.h"
    3941
    4042static void transfer_list_remove_batch(
     
    5860                return ENOMEM;
    5961        }
    60         uint32_t queue_head_pa = addr_to_phys(instance->queue_head);
     62        const uint32_t queue_head_pa = addr_to_phys(instance->queue_head);
    6163        usb_log_debug2("Transfer list %s setup with QH: %p (%#" PRIx32" ).\n",
    6264            name, instance->queue_head, queue_head_pa);
     
    9092{
    9193        assert(instance);
     94        assert(instance->queue_head);
    9295        assert(next);
    93         if (!instance->queue_head)
    94                 return;
    9596        /* Set queue_head.next to point to the follower */
    9697        qh_set_next_qh(instance->queue_head, next->queue_head);
     
    137138        write_barrier();
    138139
    139         /* Add to the driver list */
     140        /* Add to the driver's list */
    140141        list_append(&batch->link, &instance->batch_list);
    141142
     
    160161        link_t *current = instance->batch_list.next;
    161162        while (current != &instance->batch_list) {
    162                 link_t *next = current->next;
     163                link_t * const next = current->next;
    163164                usb_transfer_batch_t *batch =
    164165                    usb_transfer_batch_from_link(current);
     
    182183        fibril_mutex_lock(&instance->guard);
    183184        while (!list_empty(&instance->batch_list)) {
    184                 link_t *current = instance->batch_list.next;
     185                link_t * const current = instance->batch_list.next;
    185186                usb_transfer_batch_t *batch =
    186187                    usb_transfer_batch_from_link(current);
  • uspace/drv/uhci-hcd/transfer_list.h

    re8f826b r400735e  
    3636
    3737#include <fibril_synch.h>
     38#include <usb/host/batch.h>
    3839
    39 #include "batch.h"
    4040#include "hw_struct/queue_head.h"
    4141
  • uspace/drv/uhci-hcd/uhci.c

    re8f826b r400735e  
    6161} uhci_t;
    6262
    63 static inline uhci_t * dev_to_uhci(ddf_dev_t *dev)
     63static inline uhci_t * dev_to_uhci(const ddf_dev_t *dev)
    6464{
    6565        assert(dev);
     
    7777{
    7878        assert(dev);
    79         hc_t *hc = &((uhci_t*)dev->driver_data)->hc;
    80         uint16_t status = IPC_GET_ARG1(*call);
     79        uhci_t *uhci = dev_to_uhci(dev);
     80        hc_t *hc = &uhci->hc;
     81        const uint16_t status = IPC_GET_ARG1(*call);
    8182        assert(hc);
    8283        hc_interrupt(hc, status);
    8384}
     85/*----------------------------------------------------------------------------*/
     86/** Operations supported by the HC driver */
     87static ddf_dev_ops_t hc_ops = {
     88        .interfaces[USBHC_DEV_IFACE] = &hc_iface, /* see iface.h/c */
     89};
    8490/*----------------------------------------------------------------------------*/
    8591/** Get address of the device identified by handle.
     
    113119 * @return Error code.
    114120 */
    115 static int usb_iface_get_hc_handle(
    116     ddf_fun_t *fun, devman_handle_t *handle)
     121static int usb_iface_get_hc_handle(ddf_fun_t *fun, devman_handle_t *handle)
    117122{
    118123        assert(fun);
     
    131136};
    132137/*----------------------------------------------------------------------------*/
    133 /** Operations supported by the HC driver */
    134 static ddf_dev_ops_t hc_ops = {
    135         .interfaces[USBHC_DEV_IFACE] = &hc_iface, /* see iface.h/c */
    136 };
    137 /*----------------------------------------------------------------------------*/
    138138/** Get root hub hw resources (I/O registers).
    139139 *
     
    144144{
    145145        assert(fun);
    146         return &((rh_t*)fun->driver_data)->resource_list;
     146        rh_t *rh = fun->driver_data;
     147        assert(rh);
     148        return &rh->resource_list;
    147149}
    148150/*----------------------------------------------------------------------------*/
  • uspace/drv/uhci-hcd/uhci.h

    re8f826b r400735e  
    3535#ifndef DRV_UHCI_UHCI_H
    3636#define DRV_UHCI_UHCI_H
    37 #include <ddi.h>
    3837#include <ddf/driver.h>
    3938
  • uspace/drv/uhci-hcd/utils/malloc32.h

    re8f826b r400735e  
    4141#include <as.h>
    4242
    43 #include "slab.h"
    44 
    4543#define UHCI_STRCUTURES_ALIGNMENT 16
    4644#define UHCI_REQUIRED_PAGE_SIZE 4096
     
    5957        uintptr_t result;
    6058        const int ret = as_get_physical_mapping(addr, &result);
    61         assert(ret == EOK);
    62 
    6359        if (ret != EOK)
    6460                return 0;
     
    7268 */
    7369static inline void * malloc32(size_t size) {
    74         if (size <= SLAB_ELEMENT_SIZE)
    75                 return slab_malloc_g();
    76         usb_log_warning("Requested %zu bytes, current allocator can't handle "
    77             "that amount, pray that the standard malloc will suffice.", size);
    78         return memalign(UHCI_STRCUTURES_ALIGNMENT, size);
     70        /* This works only when the host has less than 4GB of memory as
     71         * physical address needs to fit into 32 bits */
     72
     73        /* If we need more than one page there is no guarantee that the
     74         * memory will be continuous */
     75        if (size > PAGE_SIZE)
     76                return NULL;
     77        /* Calculate alignment to make sure the block won't cross page
     78         * boundary */
     79        size_t alignment = UHCI_STRCUTURES_ALIGNMENT;
     80        while (alignment < size)
     81                alignment *= 2;
     82        return memalign(alignment, size);
    7983}
    8084/*----------------------------------------------------------------------------*/
     
    8690        if (!addr)
    8791                return;
    88         if (slab_in_range_g(addr))
    89                 return slab_free_g(addr);
    9092        free(addr);
    9193}
     
    98100{
    99101        void *free_address = as_get_mappable_page(UHCI_REQUIRED_PAGE_SIZE);
    100         assert(free_address); /* TODO: remove this assert */
    101102        if (free_address == 0)
    102103                return NULL;
  • uspace/drv/uhci-rhd/main.c

    re8f826b r400735e  
    3737#include <errno.h>
    3838#include <str_error.h>
     39
    3940#include <usb_iface.h>
    4041#include <usb/ddfiface.h>
     
    4546#define NAME "uhci-rhd"
    4647
    47 static int hc_get_my_registers(ddf_dev_t *dev,
     48static int hc_get_my_registers(const ddf_dev_t *dev,
    4849    uintptr_t *io_reg_address, size_t *io_reg_size);
    4950/*----------------------------------------------------------------------------*/
     
    130131 */
    131132int hc_get_my_registers(
    132     ddf_dev_t *dev, uintptr_t *io_reg_address, size_t *io_reg_size)
     133    const ddf_dev_t *dev, uintptr_t *io_reg_address, size_t *io_reg_size)
    133134{
    134         assert(dev != NULL);
     135        assert(dev);
    135136
    136         int parent_phone = devman_parent_device_connect(dev->handle,
     137        const int parent_phone = devman_parent_device_connect(dev->handle,
    137138            IPC_FLAG_BLOCKING);
    138139        if (parent_phone < 0) {
     
    141142
    142143        hw_resource_list_t hw_resources;
    143         int ret = hw_res_get_resource_list(parent_phone, &hw_resources);
     144        const int ret = hw_res_get_resource_list(parent_phone, &hw_resources);
    144145        if (ret != EOK) {
    145146                async_hangup(parent_phone);
  • uspace/drv/uhci-rhd/port.c

    re8f826b r400735e  
    3636#include <errno.h>
    3737#include <str_error.h>
    38 #include <time.h>
    3938#include <async.h>
    4039
     
    8281 * @param[in] number Port number.
    8382 * @param[in] usec Polling interval.
    84  * @param[in] rh Pointer to ddf instance fo the root hub driver.
     83 * @param[in] rh Pointer to ddf instance of the root hub driver.
    8584 * @return Error code.
    8685 *
     
    9190{
    9291        assert(port);
    93         asprintf(&port->id_string, "Port (%p - %u)", port, number);
    94         if (port->id_string == NULL) {
     92        char *id_string;
     93        asprintf(&id_string, "Port (%p - %u)", port, number);
     94        if (id_string == NULL) {
    9595                return ENOMEM;
    9696        }
    9797
     98        port->id_string = id_string;
    9899        port->address = address;
    99100        port->number = number;
     
    105106            usb_hc_connection_initialize_from_device(&port->hc_connection, rh);
    106107        if (ret != EOK) {
    107                 usb_log_error("Failed to initialize connection to HC.");
     108                usb_log_error("%s: failed to initialize connection to HC.",
     109                    port->id_string);
     110                free(id_string);
    108111                return ret;
    109112        }
     
    113116                usb_log_error("%s: failed to create polling fibril.",
    114117                    port->id_string);
     118                free(id_string);
    115119                return ENOMEM;
    116120        }
     
    132136        assert(port);
    133137        free(port->id_string);
    134         /* TODO: Kill fibril here */
     138        // TODO: Kill fibril here
    135139        return;
    136140}
     
    150154
    151155                /* Read register value */
    152                 port_status_t port_status = uhci_port_read_status(instance);
     156                const port_status_t port_status =
     157                    uhci_port_read_status(instance);
    153158
    154159                /* Print the value if it's interesting */
     
    161166                usb_log_debug("%s: Connected change detected: %x.\n",
    162167                    instance->id_string, port_status);
    163 
    164                 int rc =
    165                     usb_hc_connection_open(&instance->hc_connection);
    166                 if (rc != EOK) {
    167                         usb_log_error("%s: Failed to connect to HC.",
    168                             instance->id_string);
    169                         continue;
    170                 }
    171168
    172169                /* Remove any old device */
     
    175172                            instance->id_string);
    176173                        uhci_port_remove_device(instance);
     174                }
     175
     176                int ret =
     177                    usb_hc_connection_open(&instance->hc_connection);
     178                if (ret != EOK) {
     179                        usb_log_error("%s: Failed to connect to HC.",
     180                            instance->id_string);
     181                        continue;
    177182                }
    178183
     
    190195                }
    191196
    192                 rc = usb_hc_connection_close(&instance->hc_connection);
    193                 if (rc != EOK) {
     197                ret = usb_hc_connection_close(&instance->hc_connection);
     198                if (ret != EOK) {
    194199                        usb_log_error("%s: Failed to disconnect.",
    195200                            instance->id_string);
     
    209214int uhci_port_reset_enable(int portno, void *arg)
    210215{
    211         uhci_port_t *port = (uhci_port_t *) arg;
     216        uhci_port_t *port = arg;
     217        assert(port);
    212218
    213219        usb_log_debug2("%s: new_device_enable_port.\n", port->id_string);
     
    283289        usb_log_error("%s: Don't know how to remove device %" PRIun ".\n",
    284290            port->id_string, port->attached_device);
     291        port->attached_device = 0;
    285292        return ENOTSUP;
    286293}
  • uspace/drv/uhci-rhd/port.h

    re8f826b r400735e  
    5757typedef struct uhci_port
    5858{
    59         char *id_string;
     59        const char *id_string;
    6060        port_status_t *address;
    6161        unsigned number;
  • uspace/drv/usbhid/generic/hiddev.c

    re8f826b r400735e  
    6262static size_t usb_generic_hid_get_event_length(ddf_fun_t *fun);
    6363
    64 static int usb_generic_hid_get_event(ddf_fun_t *fun, int32_t *buffer,
    65     size_t size, size_t *act_size, unsigned int flags);
     64static int usb_generic_hid_get_event(ddf_fun_t *fun, uint8_t *buffer,
     65    size_t size, size_t *act_size, int *event_nr, unsigned int flags);
    6666
    6767static int usb_generic_hid_client_connected(ddf_fun_t *fun);
     68
     69static size_t usb_generic_get_report_descriptor_length(ddf_fun_t *fun);
     70
     71static int usb_generic_get_report_descriptor(ddf_fun_t *fun, uint8_t *desc,
     72    size_t size, size_t *actual_size);
    6873
    6974/*----------------------------------------------------------------------------*/
     
    7176static usbhid_iface_t usb_generic_iface = {
    7277        .get_event = usb_generic_hid_get_event,
    73         .get_event_length = usb_generic_hid_get_event_length
     78        .get_event_length = usb_generic_hid_get_event_length,
     79        .get_report_descriptor_length = usb_generic_get_report_descriptor_length,
     80        .get_report_descriptor = usb_generic_get_report_descriptor
    7481};
    7582
     
    8390static size_t usb_generic_hid_get_event_length(ddf_fun_t *fun)
    8491{
    85         if (fun == NULL || fun->driver_data) {
     92        usb_log_debug2("Generic HID: Get event length (fun: %p, "
     93            "fun->driver_data: %p.\n", fun, fun->driver_data);
     94       
     95        if (fun == NULL || fun->driver_data == NULL) {
    8696                return 0;
    8797        }
     
    8999        usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data;
    90100       
    91         return hid_dev->input_report_size;
    92 }
    93 
    94 /*----------------------------------------------------------------------------*/
    95 
    96 static int usb_generic_hid_get_event(ddf_fun_t *fun, int32_t *buffer,
    97     size_t size, size_t *act_size, unsigned int flags)
    98 {
    99         if (fun == NULL || fun->driver_data) {
     101        usb_log_debug2("hid_dev: %p, Max input report size (%zu).\n",
     102            hid_dev, hid_dev->max_input_report_size);
     103       
     104        return hid_dev->max_input_report_size;
     105}
     106
     107/*----------------------------------------------------------------------------*/
     108
     109static int usb_generic_hid_get_event(ddf_fun_t *fun, uint8_t *buffer,
     110    size_t size, size_t *act_size, int *event_nr, unsigned int flags)
     111{
     112        usb_log_debug2("Generic HID: Get event.\n");
     113       
     114        if (fun == NULL || fun->driver_data == NULL || buffer == NULL
     115            || act_size == NULL || event_nr == NULL) {
     116                usb_log_debug("No function");
    100117                return EINVAL;
    101118        }
     
    104121       
    105122        if (hid_dev->input_report_size > size) {
     123                usb_log_debug("input_report_size > size (%zu, %zu)\n",
     124                    hid_dev->input_report_size, size);
    106125                return EINVAL;  // TODO: other error code
    107126        }
    108127       
    109128        /*! @todo This should probably be atomic. */
    110         if (usb_hid_report_ready()) {
    111                 memcpy(buffer, hid_dev->input_report,
    112                     hid_dev->input_report_size);
    113                 *act_size = hid_dev->input_report_size;
    114                 usb_hid_report_received();
    115         }
     129//      if (usb_hid_report_ready()) {
     130//              usb_log_debug2("Report ready, size: %zu\n",
     131//                  hid_dev->input_report_size);
     132               
     133//              usb_hid_report_received();
     134//      } else {
     135//              memset(buffer, 0, hid_dev->input_report_size);
     136//      }
     137        memcpy(buffer, hid_dev->input_report,
     138            hid_dev->input_report_size);
     139        *act_size = hid_dev->input_report_size;
     140        *event_nr = usb_hid_report_number(hid_dev);
    116141       
    117142        // clear the buffer so that it will not be received twice
     
    120145        // note that we already received this report
    121146//      report_received = true;
     147        usb_log_debug2("OK\n");
     148       
     149        return EOK;
     150}
     151
     152/*----------------------------------------------------------------------------*/
     153
     154static size_t usb_generic_get_report_descriptor_length(ddf_fun_t *fun)
     155{
     156        usb_log_debug("Generic HID: Get report descriptor length.\n");
     157       
     158        if (fun == NULL || fun->driver_data == NULL) {
     159                usb_log_debug("No function");
     160                return EINVAL;
     161        }
     162       
     163        usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data;
     164       
     165        usb_log_debug2("hid_dev->report_desc_size = %zu\n",
     166            hid_dev->report_desc_size);
     167       
     168        return hid_dev->report_desc_size;
     169}
     170
     171/*----------------------------------------------------------------------------*/
     172
     173static int usb_generic_get_report_descriptor(ddf_fun_t *fun, uint8_t *desc,
     174    size_t size, size_t *actual_size)
     175{
     176        usb_log_debug2("Generic HID: Get report descriptor.\n");
     177       
     178        if (fun == NULL || fun->driver_data == NULL) {
     179                usb_log_debug("No function");
     180                return EINVAL;
     181        }
     182       
     183        usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data;
     184       
     185        if (hid_dev->report_desc_size > size) {
     186                return EINVAL;  // TODO: other error code
     187        }
     188       
     189        memcpy(desc, hid_dev->report_desc, hid_dev->report_desc_size);
     190        *actual_size = hid_dev->report_desc_size;
    122191       
    123192        return EOK;
     
    128197static int usb_generic_hid_client_connected(ddf_fun_t *fun)
    129198{
    130         usb_hid_report_received();
     199        usb_log_debug("Generic HID: Client connected.\n");
    131200        return EOK;
    132201}
     
    145214                return ENOMEM;
    146215        }
     216       
     217        fun->ops = &usb_generic_hid_ops;
     218        fun->driver_data = hid_dev;
    147219
    148220        int rc = ddf_fun_bind(fun);
     
    154226        }
    155227       
    156         fun->ops = &usb_generic_hid_ops;
    157         fun->driver_data = hid_dev;
     228        usb_log_debug("HID function created. Handle: %" PRIun "\n", fun->handle);
    158229       
    159230        return EOK;
     
    176247    uint8_t *buffer, size_t buffer_size)
    177248{
    178         usb_log_debug("usb_hid_polling_callback(%p, %p, %zu)\n",
     249        usb_log_debug2("usb_hid_polling_callback(%p, %p, %zu)\n",
    179250            hid_dev, buffer, buffer_size);
    180251        usb_debug_str_buffer(buffer, buffer_size, 0);
  • uspace/drv/usbhid/kbd/kbddev.c

    re8f826b r400735e  
    798798        }
    799799       
     800        usb_log_debug("%s function created. Handle: %" PRIun "\n",
     801            HID_KBD_FUN_NAME, fun->handle);
     802       
    800803        usb_log_debug("Adding DDF function to class %s...\n",
    801804            HID_KBD_CLASS_NAME);
  • uspace/drv/usbhid/mouse/mousedev.c

    re8f826b r400735e  
    234234       
    235235        if (mouse_dev->mouse_phone < 0) {
    236                 usb_log_error(NAME " No console phone.\n");
    237                 return false;   // ??
     236                usb_log_warning(NAME " No console phone.\n");
     237                return true;
    238238        }
    239239
  • uspace/drv/usbhid/multimedia/keymap.c

    re8f826b r400735e  
    4848 */
    4949static int usb_hid_keymap_consumer[0x29c] = {
    50         [0xf] = KC_F1, /* Just for testing purposes */
    51         [0x5] = KC_F2, /* Just for testing purposes */
    52         [0x8] = KC_F3, /* Just for testing purposes */
    53         [0x6] = KC_F4, /* Just for testing purposes */
    54         [0x7] = KC_F5, /* Just for testing purposes */
    55         [0xc] = KC_F6, /* Just for testing purposes */
    56        
    5750        [0xb5] = 0,       /* Scan Next Track */
    5851        [0xb6] = 0,       /* Scan Previous Track */
    5952        [0xb7] = 0,       /* Stop */
    6053        [0xb8] = 0,       /* Eject */
    61         [0xcd] = KC_F2,   /* Play/Pause */
    62         [0xe2] = KC_F3,   /* Mute */
    63         [0xe9] = KC_F5,   /* Volume Increment */
    64         [0xea] = KC_F4,   /* Volume Decrement */
    65         [0x183] = 0,      /* AL Consumer Control Configuration */
     54        [0xcd] = 0/*KC_F2*/,   /* Play/Pause */
     55        [0xe2] = 0/*KC_F3*/,   /* Mute */
     56        [0xe9] = 0/*KC_F5*/,   /* Volume Increment */
     57        [0xea] = 0/*KC_F4*/,   /* Volume Decrement */
     58        [0x183] = 0/*KC_F1*/,      /* AL Consumer Control Configuration */
    6659        [0x18a] = 0,      /* AL Email Reader */
    6760        [0x192] = 0,      /* AL Calculator */
    6861        [0x221] = 0,      /* AC Search */
    69         [0x223] = 0,      /* AC Home */
     62        [0x223] = 0/*KC_F6*/,      /* AC Home */
    7063        [0x224] = 0,      /* AC Back */
    7164        [0x225] = 0,      /* AC Forward */
    7265        [0x226] = 0,      /* AC Stop */
    73         [0x227] = KC_F1,  /* AC Refresh */
    74         [0x22a] = KC_F6   /* AC Bookmarks */
    75 };
    76 
    77 static const char *usb_hid_consumer_usage_str[0x29d] = {
    78         [0x01] = "Consumer Control",
    79         [0x02] = "Numeric Key Pad",
    80         [0x03] = "Programmable Buttons",
    81         [0x04] = "Microphone",
    82         [0x05] = "Headphone",
    83         [0x06] = "Graphic Equalizer",
    84         [0x07] = "Reserved",
    85         [0x08] = "Reserved",
    86         [0x09] = "Reserved",
    87         [0x0a] = "Reserved",
    88         [0x0b] = "Reserved",
    89         [0x0c] = "Reserved",
    90         [0x0d] = "Reserved",
    91         [0x0e] = "Reserved",
    92         [0x0f] = "Reserved",
    93         [0x10] = "Reserved",
    94         [0x11] = "Reserved",
    95         [0x12] = "Reserved",
    96         [0x13] = "Reserved",
    97         [0x14] = "Reserved",
    98         [0x15] = "Reserved",
    99         [0x16] = "Reserved",
    100         [0x17] = "Reserved",
    101         [0x18] = "Reserved",
    102         [0x19] = "Reserved",
    103         [0x1a] = "Reserved",
    104         [0x1b] = "Reserved",
    105         [0x1c] = "Reserved",
    106         [0x1d] = "Reserved",
    107         [0x1e] = "Reserved",
    108         [0x1f] = "Reserved",
    109         [0x20] = "+10",
    110         [0x21] = "+100",
    111         [0x22] = "AM/PM",
    112         [0x23] = "Reserved",
    113         [0x24] = "Reserved",
    114         [0x25] = "Reserved",
    115         [0x26] = "Reserved",
    116         [0x27] = "Reserved",
    117         [0x28] = "Reserved",
    118         [0x29] = "Reserved",
    119         [0x2a] = "Reserved",
    120         [0x2b] = "Reserved",
    121         [0x2c] = "Reserved",
    122         [0x2d] = "Reserved",
    123         [0x2e] = "Reserved",
    124         [0x2f] = "Reserved",
    125         [0x30] = "Reserved",
    126         [0x31] = "Reserved",
    127         [0x32] = "Reserved",
    128         [0x33] = "Reserved",
    129         [0x34] = "Reserved",
    130         [0x35] = "Reserved",
    131         [0x36] = "Reserved",
    132         [0x37] = "Reserved",
    133         [0x38] = "Reserved",
    134         [0x39] = "Reserved",
    135         [0x3a] = "Reserved",
    136         [0x3b] = "Reserved",
    137         [0x3c] = "Reserved",
    138         [0x3d] = "Reserved",
    139         [0x3e] = "Reserved",
    140         [0x3f] = "Reserved",
    141         [0x40] = "Menu",
    142         [0x41] = "Menu Pick",
    143         [0x42] = "Menu Up",
    144         [0x43] = "Menu Down",
    145         [0x44] = "Menu Left",
    146         [0x45] = "Menu Right",
    147         [0x46] = "Menu Escape",
    148         [0x47] = "Menu Value Increase",
    149         [0x48] = "Menu Value Decrease",
    150         [0x49] = "Reserved",
    151         [0x4a] = "Reserved",
    152         [0x4b] = "Reserved",
    153         [0x4c] = "Reserved",
    154         [0x4d] = "Reserved",
    155         [0x4e] = "Reserved",
    156         [0x4f] = "Reserved",
    157         [0x50] = "Reserved",
    158         [0x51] = "Reserved",
    159         [0x52] = "Reserved",
    160         [0x53] = "Reserved",
    161         [0x54] = "Reserved",
    162         [0x55] = "Reserved",
    163         [0x56] = "Reserved",
    164         [0x57] = "Reserved",
    165         [0x58] = "Reserved",
    166         [0x59] = "Reserved",
    167         [0x5a] = "Reserved",
    168         [0x5b] = "Reserved",
    169         [0x5c] = "Reserved",
    170         [0x5d] = "Reserved",
    171         [0x5e] = "Reserved",
    172         [0x5f] = "Reserved",
    173         [0x60] = "Data On Screen",
    174         [0x61] = "Closed Caption",
    175         [0x62] = "Closed Caption Select",
    176         [0x63] = "VCR/TV",
    177         [0x64] = "Broadcast Mode",
    178         [0x65] = "Snapshot",
    179         [0x66] = "Still",
    180         [0x67] = "Reserved",
    181         [0x68] = "Reserved",
    182         [0x69] = "Reserved",
    183         [0x6a] = "Reserved",
    184         [0x6b] = "Reserved",
    185         [0x6c] = "Reserved",
    186         [0x6d] = "Reserved",
    187         [0x6e] = "Reserved",
    188         [0x6f] = "Reserved",
    189         [0x70] = "Reserved",
    190         [0x71] = "Reserved",
    191         [0x72] = "Reserved",
    192         [0x73] = "Reserved",
    193         [0x74] = "Reserved",
    194         [0x75] = "Reserved",
    195         [0x76] = "Reserved",
    196         [0x77] = "Reserved",
    197         [0x78] = "Reserved",
    198         [0x79] = "Reserved",
    199         [0x7a] = "Reserved",
    200         [0x7b] = "Reserved",
    201         [0x7c] = "Reserved",
    202         [0x7d] = "Reserved",
    203         [0x7e] = "Reserved",
    204         [0x7f] = "Reserved",
    205         [0x80] = "Selection",
    206         [0x81] = "Assign Selection",
    207         [0x82] = "Mode Step",
    208         [0x83] = "Recall Last",
    209         [0x84] = "Enter Channel",
    210         [0x85] = "Order Movie",
    211         [0x86] = "Channel",
    212         [0x87] = "Media Selection",
    213         [0x88] = "Media Select Computer",
    214         [0x89] = "Media Select TV",
    215         [0x8a] = "Media Select WWW",
    216         [0x8b] = "Media Select DVD",
    217         [0x8c] = "Media Select Telephone",
    218         [0x8d] = "Media Select Program Guide",
    219         [0x8e] = "Media Select Video Phone",
    220         [0x8f] = "Media Select Games",
    221         [0x90] = "Media Select Messages",
    222         [0x91] = "Media Select CD",
    223         [0x92] = "Media Select VCR",
    224         [0x93] = "Media Select Tuner",
    225         [0x94] = "Quit",
    226         [0x95] = "Help",
    227         [0x96] = "Media Select Tape",
    228         [0x97] = "Media Select Cable",
    229         [0x98] = "Media Select Satellite",
    230         [0x99] = "Media Select Security",
    231         [0x9a] = "Media Select Home",
    232         [0x9b] = "Media Select Call",
    233         [0x9c] = "Channel Increment",
    234         [0x9d] = "Channel Decrement",
    235         [0x9e] = "Media Select SAP",
    236         [0x9f] = "Reserved",
    237         [0xa0] = "VCR Plus",
    238         [0xa1] = "Once",
    239         [0xa2] = "Daily",
    240         [0xa3] = "Weekly",
    241         [0xa4] = "Monthly",
    242         [0xa5] = "Reserved",
    243         [0xa6] = "Reserved",
    244         [0xa7] = "Reserved",
    245         [0xa8] = "Reserved",
    246         [0xa9] = "Reserved",
    247         [0xaa] = "Reserved",
    248         [0xab] = "Reserved",
    249         [0xac] = "Reserved",
    250         [0xad] = "Reserved",
    251         [0xae] = "Reserved",
    252         [0xaf] = "Reserved",
    253         [0xb0] = "Play",
    254         [0xb1] = "Pause",
    255         [0xb2] = "Record",
    256         [0xb3] = "Fast Forward",
    257         [0xb4] = "Rewind",
    258         [0xb5] = "Scan Next Track",
    259         [0xb6] = "Scan Previous Trac",
    260         [0xb7] = "Stop",
    261         [0xb8] = "Eject",
    262         [0xb9] = "Random Play",
    263         [0xba] = "Select Disc",
    264         [0xbb] = "Enter Disc",
    265         [0xbc] = "Repeat",
    266         [0xbd] = "Tracking",
    267         [0xbe] = "Track Normal",
    268         [0xbf] = "Slow Tracking",
    269         [0xc0] = "Frame Forward",
    270         [0xc1] = "Frame Back",
    271         [0xc2] = "Mark",
    272         [0xc3] = "Clear Mark",
    273         [0xc4] = "Repeat From Mark",
    274         [0xc5] = "Return to Mark",
    275         [0xc6] = "Search Mark Forward",
    276         [0xc7] = "Search Mark Backwards",
    277         [0xc8] = "Counter Reset",
    278         [0xc9] = "Show Counter",
    279         [0xca] = "Tracking Increment",
    280         [0xcb] = "Tracking Decrement",
    281         [0xcc] = "Stop/Eject",
    282         [0xcd] = "Play/Pause",
    283         [0xce] = "Play/Skip",
    284         [0xcf] = "Reserved",
    285         [0xd0] = "Reserved",
    286         [0xd1] = "Reserved",
    287         [0xd2] = "Reserved",
    288         [0xd3] = "Reserved",
    289         [0xd4] = "Reserved",
    290         [0xd5] = "Reserved",
    291         [0xd6] = "Reserved",
    292         [0xd7] = "Reserved",
    293         [0xd8] = "Reserved",
    294         [0xd9] = "Reserved",
    295         [0xda] = "Reserved",
    296         [0xdb] = "Reserved",
    297         [0xdc] = "Reserved",
    298         [0xdd] = "Reserved",
    299         [0xde] = "Reserved",
    300         [0xdf] = "Reserved",
    301         [0xe0] = "Volume",
    302         [0xe1] = "Balance",
    303         [0xe2] = "Mute",
    304         [0xe3] = "Bass",
    305         [0xe4] = "Treble",
    306         [0xe5] = "Bass Boost",
    307         [0xe6] = "Surround Mode",
    308         [0xe7] = "Loudness",
    309         [0xe8] = "MPX",
    310         [0xe9] = "Volume Increment",
    311         [0xea] = "Volume Decrement",
    312         [0xeb] = "Reserved",
    313         [0xec] = "Reserved",
    314         [0xed] = "Reserved",
    315         [0xee] = "Reserved",
    316         [0xef] = "Reserved",
    317         [0xf0] = "Speed Select",
    318         [0xf1] = "Playback Speed",
    319         [0xf2] = "Standard Play",
    320         [0xf3] = "Long Play",
    321         [0xf4] = "Extended Play",
    322         [0xf5] = "Slow",
    323         [0xf6] = "Reserved",
    324         [0xf7] = "Reserved",
    325         [0xf8] = "Reserved",
    326         [0xf9] = "Reserved",
    327         [0xfa] = "Reserved",
    328         [0xfb] = "Reserved",
    329         [0xfc] = "Reserved",
    330         [0xfd] = "Reserved",
    331         [0xfe] = "Reserved",
    332         [0xff] = "Reserved",
    333         [0x100] = "Fan Enable",
    334         [0x101] = "Fan Speed",
    335         [0x102] = "Light Enable",
    336         [0x103] = "Light Illumination Level",
    337         [0x104] = "Climate Control Enable",
    338         [0x105] = "Room Temperature",
    339         [0x106] = "Security Enable",
    340         [0x107] = "Fire Alarm",
    341         [0x108] = "Police Alarm",
    342         [0x109] = "Proximity",
    343         [0x10a] = "Motion",
    344         [0x10b] = "Duress Alarm",
    345         [0x10c] = "Holdup Alarm",
    346         [0x10d] = "Medical Alarm",
    347         [0x10e] = "Reserved",
    348         [0x10f] = "Reserved",
    349         [0x110] = "Reserved",
    350         [0x111] = "Reserved",
    351         [0x112] = "Reserved",
    352         [0x113] = "Reserved",
    353         [0x114] = "Reserved",
    354         [0x115] = "Reserved",
    355         [0x116] = "Reserved",
    356         [0x117] = "Reserved",
    357         [0x118] = "Reserved",
    358         [0x119] = "Reserved",
    359         [0x11a] = "Reserved",
    360         [0x11b] = "Reserved",
    361         [0x11c] = "Reserved",
    362         [0x11d] = "Reserved",
    363         [0x11e] = "Reserved",
    364         [0x11f] = "Reserved",
    365         [0x120] = "Reserved",
    366         [0x121] = "Reserved",
    367         [0x122] = "Reserved",
    368         [0x123] = "Reserved",
    369         [0x124] = "Reserved",
    370         [0x125] = "Reserved",
    371         [0x126] = "Reserved",
    372         [0x127] = "Reserved",
    373         [0x128] = "Reserved",
    374         [0x129] = "Reserved",
    375         [0x12a] = "Reserved",
    376         [0x12b] = "Reserved",
    377         [0x12c] = "Reserved",
    378         [0x12d] = "Reserved",
    379         [0x12e] = "Reserved",
    380         [0x12f] = "Reserved",
    381         [0x130] = "Reserved",
    382         [0x131] = "Reserved",
    383         [0x132] = "Reserved",
    384         [0x133] = "Reserved",
    385         [0x134] = "Reserved",
    386         [0x135] = "Reserved",
    387         [0x136] = "Reserved",
    388         [0x137] = "Reserved",
    389         [0x138] = "Reserved",
    390         [0x139] = "Reserved",
    391         [0x13a] = "Reserved",
    392         [0x13b] = "Reserved",
    393         [0x13c] = "Reserved",
    394         [0x13d] = "Reserved",
    395         [0x13e] = "Reserved",
    396         [0x13f] = "Reserved",
    397         [0x140] = "Reserved",
    398         [0x141] = "Reserved",
    399         [0x142] = "Reserved",
    400         [0x143] = "Reserved",
    401         [0x144] = "Reserved",
    402         [0x145] = "Reserved",
    403         [0x146] = "Reserved",
    404         [0x147] = "Reserved",
    405         [0x148] = "Reserved",
    406         [0x149] = "Reserved",
    407         [0x14a] = "Reserved",
    408         [0x14b] = "Reserved",
    409         [0x14c] = "Reserved",
    410         [0x14d] = "Reserved",
    411         [0x14e] = "Reserved",
    412         [0x14f] = "Reserved",
    413         [0x150] = "Balance Right",
    414         [0x151] = "Balance Left",
    415         [0x152] = "Bass Increment",
    416         [0x153] = "Bass Decrement",
    417         [0x154] = "Treble Increment",
    418         [0x155] = "Treble Decrement",
    419         [0x156] = "Reserved",
    420         [0x157] = "Reserved",
    421         [0x158] = "Reserved",
    422         [0x159] = "Reserved",
    423         [0x15a] = "Reserved",
    424         [0x15b] = "Reserved",
    425         [0x15c] = "Reserved",
    426         [0x15d] = "Reserved",
    427         [0x15e] = "Reserved",
    428         [0x15f] = "Reserved",
    429         [0x160] = "Speaker System",
    430         [0x161] = "Channel Left",
    431         [0x162] = "Channel Right",
    432         [0x163] = "Channel Center",
    433         [0x164] = "Channel Front",
    434         [0x165] = "Channel Center Front",
    435         [0x166] = "Channel Side",
    436         [0x167] = "Channel Surround",
    437         [0x168] = "Channel Low Frequency Enhancement",
    438         [0x169] = "Channel Top",
    439         [0x16a] = "Channel Unknown",
    440         [0x16b] = "Reserved",
    441         [0x16c] = "Reserved",
    442         [0x16d] = "Reserved",
    443         [0x16e] = "Reserved",
    444         [0x16f] = "Reserved",
    445         [0x170] = "Sub-channel",
    446         [0x171] = "Sub-channel Increment",
    447         [0x172] = "Sub-channel Decrement",
    448         [0x173] = "Alternate Audio Increment",
    449         [0x174] = "Alternate Audio Decrement",
    450         [0x175] = "Reserved",
    451         [0x176] = "Reserved",
    452         [0x177] = "Reserved",
    453         [0x178] = "Reserved",
    454         [0x179] = "Reserved",
    455         [0x17a] = "Reserved",
    456         [0x17b] = "Reserved",
    457         [0x17c] = "Reserved",
    458         [0x17d] = "Reserved",
    459         [0x17e] = "Reserved",
    460         [0x17f] = "Reserved",
    461         [0x180] = "Application Launch Buttons",
    462         [0x181] = "AL Launch Buttion Configuration Tool",
    463         [0x182] = "AL Programmable Button Configuration",
    464         [0x183] = "AL Consumer Control Configuration",
    465         [0x184] = "AL Word Processor",
    466         [0x185] = "AL Text Editor",
    467         [0x186] = "AL Spreadsheet",
    468         [0x187] = "AL Graphics Editor",
    469         [0x188] = "AL Presentation App",
    470         [0x189] = "AL Database App",
    471         [0x18a] = "AL Email Reader",
    472         [0x18b] = "AL Newsreader",
    473         [0x18c] = "AL Voicemail",
    474         [0x18d] = "AL Contacts/Address Book",
    475         [0x18e] = "AL Calendar/Schedule",
    476         [0x18f] = "AL Task/Project Manager",
    477         [0x190] = "AL Log/Journal/Timecard",
    478         [0x191] = "AL Checkbook/Finance",
    479         [0x192] = "AL Calculator",
    480         [0x193] = "AL A/V Capture/Playback",
    481         [0x194] = "AL Local Machine Browser",
    482         [0x195] = "AL LAN/WAN Browser",
    483         [0x196] = "AL Internet Browser",
    484         [0x197] = "AL Remote Networking/ISP Connect",
    485         [0x198] = "AL Network Conference",
    486         [0x199] = "AL Network Chat",
    487         [0x19a] = "AL Telephony/Dialer",
    488         [0x19b] = "AL Logon",
    489         [0x19c] = "AL Logoff",
    490         [0x19d] = "AL Logon/Logoff",
    491         [0x19e] = "AL Terminal Lock/Screensaver",
    492         [0x19f] = "AL Control Panel",
    493         [0x1a0] = "AL Command Line Processor/Run",
    494         [0x1a1] = "AL Process/Task Manager",
    495         [0x1a2] = "AL Select Task/Application",
    496         [0x1a3] = "AL Next Task/Application",
    497         [0x1a4] = "AL Previous Task/Application",
    498         [0x1a5] = "AL Preemptive Halt Task/Application",
    499         [0x1a6] = "AL Integrated Help Center",
    500         [0x1a7] = "AL Documents",
    501         [0x1a8] = "AL Thesaurus",
    502         [0x1a9] = "AL Dictionary",
    503         [0x1aa] = "AL Desktop",
    504         [0x1ab] = "AL Spell Check",
    505         [0x1ac] = "AL Grammar Check",
    506         [0x1ad] = "AL Wireless Status",
    507         [0x1ae] = "AL Keyboard Layout",
    508         [0x1af] = "AL Virus Protection",
    509         [0x1b0] = "AL Encryption",
    510         [0x1b1] = "AL Screen Saver",
    511         [0x1b2] = "AL Alarms",
    512         [0x1b3] = "AL Clock",
    513         [0x1b4] = "AL File Browser",
    514         [0x1b5] = "AL Power Status",
    515         [0x1b6] = "AL Image Browser",
    516         [0x1b7] = "AL Audio Browser",
    517         [0x1b8] = "AL Movie Browser",
    518         [0x1b9] = "AL Digital Rights Manager",
    519         [0x1ba] = "AL Digital Wallet",
    520         [0x1bb] = "Reserved",
    521         [0x1bc] = "AL Instant Messaging",
    522         [0x1bd] = "AL OEM Features Tips/Tutorial Browser",
    523         [0x1be] = "AL OEM Help",
    524         [0x1bf] = "AL Online Community",
    525         [0x1c0] = "AL Entertainment Content Browser",
    526         [0x1c1] = "AL Online Shopping Browser",
    527         [0x1c2] = "AL SmartCard Information/Help",
    528         [0x1c3] = "AL Market Monitor/Finance Browser",
    529         [0x1c4] = "AL Customized Corporate News Browser",
    530         [0x1c5] = "AL Online Activity Browser",
    531         [0x1c6] = "AL Research/Search Browser",
    532         [0x1c7] = "AL Audio Player",
    533         [0x1c8] = "Reserved",
    534         [0x1c9] = "Reserved",
    535         [0x1ca] = "Reserved",
    536         [0x1cb] = "Reserved",
    537         [0x1cc] = "Reserved",
    538         [0x1cd] = "Reserved",
    539         [0x1ce] = "Reserved",
    540         [0x1cf] = "Reserved",
    541         [0x1d0] = "Reserved",
    542         [0x1d1] = "Reserved",
    543         [0x1d2] = "Reserved",
    544         [0x1d3] = "Reserved",
    545         [0x1d4] = "Reserved",
    546         [0x1d5] = "Reserved",
    547         [0x1d6] = "Reserved",
    548         [0x1d7] = "Reserved",
    549         [0x1d8] = "Reserved",
    550         [0x1d9] = "Reserved",
    551         [0x1da] = "Reserved",
    552         [0x1db] = "Reserved",
    553         [0x1dc] = "Reserved",
    554         [0x1dd] = "Reserved",
    555         [0x1de] = "Reserved",
    556         [0x1df] = "Reserved",
    557         [0x1e0] = "Reserved",
    558         [0x1e1] = "Reserved",
    559         [0x1e2] = "Reserved",
    560         [0x1e3] = "Reserved",
    561         [0x1e4] = "Reserved",
    562         [0x1e5] = "Reserved",
    563         [0x1e6] = "Reserved",
    564         [0x1e7] = "Reserved",
    565         [0x1e8] = "Reserved",
    566         [0x1e9] = "Reserved",
    567         [0x1ea] = "Reserved",
    568         [0x1eb] = "Reserved",
    569         [0x1ec] = "Reserved",
    570         [0x1ed] = "Reserved",
    571         [0x1ee] = "Reserved",
    572         [0x1ef] = "Reserved",
    573         [0x1f0] = "Reserved",
    574         [0x1f1] = "Reserved",
    575         [0x1f2] = "Reserved",
    576         [0x1f3] = "Reserved",
    577         [0x1f4] = "Reserved",
    578         [0x1f5] = "Reserved",
    579         [0x1f6] = "Reserved",
    580         [0x1f7] = "Reserved",
    581         [0x1f8] = "Reserved",
    582         [0x1f9] = "Reserved",
    583         [0x1fa] = "Reserved",
    584         [0x1fb] = "Reserved",
    585         [0x1fc] = "Reserved",
    586         [0x1fd] = "Reserved",
    587         [0x1fe] = "Reserved",
    588         [0x1ff] = "Reserved",
    589         [0x200] = "Generic GUI Application Controls",
    590         [0x201] = "AC New",
    591         [0x202] = "AC Open",
    592         [0x203] = "AC Close",
    593         [0x204] = "AC Exit",
    594         [0x205] = "AC Maximize",
    595         [0x206] = "AC Minimize",
    596         [0x207] = "AC Save",
    597         [0x208] = "AC Print",
    598         [0x209] = "AC Properties",
    599         [0x20a] = "",
    600         [0x20b] = "",
    601         [0x20c] = "",
    602         [0x20d] = "",
    603         [0x20e] = "",
    604         [0x20f] = "",
    605         [0x210] = "",
    606         [0x211] = "",
    607         [0x212] = "",
    608         [0x213] = "",
    609         [0x214] = "",
    610         [0x215] = "",
    611         [0x216] = "",
    612         [0x217] = "",
    613         [0x218] = "",
    614         [0x219] = "",
    615         [0x21a] = "AC Undo",
    616         [0x21b] = "AC Copy",
    617         [0x21c] = "AC Cut",
    618         [0x21d] = "AC Paste",
    619         [0x21e] = "AC Select All",
    620         [0x21f] = "AC Find",
    621         [0x220] = "AC Find and Replace",
    622         [0x221] = "AC Search",
    623         [0x222] = "AC Go To",
    624         [0x223] = "AC Home",
    625         [0x224] = "AC Back",
    626         [0x225] = "AC Forward",
    627         [0x226] = "AC Stop",
    628         [0x227] = "AC Refresh",
    629         [0x228] = "AC Previous Link",
    630         [0x229] = "AC Next Link",
    631         [0x22a] = "AC Bookmarks",
    632         [0x22b] = "AC History",
    633         [0x22c] = "AC Subscriptions",
    634         [0x22d] = "AC Zoom In",
    635         [0x22e] = "AC Zoom Out",
    636         [0x22f] = "AC Zoom",
    637         [0x230] = "AC Full Screen View",
    638         [0x231] = "AC Normal View",
    639         [0x232] = "AC View Toggle",
    640         [0x233] = "AC Scroll Up",
    641         [0x234] = "AC Scroll Down",
    642         [0x235] = "AC Scroll",
    643         [0x236] = "AC Pan Left",
    644         [0x237] = "AC Pan Right",
    645         [0x238] = "AC Pan",
    646         [0x239] = "AC New Window",
    647         [0x23a] = "AC Tile Horizontally",
    648         [0x23b] = "AC Tile Vertically",
    649         [0x23c] = "AC Format",
    650         [0x23d] = "AC Edit",
    651         [0x23e] = "AC Bold",
    652         [0x23f] = "AC Italics",
    653         [0x240] = "AC Undeline",
    654         [0x241] = "AC Strikethrough",
    655         [0x242] = "AC Subscript",
    656         [0x243] = "AC Superscript",
    657         [0x244] = "AC All Caps",
    658         [0x245] = "AC Rotate",
    659         [0x246] = "AC Resize",
    660         [0x247] = "AC Flip Horizontal",
    661         [0x248] = "AC Flip Vertical",
    662         [0x249] = "AC Mirror Horizontal",
    663         [0x24a] = "AC Mirror Vertical",
    664         [0x24b] = "AC Font Select",
    665         [0x24c] = "AC Font Color",
    666         [0x24d] = "AC Font Size",
    667         [0x24e] = "AC Justify Left",
    668         [0x24f] = "AC Justify Center H",
    669         [0x250] = "AC Justify Right",
    670         [0x251] = "AC Justify Block H",
    671         [0x252] = "AC Justify Top",
    672         [0x253] = "AC Justify Center V",
    673         [0x254] = "AC Justify Bottom",
    674         [0x255] = "AC Justify Block V",
    675         [0x256] = "AC Indent Decrease",
    676         [0x257] = "AC Indent Increase",
    677         [0x258] = "AC Numbered List",
    678         [0x259] = "AC Restart Numbering",
    679         [0x25a] = "AC Bulleted List",
    680         [0x25b] = "AC Promote",
    681         [0x25c] = "AC Demote",
    682         [0x25d] = "AC Yes",
    683         [0x25e] = "AC No",
    684         [0x25f] = "AC Cancel",
    685         [0x260] = "AC Catalog",
    686         [0x261] = "AC Buy/Checkout",
    687         [0x262] = "AC Add to Cart",
    688         [0x263] = "AC Expand",
    689         [0x264] = "AC Expand All",
    690         [0x265] = "AC Collapse",
    691         [0x266] = "AC Collapse All",
    692         [0x267] = "AC Print Preview",
    693         [0x268] = "AC Paste Special",
    694         [0x269] = "AC Insert Mode",
    695         [0x26a] = "AC Delete",
    696         [0x26b] = "AC Lock",
    697         [0x26c] = "AC Unlock",
    698         [0x26d] = "AC Protect",
    699         [0x26e] = "AC Unprotect",
    700         [0x26f] = "AC Attach Comment",
    701         [0x270] = "AC Delete Comment",
    702         [0x271] = "AC View Comment",
    703         [0x272] = "AC Select Word",
    704         [0x273] = "AC Select Sentence",
    705         [0x274] = "AC Select Paragraph",
    706         [0x275] = "AC Select Column",
    707         [0x276] = "AC Select Row",
    708         [0x277] = "AC Select Table",
    709         [0x278] = "AC Select Object",
    710         [0x279] = "AC Redo/Repeat",
    711         [0x27a] = "AC Sort",
    712         [0x27b] = "AC Sort Ascending",
    713         [0x27c] = "AC Sort Descending",
    714         [0x27d] = "AC Filter",
    715         [0x27e] = "AC Set Clock",
    716         [0x27f] = "AC View Clock",
    717         [0x280] = "AC Select Time Zone",
    718         [0x281] = "AC Edit Time Zones",
    719         [0x282] = "AC Set Alarm",
    720         [0x283] = "AC Clear Alarm",
    721         [0x284] = "AC Snooze Alarm",
    722         [0x285] = "AC Reset Alarm",
    723         [0x286] = "AC Synchronize",
    724         [0x287] = "AC Send/Receive",
    725         [0x288] = "AC Send To",
    726         [0x289] = "AC Reply",
    727         [0x28a] = "AC Reply All",
    728         [0x28b] = "AC Forward Msg",
    729         [0x28c] = "AC Send",
    730         [0x28d] = "AC Attach File",
    731         [0x28e] = "AC Upload",
    732         [0x28f] = "AC Download (Save Target As)",
    733         [0x290] = "AC Set Borders",
    734         [0x291] = "AC Insert Row",
    735         [0x292] = "AC Insert Column",
    736         [0x293] = "AC Insert File",
    737         [0x294] = "AC Insert Picture",
    738         [0x295] = "AC Insert Object",
    739         [0x296] = "AC Insert Symbol",
    740         [0x297] = "AC Save and Close",
    741         [0x298] = "AC Rename",
    742         [0x299] = "AC Merge",
    743         [0x29a] = "AC Split",
    744         [0x29b] = "AC Distrubute Horizontally",
    745         [0x29c] = "AC Distrubute Vertically"
     66        [0x227] = 0,  /* AC Refresh */
     67        [0x22a] = 0   /* AC Bookmarks */
    74668};
    74769
     
    76991
    77092/**
    771  * Translates USB HID Usages from the Consumer Page into their string
    772  * representation.
    773  *
    774  * @param usage USB HID Consumer Page Usage number.
    775  *
    776  * @retval HelenOS key code corresponding to the given USB Consumer Page Usage.
    777  */
    778 const char *usb_multimedia_usage_to_str(int usage)
    779 {
    780         size_t map_length = sizeof(usb_hid_consumer_usage_str) / sizeof(char *);
    781 
    782         if ((usage < 0) || ((size_t)usage >= map_length))
    783                 return "Unknown usage";
    784 
    785         /*! @todo What if the usage is not in the table? */
    786         return usb_hid_consumer_usage_str[usage];
    787 }
    788 
    789 /**
    79093 * @}
    79194 */
  • uspace/drv/usbhid/multimedia/keymap.h

    re8f826b r400735e  
    3939unsigned int usb_multimedia_map_usage(int usage);
    4040
    41 const char *usb_multimedia_usage_to_str(int usage);
    42 
    4341#endif /* USB_HID_MULTIMEDIA_KEYMAP_H_ */
    4442
  • uspace/drv/usbhid/multimedia/multimedia.c

    re8f826b r400735e  
    4343#include <usb/debug.h>
    4444#include <usb/hid/usages/core.h>
     45#include <usb/hid/usages/consumer.h>
    4546
    4647#include <errno.h>
     
    5859typedef struct usb_multimedia_t {
    5960        /** Previously pressed keys (not translated to key codes). */
    60         int32_t *keys_old;
     61        //int32_t *keys_old;
    6162        /** Currently pressed keys (not translated to key codes). */
    62         int32_t *keys;
     63        //int32_t *keys;
    6364        /** Count of stored keys (i.e. number of keys in the report). */
    64         size_t key_count;       
     65        //size_t key_count;     
    6566        /** IPC phone to the console device (for sending key events). */
    6667        int console_phone;
     
    174175       
    175176        // free all buffers
    176         if ((*multim_dev)->keys != NULL) {
    177                 free((*multim_dev)->keys);
    178         }
    179         if ((*multim_dev)->keys_old != NULL) {
    180                 free((*multim_dev)->keys_old);
    181         }
     177//      if ((*multim_dev)->keys != NULL) {
     178//              free((*multim_dev)->keys);
     179//      }
     180//      if ((*multim_dev)->keys_old != NULL) {
     181//              free((*multim_dev)->keys_old);
     182//      }
    182183
    183184        free(*multim_dev);
     
    209210                return rc;
    210211        }
     212       
     213        usb_log_debug("%s function created (jandle: %" PRIun ").\n",
     214            NAME, fun->handle);
    211215       
    212216        rc = ddf_fun_add_to_class(fun, "keyboard");
     
    241245        multim_dev->console_phone = -1;
    242246       
    243         usb_hid_report_path_t *path = usb_hid_report_path();
    244         usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_CONSUMER, 0);
    245        
    246         usb_hid_report_path_set_report_id(path, 1);
    247        
    248         multim_dev->key_count = usb_hid_report_size(
    249             hid_dev->report, 0, USB_HID_REPORT_TYPE_INPUT);
    250 
    251         usb_hid_report_path_free(path);
    252        
    253         usb_log_debug(NAME " Size of the input report: %zu\n",
    254             multim_dev->key_count);
    255        
    256         multim_dev->keys = (int32_t *)calloc(multim_dev->key_count,
    257             sizeof(int32_t));
    258        
    259         if (multim_dev->keys == NULL) {
    260                 usb_log_fatal("No memory!\n");
    261                 free(multim_dev);
    262                 return ENOMEM;
    263         }
    264        
    265         multim_dev->keys_old =
    266                 (int32_t *)calloc(multim_dev->key_count, sizeof(int32_t));
    267        
    268         if (multim_dev->keys_old == NULL) {
    269                 usb_log_fatal("No memory!\n");
    270                 free(multim_dev->keys);
    271                 free(multim_dev);
    272                 return ENOMEM;
    273         }
     247//      usb_hid_report_path_t *path = usb_hid_report_path();
     248//      usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_CONSUMER, 0);
     249       
     250//      usb_hid_report_path_set_report_id(path, 1);
     251       
     252//      multim_dev->key_count = usb_hid_report_size(
     253//          hid_dev->report, 1, USB_HID_REPORT_TYPE_INPUT);
     254
     255//      usb_hid_report_path_free(path);
     256       
     257//      usb_log_debug(NAME " Size of the input report: %zu\n",
     258//          multim_dev->key_count);
     259       
     260//      multim_dev->keys = (int32_t *)calloc(multim_dev->key_count,
     261//          sizeof(int32_t));
     262       
     263//      if (multim_dev->keys == NULL) {
     264//              usb_log_fatal("No memory!\n");
     265//              free(multim_dev);
     266//              return ENOMEM;
     267//      }
     268       
     269//      multim_dev->keys_old =
     270//              (int32_t *)calloc(multim_dev->key_count, sizeof(int32_t));
     271       
     272//      if (multim_dev->keys_old == NULL) {
     273//              usb_log_fatal("No memory!\n");
     274//              free(multim_dev->keys);
     275//              free(multim_dev);
     276//              return ENOMEM;
     277//      }
    274278       
    275279        /*! @todo Autorepeat */
     
    357361                            usb_multimedia_map_usage(field->usage);
    358362                        const char *key_str =
    359                             usb_multimedia_usage_to_str(field->usage);
     363                            usbhid_multimedia_usage_to_str(field->usage);
    360364                        usb_log_info("Pressed key: %s\n", key_str);
    361365                        usb_multimedia_push_ev(hid_dev, multim_dev, KEY_PRESS,
  • uspace/drv/usbhid/subdrivers.c

    re8f826b r400735e  
    3838#include <usb/hid/hidpath.h>
    3939
    40 //#include "lgtch-ultrax/lgtch-ultrax.h"
    4140#include "multimedia/multimedia.h"
    4241#include "mouse/mousedev.h"
     42#include "generic/hiddev.h"
    4343
    4444static usb_hid_subdriver_usage_t path_kbd[] = {
     
    5858};
    5959
     60//static usb_hid_subdriver_usage_t generic_hid_key_path[] = {
     61//      {0, 0}
     62//};
     63
    6064const usb_hid_subdriver_mapping_t usb_hid_subdrivers[] = {
    6165        {
    6266                path_kbd,
    63                 -1,
     67                0,
    6468                USB_HID_PATH_COMPARE_BEGIN,
    6569                -1,
     
    8892        {
    8993                path_mouse,
    90                 -1,
     94                0,
    9195                USB_HID_PATH_COMPARE_BEGIN,
    9296                -1,
     
    99103                }
    100104        },
     105//      {
     106//              generic_hid_key_path,
     107//              0,
     108//              USB_HID_PATH_COMPARE_ANYWHERE,
     109//              -1,
     110//              -1,
     111//              {
     112//                      .init = usb_generic_hid_init,
     113//                      .deinit = NULL,
     114//                      .poll = usb_generic_hid_polling_callback,
     115//                      .poll_end = NULL
     116//              }
     117//      },
    101118        {NULL, -1, 0, -1, -1, {NULL, NULL, NULL, NULL, NULL}}
    102119};
  • uspace/drv/usbhid/usbhid.c

    re8f826b r400735e  
    6363static const int USB_HID_MAX_SUBDRIVERS = 10;
    6464
    65 static fibril_local bool report_received;
     65/** @todo What happens if this is not fibril local? */
     66//static fibril_local bool report_number;
    6667
    6768/*----------------------------------------------------------------------------*/
     
    234235        }
    235236       
    236         hid_dev->subdrivers = (usb_hid_subdriver_t *)malloc(count *
     237        // add one generic HID subdriver per device
     238       
     239        hid_dev->subdrivers = (usb_hid_subdriver_t *)malloc((count + 1) *
    237240            sizeof(usb_hid_subdriver_t));
    238241        if (hid_dev->subdrivers == NULL) {
     
    247250        }
    248251       
    249         hid_dev->subdriver_count = count;
     252        hid_dev->subdrivers[count].init = usb_generic_hid_init;
     253        hid_dev->subdrivers[count].poll = usb_generic_hid_polling_callback;
     254        hid_dev->subdrivers[count].deinit = NULL;
     255        hid_dev->subdrivers[count].poll_end = NULL;
     256       
     257        hid_dev->subdriver_count = count + 1;
    250258       
    251259        return EOK;
     
    307315               
    308316                if (matched) {
     317                        usb_log_debug("Subdriver matched.\n");
    309318                        subdrivers[count++] = &mapping->subdriver;
    310319                }
     
    348357/*----------------------------------------------------------------------------*/
    349358
     359static int usb_hid_init_report(usb_hid_dev_t *hid_dev)
     360{
     361        assert(hid_dev != NULL && hid_dev->report != NULL);
     362       
     363        uint8_t report_id = 0;
     364        size_t size;/* = usb_hid_report_byte_size(hid_dev->report, report_id,
     365            USB_HID_REPORT_TYPE_INPUT);*/
     366       
     367        size_t max_size = 0;
     368       
     369        do {
     370                size = usb_hid_report_byte_size(hid_dev->report, report_id,
     371                    USB_HID_REPORT_TYPE_INPUT);
     372                usb_log_debug("Report ID: %u, size: %zu\n", report_id, size);
     373                max_size = (size > max_size) ? size : max_size;
     374                report_id = usb_hid_get_next_report_id(hid_dev->report,
     375                    report_id, USB_HID_REPORT_TYPE_INPUT);
     376        } while (report_id != 0);
     377       
     378        usb_log_debug("Max size of input report: %zu\n", max_size);
     379       
     380        hid_dev->max_input_report_size = max_size;
     381        assert(hid_dev->input_report == NULL);
     382       
     383        hid_dev->input_report = malloc(max_size);
     384        if (hid_dev->input_report == NULL) {
     385                return ENOMEM;
     386        }
     387        memset(hid_dev->input_report, 0, max_size);
     388       
     389        return EOK;
     390}
     391
     392/*----------------------------------------------------------------------------*/
     393
    350394usb_hid_dev_t *usb_hid_new(void)
    351395{
     
    402446        /* Get the report descriptor and parse it. */
    403447        rc = usb_hid_process_report_descriptor(hid_dev->usb_dev,
    404             hid_dev->report);
     448            hid_dev->report, &hid_dev->report_desc, &hid_dev->report_desc_size);
    405449       
    406450        bool fallback = false;
     
    483527        }
    484528       
     529        // save max input report size and allocate space for the report
     530        rc = usb_hid_init_report(hid_dev);
     531        if (rc != EOK) {
     532                usb_log_error("Failed to initialize input report buffer.\n");
     533        }
     534       
    485535        return rc;
    486536}
     
    500550        usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)arg;
    501551       
    502         int allocated = (hid_dev->input_report != NULL);
    503        
    504         if (!allocated
    505             || hid_dev->input_report_size < buffer_size) {
    506                 uint8_t *input_old = hid_dev->input_report;
    507                 uint8_t *input_new = (uint8_t *)malloc(buffer_size);
    508                
    509                 if (input_new == NULL) {
    510                         usb_log_error("Failed to allocate space for input "
    511                             "buffer. This event may not be reported\n");
    512                         memset(hid_dev->input_report, 0,
    513                             hid_dev->input_report_size);
    514                 } else {
    515                         memcpy(input_new, input_old,
    516                             hid_dev->input_report_size);
    517                         hid_dev->input_report = input_new;
    518                         if (allocated) {
    519                                 free(input_old);
    520                         }
    521                         usb_hid_new_report();
    522                 }
    523         }
     552//      int allocated = (hid_dev->input_report != NULL);
     553        assert(hid_dev->input_report != NULL);
     554        usb_log_debug("Max input report size: %zu, buffer size: %zu\n",
     555            hid_dev->max_input_report_size, buffer_size);
     556        assert(hid_dev->max_input_report_size >= buffer_size);
     557       
     558//      if (/*!allocated*/
     559//          /*|| *//*hid_dev->input_report_size < buffer_size*/) {
     560//              uint8_t *input_old = hid_dev->input_report;
     561//              uint8_t *input_new = (uint8_t *)malloc(buffer_size);
     562               
     563//              if (input_new == NULL) {
     564//                      usb_log_error("Failed to allocate space for input "
     565//                          "buffer. This event may not be reported\n");
     566//                      memset(hid_dev->input_report, 0,
     567//                          hid_dev->input_report_size);
     568//              } else {
     569//                      memcpy(input_new, input_old,
     570//                          hid_dev->input_report_size);
     571//                      hid_dev->input_report = input_new;
     572//                      if (allocated) {
     573//                              free(input_old);
     574//                      }
     575//                      usb_hid_new_report();
     576//              }
     577//      }
    524578       
    525579        /*! @todo This should probably be atomic. */
    526580        memcpy(hid_dev->input_report, buffer, buffer_size);
    527581        hid_dev->input_report_size = buffer_size;
     582        usb_hid_new_report(hid_dev);
    528583       
    529584        bool cont = false;
     
    601656/*----------------------------------------------------------------------------*/
    602657
    603 void usb_hid_new_report(void)
    604 {
    605         report_received = false;
    606 }
    607 
    608 /*----------------------------------------------------------------------------*/
    609 
    610 void usb_hid_report_received(void)
    611 {
    612         report_received = true;
    613 }
    614 
    615 /*----------------------------------------------------------------------------*/
    616 
    617 bool usb_hid_report_ready(void)
    618 {
    619         return !report_received;
    620 }
     658void usb_hid_new_report(usb_hid_dev_t *hid_dev)
     659{
     660        ++hid_dev->report_nr;
     661}
     662
     663/*----------------------------------------------------------------------------*/
     664
     665int usb_hid_report_number(usb_hid_dev_t *hid_dev)
     666{
     667        return hid_dev->report_nr;
     668}
     669
     670/*----------------------------------------------------------------------------*/
     671
     672//void usb_hid_report_received(void)
     673//{
     674//      ++report_number;
     675//}
     676
     677/*----------------------------------------------------------------------------*/
     678
     679//bool usb_hid_report_ready(void)
     680//{
     681//      return !report_received;
     682//}
    621683
    622684/*----------------------------------------------------------------------------*/
  • uspace/drv/usbhid/usbhid.h

    re8f826b r400735e  
    9898       
    9999        size_t input_report_size;
     100        size_t max_input_report_size;
     101       
     102        int report_nr;
    100103} usb_hid_dev_t;
    101104
     
    127130//const char *usb_hid_get_class_name(const usb_hid_dev_t *hid_dev);
    128131
    129 void usb_hid_new_report(void);
     132void usb_hid_new_report(usb_hid_dev_t *hid_dev);
    130133
    131 void usb_hid_report_received(void);
     134int usb_hid_report_number(usb_hid_dev_t *hid_dev);
    132135
    133 bool usb_hid_report_ready(void);
     136//void usb_hid_report_received(void);
     137
     138//bool usb_hid_report_ready(void);
    134139
    135140void usb_hid_free(usb_hid_dev_t **hid_dev);
  • uspace/drv/usbhub/usbhub.c

    re8f826b r400735e  
    6767    usb_hub_status_t status);
    6868
    69 static int usb_process_hub_power_change(usb_hub_info_t * hub_info,
     69static int usb_process_hub_local_power_change(usb_hub_info_t * hub_info,
    7070    usb_hub_status_t status);
    7171
     
    336336 */
    337337static int usb_hub_start_hub_fibril(usb_hub_info_t * hub_info){
    338         /*
    339          * The processing will require opened control pipe and connection
    340          * to the host controller.
    341          * It is waste of resources but let's hope there will be less
    342          * hubs than the phone limit.
    343          * FIXME: with some proper locking over pipes and session
    344          * auto destruction, this could work better.
    345          */
    346         int rc = usb_hc_connection_open(&hub_info->connection);
    347         if (rc != EOK) {
    348                 //usb_pipe_end_session(hub_info->control_pipe);
    349                 usb_log_error("Failed to open connection to HC: %s.\n",
    350                     str_error(rc));
    351                 return rc;
    352         }
     338        int rc;
    353339
    354340        rc = usb_device_auto_poll(hub_info->usb_device, 0,
     
    386372        int opResult;
    387373        if (usb_hub_is_status(status,USB_HUB_FEATURE_HUB_OVER_CURRENT)){
    388                 opResult = usb_hub_clear_feature(hub_info->control_pipe,
    389                     USB_HUB_FEATURE_HUB_LOCAL_POWER);
    390                 if (opResult != EOK) {
    391                         usb_log_error("cannot power off hub: %d\n",
    392                             opResult);
     374                //poweroff all ports
     375                unsigned int port;
     376                for(port = 1;port <= hub_info->port_count;++port){
     377                        opResult = usb_hub_clear_port_feature(
     378                            hub_info->control_pipe,port,
     379                            USB_HUB_FEATURE_PORT_POWER);
     380                        if (opResult != EOK) {
     381                                usb_log_warning(
     382                                    "cannot power off port %d;  %d\n",
     383                                    port, opResult);
     384                        }
    393385                }
    394386        } else {
    395                 opResult = usb_hub_set_feature(hub_info->control_pipe,
    396                     USB_HUB_FEATURE_HUB_LOCAL_POWER);
    397                 if (opResult != EOK) {
    398                         usb_log_error("cannot power on hub: %d\n",
    399                             opResult);
     387                //power all ports
     388                unsigned int port;
     389                for(port = 1;port <= hub_info->port_count;++port){
     390                        opResult = usb_hub_set_port_feature(
     391                            hub_info->control_pipe,port,
     392                            USB_HUB_FEATURE_PORT_POWER);
     393                        if (opResult != EOK) {
     394                                usb_log_warning(
     395                                    "cannot power off port %d;  %d\n",
     396                                    port, opResult);
     397                        }
    400398                }
    401399        }
     
    404402
    405403/**
    406  * process hub power change
    407  *
    408  * If the power has been lost, reestablish it.
    409  * If it was reestablished, re-power all ports.
     404 * process hub local power change
     405 *
     406 * This change is ignored.
    410407 * @param hub_info hub instance
    411408 * @param status hub status bitmask
    412409 * @return error code
    413410 */
    414 static int usb_process_hub_power_change(usb_hub_info_t * hub_info,
     411static int usb_process_hub_local_power_change(usb_hub_info_t * hub_info,
    415412    usb_hub_status_t status) {
    416413        int opResult = EOK;
    417         if (!usb_hub_is_status(status,USB_HUB_FEATURE_HUB_LOCAL_POWER)) {
    418                 //restart power on hub
    419                 opResult = usb_hub_set_feature(hub_info->control_pipe,
    420                     USB_HUB_FEATURE_HUB_LOCAL_POWER);
    421                 if (opResult != EOK) {
    422                         usb_log_error("cannot power on hub: %d\n",
    423                             opResult);
    424                 }
    425         } else {//power reestablished on hub- restart ports
    426                 size_t port;
    427                 for (port = 1; port <= hub_info->port_count; ++port) {
    428                         opResult = usb_hub_set_port_feature(
    429                             hub_info->control_pipe,
    430                             port, USB_HUB_FEATURE_PORT_POWER);
    431                         if (opResult != EOK) {
    432                                 usb_log_error("Cannot power on port %zu: %s.\n",
    433                                     port, str_error(opResult));
    434                         }
    435                 }
    436         }
    437         if(opResult!=EOK){
    438                 return opResult;//no feature clearing
    439         }
    440414        opResult = usb_hub_clear_feature(hub_info->control_pipe,
    441415            USB_HUB_FEATURE_C_HUB_LOCAL_POWER);
     
    452426 *
    453427 * The change can be either in the over-current condition or
    454  * local-power lost condition.
     428 * local-power change.
    455429 * @param hub_info hub instance
    456430 */
     
    487461        if (
    488462            usb_hub_is_status(status,16+USB_HUB_FEATURE_C_HUB_LOCAL_POWER)) {
    489                 usb_process_hub_power_change(hub_info, status);
     463                usb_process_hub_local_power_change(hub_info, status);
    490464        }
    491465}
  • uspace/lib/drv/Makefile

    re8f826b r400735e  
    4040        generic/remote_usb.c \
    4141        generic/remote_pci.c \
    42         generic/remote_usbhc.c
     42        generic/remote_usbhc.c \
     43        generic/remote_usbhid.c
    4344
    4445include $(USPACE_PREFIX)/Makefile.common
  • uspace/lib/drv/generic/dev_iface.c

    re8f826b r400735e  
    4646#include "remote_pci.h"
    4747
     48#include <stdio.h>
     49
    4850static iface_dipatch_table_t remote_ifaces = {
    4951        .ifaces = {
     
    6062{
    6163        assert(is_valid_iface_idx(idx));
     64       
    6265        return remote_ifaces.ifaces[idx];
    6366}
  • uspace/lib/drv/generic/driver.c

    re8f826b r400735e  
    405405                                /* The interface has not such method */
    406406                                printf("%s: driver_connection_gen error - "
    407                                     "invalid interface method.", driver->name);
     407                                    "invalid interface method "
     408                                    "(index %" PRIun ").\n",
     409                                    driver->name, iface_method_idx);
    408410                                async_answer_0(callid, ENOTSUP);
    409411                                break;
  • uspace/lib/drv/generic/remote_usbhid.c

    re8f826b r400735e  
    3636#include <errno.h>
    3737#include <assert.h>
     38#include <stdio.h>
    3839
    3940#include "usbhid_iface.h"
     
    4243static void remote_usbhid_get_event_length(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
    4344static void remote_usbhid_get_event(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
     45static void remote_usbhid_get_report_descriptor_length(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
     46static void remote_usbhid_get_report_descriptor(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
    4447// static void remote_usbhid_(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
    4548
     
    4750static remote_iface_func_ptr_t remote_usbhid_iface_ops [] = {
    4851        remote_usbhid_get_event_length,
    49         remote_usbhid_get_event
     52        remote_usbhid_get_event,
     53        remote_usbhid_get_report_descriptor_length,
     54        remote_usbhid_get_report_descriptor
    5055};
    5156
     
    5863};
    5964
    60 usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface;
     65//usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface;
    6166
    6267
     
    6469    ipc_callid_t callid, ipc_call_t *call)
    6570{
     71        printf("remote_usbhid_get_event_length()\n");
     72       
    6673        usbhid_iface_t *hid_iface = (usbhid_iface_t *) iface;
    6774
    6875        if (!hid_iface->get_event_length) {
    69                 async_answer_0(callid, ENOTSUP);
    70                 return;
    71         }
    72 
    73         int len = hid_iface->get_event_length(fun);
    74         if (len == 0) {
    75                 len = EEMPTY;
    76         }
    77         if (len < 0) {
    78                 async_answer_0(callid, len);
    79         } else {
    80                 async_answer_1(callid, EOK, len);
    81         }
     76                printf("Get event length not set!\n");
     77                async_answer_0(callid, ENOTSUP);
     78                return;
     79        }
     80
     81        size_t len = hid_iface->get_event_length(fun);
     82//      if (len == 0) {
     83//              len = EEMPTY;
     84//      }
     85        async_answer_1(callid, EOK, len);
     86       
     87//      if (len < 0) {
     88//              async_answer_0(callid, len);
     89//      } else {
     90//              async_answer_1(callid, EOK, len);
     91//      }
    8292}
    8393
     
    100110                return;
    101111        }
    102         /* Check that length is even number. Truncate otherwise. */
    103         if ((len % 2) == 1) {
    104                 len--;
    105         }
     112//      /* Check that length is even number. Truncate otherwise. */
     113//      if ((len % 2) == 1) {
     114//              len--;
     115//      }
    106116        if (len == 0) {
    107117                async_answer_0(data_callid, EINVAL);
    108118                async_answer_0(callid, EINVAL);
     119                return;
    109120        }
    110121
    111122        int rc;
    112123
    113         size_t items = len / 2;
    114         uint16_t *usage_pages_and_usages = malloc(sizeof(uint16_t) * len);
    115         if (usage_pages_and_usages == NULL) {
     124        uint8_t *data = malloc(len);
     125        if (data == NULL) {
    116126                async_answer_0(data_callid, ENOMEM);
    117127                async_answer_0(callid, ENOMEM);
    118         }
    119 
    120         size_t act_items;
    121         int rc = hid_iface->get_event(fun, usage_pages_and_usages,
    122             usage_pages_and_usages + items, items, &act_items, flags);
     128                return;
     129        }
     130
     131        size_t act_length;
     132        int event_nr;
     133        rc = hid_iface->get_event(fun, data, len, &act_length, &event_nr, flags);
    123134        if (rc != EOK) {
    124                 free(usage_pages_and_usages);
     135                free(data);
    125136                async_answer_0(data_callid, rc);
    126137                async_answer_0(callid, rc);
    127         }
    128         if (act_items >= items) {
     138                return;
     139        }
     140        if (act_length >= len) {
    129141                /* This shall not happen. */
    130142                // FIXME: how about an assert here?
    131                 act_items = items;
    132         }
    133 
    134         async_data_read_finalize(data_callid, usage_pages_and_usages,
    135             act_items * 2 * sizeof(uint16_t));
    136 
    137         free(usage_pages_and_usages);
    138 
     143                act_length = len;
     144        }
     145
     146        async_data_read_finalize(data_callid, data, act_length);
     147
     148        free(data);
     149
     150        async_answer_1(callid, EOK, event_nr);
     151}
     152
     153void remote_usbhid_get_report_descriptor_length(ddf_fun_t *fun, void *iface,
     154    ipc_callid_t callid, ipc_call_t *call)
     155{
     156        usbhid_iface_t *hid_iface = (usbhid_iface_t *) iface;
     157
     158        if (!hid_iface->get_report_descriptor_length) {
     159                async_answer_0(callid, ENOTSUP);
     160                return;
     161        }
     162
     163        size_t len = hid_iface->get_report_descriptor_length(fun);
     164        async_answer_1(callid, EOK, (sysarg_t) len);
     165}
     166
     167void remote_usbhid_get_report_descriptor(ddf_fun_t *fun, void *iface,
     168    ipc_callid_t callid, ipc_call_t *call)
     169{
     170        usbhid_iface_t *hid_iface = (usbhid_iface_t *) iface;
     171
     172        if (!hid_iface->get_report_descriptor) {
     173                async_answer_0(callid, ENOTSUP);
     174                return;
     175        }
     176
     177        size_t len;
     178        ipc_callid_t data_callid;
     179        if (!async_data_read_receive(&data_callid, &len)) {
     180                async_answer_0(callid, EINVAL);
     181                return;
     182        }
     183
     184        if (len == 0) {
     185                async_answer_0(data_callid, EINVAL);
     186                async_answer_0(callid, EINVAL);
     187                return;
     188        }
     189
     190        uint8_t *descriptor = malloc(len);
     191        if (descriptor == NULL) {
     192                async_answer_0(data_callid, ENOMEM);
     193                async_answer_0(callid, ENOMEM);
     194                return;
     195        }
     196
     197        size_t act_len = 0;
     198        int rc = hid_iface->get_report_descriptor(fun, descriptor, len,
     199            &act_len);
     200        if (act_len > len) {
     201                rc = ELIMIT;
     202        }
     203        if (rc != EOK) {
     204                free(descriptor);
     205                async_answer_0(data_callid, rc);
     206                async_answer_0(callid, rc);
     207                return;
     208        }
     209
     210        async_data_read_finalize(data_callid, descriptor, act_len);
    139211        async_answer_0(callid, EOK);
    140 }
     212
     213        free(descriptor);
     214}
     215
     216
    141217
    142218/**
  • uspace/lib/drv/include/remote_pci.h

    re8f826b r400735e  
    3636#define LIBDRV_REMOTE_PCI_H_
    3737
    38 remote_iface_t remote_pci_iface;
     38extern remote_iface_t remote_pci_iface;
    3939
    4040#endif
  • uspace/lib/drv/include/remote_usb.h

    re8f826b r400735e  
    3636#define LIBDRV_REMOTE_USB_H_
    3737
    38 remote_iface_t remote_usb_iface;
     38extern remote_iface_t remote_usb_iface;
    3939
    4040#endif
  • uspace/lib/drv/include/remote_usbhc.h

    re8f826b r400735e  
    3636#define LIBDRV_REMOTE_USBHC_H_
    3737
    38 remote_iface_t remote_usbhc_iface;
     38extern remote_iface_t remote_usbhc_iface;
    3939
    4040#endif
  • uspace/lib/drv/include/remote_usbhid.h

    re8f826b r400735e  
    3636#define LIBDRV_REMOTE_USBHID_H_
    3737
    38 remote_iface_t remote_usbhid_iface;
     38extern remote_iface_t remote_usbhid_iface;
    3939
    4040#endif
  • uspace/lib/drv/include/usbhid_iface.h

    re8f826b r400735e  
    4545         * Parameters: none
    4646         * Answer:
    47          * - EOK (expected always as long as device support USB HID interface)
    48          * Parameters of the answer:
    49          * - number of items
     47         * - Size of one report in bytes.
    5048         */
    5149        IPC_M_USBHID_GET_EVENT_LENGTH,
     
    6361         * It is okay if the client requests less data. Extra data must
    6462         * be truncated by the driver.
     63         *
     64         * @todo Change this comment.
    6565         */
    66         IPC_M_USBHID_GET_EVENT
     66        IPC_M_USBHID_GET_EVENT,
     67       
     68        /** Get the size of the report descriptor from the HID device.
     69         *
     70         * Parameters:
     71         * - none
     72         * Answer:
     73         * - EOK - method is implemented (expected always)
     74         * Parameters of the answer:
     75         * - Size of the report in bytes.
     76         */
     77        IPC_M_USBHID_GET_REPORT_DESCRIPTOR_LENGTH,
     78       
     79        /** Get the report descriptor from the HID device.
     80         *
     81         * Parameters:
     82         * - none
     83         * The call is followed by data read expecting the descriptor itself.
     84         * Answer:
     85         * - EOK - report descriptor returned.
     86         */
     87        IPC_M_USBHID_GET_REPORT_DESCRIPTOR
    6788} usbhid_iface_funcs_t;
    6889
     
    7596         *
    7697         * @param[in] fun DDF function answering the request.
    77          * @return Number of events or error code.
     98         * @return Size of the event in bytes.
    7899         */
    79100        size_t (*get_event_length)(ddf_fun_t *fun);
     
    87108         * @return Error code.
    88109         */
    89         int (*get_event)(ddf_fun_t *fun, int32_t *buffer, size_t size,
    90             size_t *act_size, unsigned int flags);
     110        int (*get_event)(ddf_fun_t *fun, uint8_t *buffer, size_t size,
     111            size_t *act_size, int *event_nr, unsigned int flags);
     112       
     113        /** Get size of the report descriptor in bytes.
     114         *
     115         * @param[in] fun DDF function answering the request.
     116         * @return Size of the report descriptor in bytes.
     117         */
     118        size_t (*get_report_descriptor_length)(ddf_fun_t *fun);
     119       
     120        /** Get the report descriptor from the HID device.
     121         *
     122         * @param[in] fun DDF function answering the request.
     123         * @param[out] desc Buffer with the report descriptor.
     124         * @param[in] size Size of the allocated @p desc buffer.
     125         * @param[out] act_size Actual size of the report descriptor returned.
     126         * @return Error code.
     127         */
     128        int (*get_report_descriptor)(ddf_fun_t *fun, uint8_t *desc,
     129            size_t size, size_t *act_size);
    91130} usbhid_iface_t;
    92131
  • uspace/lib/usbdev/src/hub.c

    re8f826b r400735e  
    331331                goto leave_release_free_address;
    332332        }
     333       
     334        usb_hc_connection_close(&hc_conn);
    333335
    334336        /*
  • uspace/lib/usbhid/Makefile

    re8f826b r400735e  
    4141        src/hidpath.c \
    4242        src/hidreport.c \
     43        src/consumer.c \
    4344        src/hidreq.c
    4445
  • uspace/lib/usbhid/include/usb/hid/hid_report_items.h

    re8f826b r400735e  
    2727 */
    2828
    29 /** @addtogroup libusbhid
     29/** @addtogroup libusb
    3030 * @{
    3131 */
    3232/** @file
    33  * @brief USB HID parser.
    34  */
    35 #ifndef LIBUSBHID_HID_REPORT_ITEMS_H_
    36 #define LIBUSBHID_HID_REPORT_ITEMS_H_
     33 * @brief USB HID Report descriptor item tags.
     34 */
     35#ifndef LIBUSB_HID_REPORT_ITEMS_H_
     36#define LIBUSB_HID_REPORT_ITEMS_H_
    3737
    3838#include <stdint.h>
    3939
    40 /**
     40/*---------------------------------------------------------------------------*/
     41/*
    4142 * Item prefix
    4243 */
     44
     45/** Returns size of item data in bytes */
    4346#define USB_HID_ITEM_SIZE(data)         ((uint8_t)(data & 0x3))
     47
     48/** Returns item tag */
    4449#define USB_HID_ITEM_TAG(data)          ((uint8_t)((data & 0xF0) >> 4))
     50
     51/** Returns class of item tag */
    4552#define USB_HID_ITEM_TAG_CLASS(data)    ((uint8_t)((data & 0xC) >> 2))
     53
     54/** Returns if the item is the short item or long item. Long items are not
     55 * supported. */
    4656#define USB_HID_ITEM_IS_LONG(data)      (data == 0xFE)
    4757
    48 
    49 /**
     58/*---------------------------------------------------------------------------*/
     59/*
    5060 * Extended usage macros
    5161 */
     62
     63/** Recognizes if the given usage is extended (contains also usage page).  */
    5264#define USB_HID_IS_EXTENDED_USAGE(usage)        ((usage & 0xFFFF0000) != 0)
     65
     66/** Cuts usage page of the extended usage. */
    5367#define USB_HID_EXTENDED_USAGE_PAGE(usage)      ((usage & 0xFFFF0000) >> 16)
     68
     69/** Cuts usage of the extended usage */
    5470#define USB_HID_EXTENDED_USAGE(usage)           (usage & 0xFFFF)
    5571
    56 /**
     72/*---------------------------------------------------------------------------*/
     73/*
    5774 * Input/Output/Feature Item flags
    5875 */
    59 /** Constant (1) / Variable (0) */
     76/**
     77 * Indicates whether the item is data (0) or a constant (1) value. Data
     78 * indicates the item is defining report fields that contain modifiable device
     79 * data. Constant indicates the item is a static read-only field in a report
     80 * and cannot be modified (written) by the host.
     81 */
    6082#define USB_HID_ITEM_FLAG_CONSTANT(flags)       ((flags & 0x1) == 0x1)
    61 /** Variable (1) / Array (0) */
     83
     84/**
     85 * Indicates whether the item creates variable (1) or array (0) data fields in
     86 * reports.
     87 */
    6288#define USB_HID_ITEM_FLAG_VARIABLE(flags)       ((flags & 0x2) == 0x2)
    63 /** Absolute / Relative*/
     89
     90/**
     91 * Indicates whether the data is absolute (0) (based on a fixed origin) or
     92 * relative (1) (indicating the change in value from the last report). Mouse
     93 * devices usually provide relative data, while tablets usually provide
     94 * absolute data.
     95 */
    6496#define USB_HID_ITEM_FLAG_RELATIVE(flags)       ((flags & 0x4) == 0x4)
    65 /** Wrap / No Wrap */
     97
     98/** Indicates whether the data “rolls over” when reaching either the extreme
     99 * high or low value. For example, a dial that can spin freely 360 degrees
     100 * might output values from 0 to 10. If Wrap is indicated, the next value
     101 * reported after passing the 10 position in the increasing direction would be
     102 * 0.
     103 */
    66104#define USB_HID_ITEM_FLAG_WRAP(flags)           ((flags & 0x8) == 0x8)
     105
     106/**
     107 * Indicates whether the raw data from the device has been processed in some
     108 * way, and no longer represents a linear relationship between what is
     109 * measured and the data that is reported.
     110 */
    67111#define USB_HID_ITEM_FLAG_LINEAR(flags)         ((flags & 0x10) == 0x10)
     112
     113/**
     114 * Indicates whether the control has a preferred state to which it will return
     115 * when the user is not physically interacting with the control. Push buttons
     116 * (as opposed to toggle buttons) and self- centering joysticks are examples.
     117 */
    68118#define USB_HID_ITEM_FLAG_PREFERRED(flags)      ((flags & 0x20) == 0x20)
     119
     120/**
     121 * Indicates whether the control has a state in which it is not sending
     122 * meaningful data. One possible use of the null state is for controls that
     123 * require the user to physically interact with the control in order for it to
     124 * report useful data.
     125 */
    69126#define USB_HID_ITEM_FLAG_POSITION(flags)       ((flags & 0x40) == 0x40)
     127
     128/**
     129 * Indicates whether the Feature or Output control's value should be changed
     130 * by the host or not.  Volatile output can change with or without host
     131 * interaction. To avoid synchronization problems, volatile controls should be
     132 * relative whenever possible.
     133 */
    70134#define USB_HID_ITEM_FLAG_VOLATILE(flags)       ((flags & 0x80) == 0x80)
     135
     136/**
     137 * Indicates that the control emits a fixed-size stream of bytes. The contents
     138 * of the data field are determined by the application. The contents of the
     139 * buffer are not interpreted as a single numeric quantity. Report data
     140 * defined by a Buffered Bytes item must be aligned on an 8-bit boundary.
     141 */
    71142#define USB_HID_ITEM_FLAG_BUFFERED(flags)       ((flags & 0x100) == 0x100)
    72143
     144/*---------------------------------------------------------------------------*/
     145
    73146/* MAIN ITEMS */
    74 #define USB_HID_TAG_CLASS_MAIN                          0x0
    75 #define USB_HID_REPORT_TAG_INPUT                        0x8
    76 #define USB_HID_REPORT_TAG_OUTPUT                       0x9
    77 #define USB_HID_REPORT_TAG_FEATURE                      0xB
     147
     148/**
     149 * Main items are used to either define or group certain types of data fields
     150 * within a Report descriptor.
     151 */
     152#define USB_HID_TAG_CLASS_MAIN                  0x0
     153
     154/**
     155 * An Input item describes information about the data provided by one or more
     156 * physical controls. An application can use this information to interpret the
     157 * data provided by the device. All data fields defined in a single item share
     158 * an identical data format.
     159 */
     160#define USB_HID_REPORT_TAG_INPUT                0x8
     161
     162/**
     163 * The Output item is used to define an output data field in a report. This
     164 * item is similar to an Input item except it describes data sent to the
     165 * device—for example, LED states.
     166 */
     167#define USB_HID_REPORT_TAG_OUTPUT               0x9
     168
     169/**
     170 * Feature items describe device configuration information that can be sent to
     171 * the device.
     172 */
     173#define USB_HID_REPORT_TAG_FEATURE              0xB
     174
     175/**
     176 * A Collection item identifies a relationship between two or more data
     177 * (Input, Output, or Feature.)
     178 */
    78179#define USB_HID_REPORT_TAG_COLLECTION           0xA
     180
     181/**
     182 * While the Collection item opens a collection of data, the End Collection
     183 * item closes a collection.
     184 */
    79185#define USB_HID_REPORT_TAG_END_COLLECTION       0xC
    80186
     187/*---------------------------------------------------------------------------*/
     188
    81189/* GLOBAL ITEMS */
    82 #define USB_HID_TAG_CLASS_GLOBAL                        0x1
     190
     191/**
     192 * Global items describe rather than define data from a control.
     193 */
     194#define USB_HID_TAG_CLASS_GLOBAL                0x1
     195
     196/**
     197 * Unsigned integer specifying the current Usage Page. Since a usage are 32
     198 * bit values, Usage Page items can be used to conserve space in a report
     199 * descriptor by setting the high order 16 bits of a subsequent usages. Any
     200 * usage that follows which is defines 16 bits or less is interpreted as a
     201 * Usage ID and concatenated with the Usage Page to form a 32 bit Usage.
     202 */
    83203#define USB_HID_REPORT_TAG_USAGE_PAGE           0x0
     204
     205/**
     206 * Extent value in logical units. This is the minimum value that a variable
     207 * or array item will report. For example, a mouse reporting x position values
     208 * from 0 to 128 would have a Logical Minimum of 0 and a Logical Maximum of
     209 * 128.
     210 */
    84211#define USB_HID_REPORT_TAG_LOGICAL_MINIMUM      0x1
     212
     213/**
     214 * Extent value in logical units. This is the maximum value that a variable
     215 * or array item will report.
     216 */
    85217#define USB_HID_REPORT_TAG_LOGICAL_MAXIMUM      0x2
    86 #define USB_HID_REPORT_TAG_PHYSICAL_MINIMUM 0x3
    87 #define USB_HID_REPORT_TAG_PHYSICAL_MAXIMUM 0x4
     218
     219/**
     220 * Minimum value for the physical extent of a variable item. This represents
     221 * the Logical Minimum with units applied to it.
     222 */
     223#define USB_HID_REPORT_TAG_PHYSICAL_MINIMUM     0x3
     224
     225/**
     226 * Maximum value for the physical extent of a variable item.
     227 */
     228#define USB_HID_REPORT_TAG_PHYSICAL_MAXIMUM     0x4
     229
     230/**
     231 * Value of the unit exponent in base 10. See the table later in this section
     232 * for more information.
     233 */
    88234#define USB_HID_REPORT_TAG_UNIT_EXPONENT        0x5
    89 #define USB_HID_REPORT_TAG_UNIT                         0x6
     235
     236/**
     237 * Unit values.
     238 */
     239#define USB_HID_REPORT_TAG_UNIT                 0x6
     240
     241/**
     242 * Unsigned integer specifying the size of the report fields in bits. This
     243 * allows the parser to build an item map for the report handler to use.
     244 */
    90245#define USB_HID_REPORT_TAG_REPORT_SIZE          0x7
     246
     247/**
     248 * Unsigned value that specifies the Report ID. If a Report ID tag is used
     249 * anywhere in Report descriptor, all data reports for the device are preceded
     250 * by a single byte ID field. All items succeeding the first Report ID tag but
     251 * preceding a second Report ID tag are included in a report prefixed by a
     252 * 1-byte ID. All items succeeding the second but preceding a third Report ID
     253 * tag are included in a second report prefixed by a second ID, and so on.
     254 */
    91255#define USB_HID_REPORT_TAG_REPORT_ID            0x8
     256
     257/**
     258 * Unsigned integer specifying the number of data fields for the item;
     259 * determines how many fields are included in the report for this particular
     260 * item (and consequently how many bits are added to the report).
     261 */
    92262#define USB_HID_REPORT_TAG_REPORT_COUNT         0x9
    93 #define USB_HID_REPORT_TAG_PUSH                         0xA
    94 #define USB_HID_REPORT_TAG_POP                          0xB
    95 
     263
     264/**
     265 * Places a copy of the global item state table on the stack.
     266 */
     267#define USB_HID_REPORT_TAG_PUSH                 0xA
     268
     269/**
     270 * Replaces the item state table with the top structure from the stack.
     271 */
     272#define USB_HID_REPORT_TAG_POP                  0xB
     273
     274/*---------------------------------------------------------------------------*/
    96275
    97276/* LOCAL ITEMS */
    98 #define USB_HID_TAG_CLASS_LOCAL                                 0x2
    99 #define USB_HID_REPORT_TAG_USAGE                                0x0
    100 #define USB_HID_REPORT_TAG_USAGE_MINIMUM                0x1
    101 #define USB_HID_REPORT_TAG_USAGE_MAXIMUM                0x2
    102 #define USB_HID_REPORT_TAG_DESIGNATOR_INDEX             0x3
     277
     278/**
     279 * Local item tags define characteristics of controls. These items do not
     280 * carry over to the next Main item. If a Main item defines more than one
     281 * control, it may be preceded by several similar Local item tags. For
     282 * example, an Input item may have several Usage tags associated with it, one
     283 * for each control.
     284 */
     285#define USB_HID_TAG_CLASS_LOCAL                 0x2
     286
     287/**
     288 * Usage index for an item usage; represents a suggested usage for the item or
     289 * collection. In the case where an item represents multiple controls, a Usage
     290 * tag may suggest a usage for every variable or element in an array.
     291 */
     292#define USB_HID_REPORT_TAG_USAGE                0x0
     293
     294/**
     295 * Defines the starting usage associated with an array or bitmap.
     296 */
     297#define USB_HID_REPORT_TAG_USAGE_MINIMUM        0x1
     298
     299/**
     300 * Defines the ending usage associated with an array or bitmap.
     301 */
     302#define USB_HID_REPORT_TAG_USAGE_MAXIMUM        0x2
     303
     304/**
     305 * Determines the body part used for a control. Index points to a designator
     306 * in the Physical descriptor.
     307 */
     308#define USB_HID_REPORT_TAG_DESIGNATOR_INDEX     0x3
     309
     310/**
     311 * Defines the index of the starting designator associated with an array or
     312 * bitmap.
     313 */
    103314#define USB_HID_REPORT_TAG_DESIGNATOR_MINIMUM   0x4
     315
     316/**
     317 * Defines the index of the ending designator associated with an array or
     318 * bitmap.
     319 */
    104320#define USB_HID_REPORT_TAG_DESIGNATOR_MAXIMUM   0x5
    105 #define USB_HID_REPORT_TAG_STRING_INDEX                 0x7
    106 #define USB_HID_REPORT_TAG_STRING_MINIMUM               0x8
    107 #define USB_HID_REPORT_TAG_STRING_MAXIMUM               0x9
    108 #define USB_HID_REPORT_TAG_DELIMITER                    0xA
     321
     322/**
     323 * String index for a String descriptor; allows a string to be associated with
     324 * a particular item or control.
     325 */
     326#define USB_HID_REPORT_TAG_STRING_INDEX         0x7
     327
     328/**
     329 * Specifies the first string index when assigning a group of sequential
     330 * strings to controls in an array or bitmap.
     331 */
     332#define USB_HID_REPORT_TAG_STRING_MINIMUM       0x8
     333
     334/**
     335 * Specifies the last string index when assigning a group of sequential
     336 * strings to controls in an array or bitmap.
     337 */
     338#define USB_HID_REPORT_TAG_STRING_MAXIMUM       0x9
     339
     340/**
     341 * Defines the beginning or end of a set of local items (1 = open set, 0 =
     342 * close set).
     343 *
     344 * Usages other than the first (most preferred) usage defined are not
     345 * accessible by system software.
     346 */
     347#define USB_HID_REPORT_TAG_DELIMITER            0xA
     348
     349/*---------------------------------------------------------------------------*/
    109350
    110351#endif
  • uspace/lib/usbhid/include/usb/hid/hiddescriptor.h

    re8f826b r400735e  
    2727 */
    2828
    29 /** @addtogroup libusbhid
     29/** @addtogroup libusb
    3030 * @{
    3131 */
     
    3333 * USB HID report descriptor and report data parser
    3434 */
    35 #ifndef LIBUSBHID_HIDDESCRIPTOR_H_
    36 #define LIBUSBHID_HIDDESCRIPTOR_H_
     35#ifndef LIBUSB_HIDDESCRIPTOR_H_
     36#define LIBUSB_HIDDESCRIPTOR_H_
    3737
    3838#include <stdint.h>
     
    4242#include <usb/hid/hidtypes.h>
    4343
     44int usb_hid_parse_report_descriptor(usb_hid_report_t *report,
     45                const uint8_t *data, size_t size);
    4446
    45 /*
    46  * Descriptor parser functions
    47  */
    48 
    49 /** */
    50 int usb_hid_parse_report_descriptor(usb_hid_report_t *report,
    51                                     const uint8_t *data, size_t size);
    52 
    53 /** */
    5447void usb_hid_free_report(usb_hid_report_t *report);
    5548
    56 /** */
    5749void usb_hid_descriptor_print(usb_hid_report_t *report);
    5850
     51int usb_hid_report_init(usb_hid_report_t *report);
    5952
    60 int usb_hid_report_init(usb_hid_report_t *report);
    61 int usb_hid_report_append_fields(usb_hid_report_t *report,
    62                                  usb_hid_report_item_t *report_item);
     53int usb_hid_report_append_fields(usb_hid_report_t *report,
     54                usb_hid_report_item_t *report_item);
    6355
    64 usb_hid_report_description_t * usb_hid_report_find_description(const usb_hid_report_t *report, uint8_t report_id, usb_hid_report_type_t type);
    65 int usb_hid_report_parse_tag(uint8_t tag, uint8_t class, const uint8_t *data, size_t item_size,
    66                              usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path);
    67 int usb_hid_report_parse_main_tag(uint8_t tag, const uint8_t *data, size_t item_size,
    68                              usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path);
    69 int usb_hid_report_parse_global_tag(uint8_t tag, const uint8_t *data, size_t item_size,
    70                              usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path);
    71 int usb_hid_report_parse_local_tag(uint8_t tag, const uint8_t *data, size_t item_size,
    72                              usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path);
     56usb_hid_report_description_t * usb_hid_report_find_description(
     57                const usb_hid_report_t *report, uint8_t report_id,
     58                usb_hid_report_type_t type);
     59
     60int usb_hid_report_parse_tag(uint8_t tag, uint8_t class, const uint8_t *data,
     61                size_t item_size, usb_hid_report_item_t *report_item,
     62                usb_hid_report_path_t *usage_path);
     63
     64int usb_hid_report_parse_main_tag(uint8_t tag, const uint8_t *data,
     65                size_t item_size, usb_hid_report_item_t *report_item,
     66                usb_hid_report_path_t *usage_path);
     67
     68int usb_hid_report_parse_global_tag(uint8_t tag, const uint8_t *data,
     69                size_t item_size, usb_hid_report_item_t *report_item,
     70                usb_hid_report_path_t *usage_path);
     71
     72int usb_hid_report_parse_local_tag(uint8_t tag, const uint8_t *data,
     73                size_t item_size, usb_hid_report_item_t *report_item,
     74                usb_hid_report_path_t *usage_path);
    7375
    7476void usb_hid_descriptor_print_list(link_t *head);
     77
    7578void usb_hid_report_reset_local_items(usb_hid_report_item_t *report_item);
     79
    7680void usb_hid_free_report_list(link_t *head);
    77 usb_hid_report_item_t *usb_hid_report_item_clone(const usb_hid_report_item_t *item);
     81
     82usb_hid_report_item_t *usb_hid_report_item_clone(
     83                const usb_hid_report_item_t *item);
     84
    7885uint32_t usb_hid_report_tag_data_uint32(const uint8_t *data, size_t size);
    7986
    80 usb_hid_report_path_t *usb_hid_report_path_try_insert(usb_hid_report_t *report, usb_hid_report_path_t *cmp_path);
     87usb_hid_report_path_t *usb_hid_report_path_try_insert(usb_hid_report_t*report,
     88                usb_hid_report_path_t *cmp_path);
     89
     90
    8191#endif
    8292/**
  • uspace/lib/usbhid/include/usb/hid/hidparser.h

    re8f826b r400735e  
    4747 * Input report parser functions
    4848 */
    49 /** */
    50 int usb_hid_parse_report(const usb_hid_report_t *report, const uint8_t *data,
    51                          size_t size, uint8_t *report_id);
     49int usb_hid_parse_report(const usb_hid_report_t *report, const uint8_t *data,
     50                size_t size, uint8_t *report_id);
    5251
    5352/*
    5453 * Output report parser functions
    5554 */
    56 /** Allocates output report buffer*/
    5755uint8_t *usb_hid_report_output(usb_hid_report_t *report, size_t *size,
    58                                uint8_t report_id);
     56                uint8_t report_id);
    5957
    60 /** Frees output report buffer*/
    6158void usb_hid_report_output_free(uint8_t *output);
    6259
    63 /** Returns size of report in items */
    64 size_t usb_hid_report_size(usb_hid_report_t *report, uint8_t report_id,
    65                            usb_hid_report_type_t type);
     60size_t usb_hid_report_size(usb_hid_report_t *report, uint8_t report_id,
     61                usb_hid_report_type_t type);
    6662
    67 /** Makes the output report buffer by translated given data */
    68 int usb_hid_report_output_translate(usb_hid_report_t *report, uint8_t report_id,
    69                                     uint8_t *buffer, size_t size);
     63size_t usb_hid_report_byte_size(usb_hid_report_t *report, uint8_t report_id,
     64                usb_hid_report_type_t type);
    7065
    71 /** */
    72 usb_hid_report_field_t *usb_hid_report_get_sibling(usb_hid_report_t *report,
    73                                                    usb_hid_report_field_t *field,
    74                                                    usb_hid_report_path_t *path,
    75                                                    int flags,
    76                                                    usb_hid_report_type_t type);
    7766
    78 /** */
    79 uint8_t usb_hid_report_get_report_id(usb_hid_report_t *report,
    80                                      uint8_t report_id,
    81                                      usb_hid_report_type_t type);
     67int usb_hid_report_output_translate(usb_hid_report_t *report,
     68                uint8_t report_id, uint8_t *buffer, size_t size);
     69
     70
     71/*
     72 * Report descriptor structure observing functions
     73 */
     74usb_hid_report_field_t *usb_hid_report_get_sibling(usb_hid_report_t *report,
     75                usb_hid_report_field_t *field, usb_hid_report_path_t *path,
     76                int flags, usb_hid_report_type_t type);
     77
     78uint8_t usb_hid_get_next_report_id(usb_hid_report_t *report,
     79                uint8_t report_id, usb_hid_report_type_t type);
    8280
    8381#endif
  • uspace/lib/usbhid/include/usb/hid/hidpath.h

    re8f826b r400735e  
    2727 */
    2828
    29 /** @addtogroup libusbhid
     29/** @addtogroup libusb
    3030 * @{
    3131 */
     
    3333 * USB HID report descriptor and report data parser
    3434 */
    35 #ifndef LIBUSBHID_HIDPATH_H_
    36 #define LIBUSBHID_HIDPATH_H_
     35#ifndef LIBUSB_HIDPATH_H_
     36#define LIBUSB_HIDPATH_H_
    3737
    3838#include <usb/hid/hidparser.h>
     
    4040#include <adt/list.h>
    4141
     42
     43/*---------------------------------------------------------------------------*/
     44/*
     45 * Flags of usage paths comparison modes.
     46 *
     47 */
     48/** Wanted usage path must be exactly the same as the searched one.  This
     49 * option cannot be combined with the others.
     50 */
     51#define USB_HID_PATH_COMPARE_STRICT             0
     52
    4253/**
    43  * Description of path of usage pages and usages in report descriptor
     54 * Wanted usage path must be the suffix in the searched one.
    4455 */
    45 /** Wanted usage path must be exactly the same as the searched one */
    46 #define USB_HID_PATH_COMPARE_STRICT             0
    47 /** Wanted usage path must be the suffix in the searched one */
    4856#define USB_HID_PATH_COMPARE_END                1
    49 /** */
     57
     58/**
     59 * Only usage page are compared along the usage path.  This option can be
     60 * combined with others.
     61 */
    5062#define USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY    2
    51 /** Searched usage page must be prefix of the other one */
     63
     64/**
     65 * Searched usage page must be prefix of the other one.
     66 */
    5267#define USB_HID_PATH_COMPARE_BEGIN              4
    53 /** Searched couple of usage page and usage can be anywhere in usage path */
     68
     69/**
     70 * Searched couple of usage page and usage can be anywhere in usage path.
     71 * This option is deprecated.
     72 */
    5473#define USB_HID_PATH_COMPARE_ANYWHERE           8
    5574
    56 
    57 /** Collection usage path structure */
     75/*----------------------------------------------------------------------------*/
     76/**
     77 * Item of usage path structure. Last item of linked list describes one item
     78 * in report, the others describe superior Collection tags. Usage and Usage
     79 * page of report item can be changed due to data in report.
     80 */
    5881typedef struct {
    59         /** */
     82        /** Usage page of report item. Zero when usage page can be changed. */
    6083        uint32_t usage_page;
    61         /** */ 
     84        /** Usage of report item. Zero when usage can be changed. */   
    6285        uint32_t usage;
    6386
     87        /** Attribute of Collection tag in report descriptor*/
    6488        uint8_t flags;
    65         /** */
     89
     90        /** Linked list structure*/
    6691        link_t link;
    6792} usb_hid_report_usage_path_t;
    6893
    69 /** */
     94
     95/*---------------------------------------------------------------------------*/
     96/**
     97 * USB HID usage path structure.
     98 * */
    7099typedef struct {
    71         /** */ 
     100        /** Length of usage path */     
    72101        int depth;     
     102
     103        /** Report id. Zero is reserved and means that report id is not used.
     104         * */
    73105        uint8_t report_id;
    74106       
    75         /** */ 
     107        /** Linked list structure. */   
    76108        link_t link; /* list */
    77109
    78         link_t head; /* head of list of usage paths */
     110        /** Head of the list of usage path items. */
     111        link_t head;
    79112
    80113} usb_hid_report_path_t;
    81114
    82 /** */
     115/*---------------------------------------------------------------------------*/
    83116usb_hid_report_path_t *usb_hid_report_path(void);
    84117
    85 /** */
    86118void usb_hid_report_path_free(usb_hid_report_path_t *path);
    87119
    88 /** */
    89 int usb_hid_report_path_set_report_id(usb_hid_report_path_t *usage_path,
    90                                       uint8_t report_id);
     120int usb_hid_report_path_set_report_id(usb_hid_report_path_t *usage_path,
     121                uint8_t report_id);
    91122
    92 /** */
    93123int usb_hid_report_path_append_item(usb_hid_report_path_t *usage_path,
    94                                     int32_t usage_page, int32_t usage);
     124                int32_t usage_page, int32_t usage);
    95125
    96 /** */
    97126void usb_hid_report_remove_last_item(usb_hid_report_path_t *usage_path);
    98127
    99 /** */
    100128void usb_hid_report_null_last_item(usb_hid_report_path_t *usage_path);
    101129
    102 /** */
    103130void usb_hid_report_set_last_item(usb_hid_report_path_t *usage_path,
    104                                   int32_t tag, int32_t data);
     131                int32_t tag, int32_t data);
    105132
    106 /** */
    107 int usb_hid_report_compare_usage_path(usb_hid_report_path_t *report_path,
    108                                       usb_hid_report_path_t *path, int flags);
     133int usb_hid_report_compare_usage_path(usb_hid_report_path_t *report_path,
     134                usb_hid_report_path_t *path, int flags);
    109135
    110 /** */
    111 usb_hid_report_path_t *usb_hid_report_path_clone(usb_hid_report_path_t *usage_path);
     136usb_hid_report_path_t *usb_hid_report_path_clone(
     137                usb_hid_report_path_t *usage_path);
    112138
    113139void usb_hid_print_usage_path(usb_hid_report_path_t *path);
  • uspace/lib/usbhid/include/usb/hid/hidreport.h

    re8f826b r400735e  
    4444 * report parser.
    4545 *
    46  * \param dev USB device representing a HID device.
    47  * \param parser HID Report parser.
     46 * \param[in] dev USB device representing a HID device.
     47 * \param[in/out] parser HID Report parser.
     48 * \param[out] report_desc Place to save report descriptor into.
     49 * \param[out] report_size
    4850 *
    4951 * \retval EOK if successful.
     
    5759 */
    5860int usb_hid_process_report_descriptor(usb_device_t *dev,
    59     usb_hid_report_t *report);
     61    usb_hid_report_t *report, uint8_t **report_desc, size_t *report_size);
    6062
    6163#endif /* LIBUSB_HIDREPORT_H_ */
  • uspace/lib/usbhid/include/usb/hid/hidtypes.h

    re8f826b r400735e  
    2727 */
    2828
    29 /** @addtogroup libusbhid
     29/** @addtogroup libusb
    3030 * @{
    3131 */
    3232/** @file
    33  * USB HID report descriptor and report data parser
    34  */
    35 #ifndef LIBUSBHID_HIDTYPES_H_
    36 #define LIBUSBHID_HIDTYPES_H_
     33 * Basic data structures for USB HID Report descriptor and report parser.
     34 */
     35#ifndef LIBUSB_HIDTYPES_H_
     36#define LIBUSB_HIDTYPES_H_
    3737
    3838#include <stdint.h>
    3939#include <adt/list.h>
    4040
     41/*---------------------------------------------------------------------------*/
     42
     43/**
     44 * Maximum amount of specified usages for one report item
     45 */
    4146#define USB_HID_MAX_USAGES      0xffff
    4247
    43 #define USB_HID_UINT32_TO_INT32(x, size)        ((((x) & (1 << ((size) - 1))) != 0) ? -(~(x - 1) & ((1 << size) - 1)) : (x)) //(-(~((x) - 1)))
    44 #define USB_HID_INT32_TO_UINT32(x, size)        (((x) < 0 ) ? ((1 << (size)) + (x)) : (x))
    45 
    46 
     48/**
     49 * Converts integer from unsigned two's complement format format to signed
     50 * one.
     51 *
     52 * @param x Number to convert
     53 * @param size Length of the unsigned number in bites
     54 * @return signed int
     55 */
     56#define USB_HID_UINT32_TO_INT32(x, size)        \
     57        ((((x) & (1 << ((size) - 1))) != 0) ?   \
     58         -(~((x) - 1) & ((1 << size) - 1)) : (x))
     59
     60/**
     61 * Convert integer from signed format to unsigned. If number is negative the
     62 * two's complement format is used.
     63 *
     64 * @param x Number to convert
     65 * @param size Length of result number in bites
     66 * @return unsigned int
     67 */
     68#define USB_HID_INT32_TO_UINT32(x, size)        \
     69        (((x) < 0 ) ? ((1 << (size)) + (x)) : (x))
     70
     71/*---------------------------------------------------------------------------*/
     72
     73/**
     74 * Enum of report types
     75 */
    4776typedef enum {
     77        /** Input report. Data are sent from device to system */
    4878        USB_HID_REPORT_TYPE_INPUT = 1,
     79
     80        /** Output report. Data are sent from system to device */
    4981        USB_HID_REPORT_TYPE_OUTPUT = 2,
     82
     83        /** Feature report. Describes device configuration information that
     84         * can be sent to the device */
    5085        USB_HID_REPORT_TYPE_FEATURE = 3
    5186} usb_hid_report_type_t;
    5287
    53 
     88/*---------------------------------------------------------------------------*/
     89
     90/**
     91 * Description of all reports described in one report descriptor.
     92 */
    5493typedef struct {
    55         /** */
     94        /** Count of available reports. */
    5695        int report_count;
    57         link_t reports;         /** list of usb_hid_report_description_t */
    58 
     96
     97        /** Head of linked list of description of reports. */
     98        link_t reports;
     99
     100        /** Head of linked list of all used usage/collection paths. */
    59101        link_t collection_paths;
     102
     103        /** Length of list of usage paths. */
    60104        int collection_paths_count;
    61105
     106        /** Flag whether report ids are used. */
    62107        int use_report_ids;
     108
     109        /** Report id of last parsed report. */
    63110        uint8_t last_report_id;
    64111       
    65112} usb_hid_report_t;
    66 
     113/*---------------------------------------------------------------------------*/
     114
     115/**
     116 * Description of one concrete report
     117 */
    67118typedef struct {
     119        /** Report id. Zero when no report id is used. */
    68120        uint8_t report_id;
     121
     122        /** Type of report */
    69123        usb_hid_report_type_t type;
    70124
     125        /** Bit length of the report */
    71126        size_t bit_length;
     127
     128        /** Number of items in report */
    72129        size_t item_length;
    73130       
    74         link_t report_items;    /** list of report items (fields) */
    75 
     131        /** Linked list of report items in report */
     132        link_t report_items;
     133
     134        /** Linked list of descriptions. */
    76135        link_t link;
    77136} usb_hid_report_description_t;
    78 
     137/*---------------------------------------------------------------------------*/
     138
     139/**
     140 * Description of one field/item in report
     141 */
    79142typedef struct {
    80 
     143        /** Bit offset of the field */
    81144        int offset;
     145
     146        /** Bit size of the field */
    82147        size_t size;
    83148
     149        /** Usage page. Zero when usage page can be changed. */
    84150        uint16_t usage_page;
     151
     152        /** Usage. Zero when usage can be changed. */
    85153        uint16_t usage;
    86154
     155        /** Item's attributes */
    87156        uint8_t item_flags;
     157
     158        /** Usage/Collection path of the field. */
    88159        usb_hid_report_path_t *collection_path;
    89160
     161        /**
     162         * The lowest valid logical value (value with the device operates)
     163         */
    90164        int32_t logical_minimum;
     165
     166        /**
     167         * The greatest valid logical value
     168         */
    91169        int32_t logical_maximum;
     170
     171        /**
     172         * The lowest valid physical value (value with the system operates)
     173         */
    92174        int32_t physical_minimum;
     175
     176        /** The greatest valid physical value */
    93177        int32_t physical_maximum;
     178
     179        /** The lowest valid usage index */
    94180        int32_t usage_minimum;
     181
     182        /** The greatest valid usage index */
    95183        int32_t usage_maximum;
     184       
     185        /** Unit of the value */
    96186        uint32_t unit;
     187
     188        /** Unit exponent */
    97189        uint32_t unit_exponent;
    98190
     191        /** Array of possible usages */
    99192        uint32_t *usages;
     193
     194        /** Size of the array of usages */
    100195        size_t usages_count;
    101196
     197        /** Parsed value */
    102198        int32_t value;
    103199
     200        /** List to another report items */
    104201        link_t link;
    105202} usb_hid_report_field_t;
    106203
    107 
    108 
    109 /**
    110  * state table
     204/*---------------------------------------------------------------------------*/
     205
     206/**
     207 * State table for report descriptor parsing
    111208 */
    112209typedef struct {
     
    114211        int32_t id;
    115212       
    116         /** */
     213        /** Extended usage page */
    117214        uint16_t extended_usage_page;
     215
     216        /** Array of usages specified for this item */
    118217        uint32_t usages[USB_HID_MAX_USAGES];
     218       
     219        /** Length of usages array */
    119220        int usages_count;
    120221
    121         /** */
     222        /** Usage page*/
    122223        uint32_t usage_page;
    123224
    124         /** */ 
     225        /** Minimum valid usage index */       
    125226        int32_t usage_minimum;
    126         /** */ 
     227       
     228        /** Maximum valid usage index */       
    127229        int32_t usage_maximum;
    128         /** */ 
     230       
     231        /** Minimum valid logical value */     
    129232        int32_t logical_minimum;
    130         /** */ 
     233       
     234        /** Maximum valid logical value */     
    131235        int32_t logical_maximum;
    132         /** */ 
     236
     237        /** Length of the items in bits*/       
    133238        int32_t size;
    134         /** */ 
     239
     240        /** COunt of items*/   
    135241        int32_t count;
    136         /** */ 
     242
     243        /**  Bit offset of the item in report */       
    137244        size_t offset;
    138         /** */ 
     245
     246        /** Unit exponent */   
    139247        int32_t unit_exponent;
    140         /** */ 
     248        /** Unit of the value */       
    141249        int32_t unit;
    142250
    143         /** */
     251        /** String index */
    144252        uint32_t string_index;
    145         /** */ 
     253
     254        /** Minimum valid string index */       
    146255        uint32_t string_minimum;
    147         /** */ 
     256
     257        /** Maximum valid string index */       
    148258        uint32_t string_maximum;
    149         /** */ 
     259
     260        /** The designator index */     
    150261        uint32_t designator_index;
    151         /** */ 
     262
     263        /** Minimum valid designator value*/   
    152264        uint32_t designator_minimum;
    153         /** */ 
     265
     266        /** Maximum valid designator value*/   
    154267        uint32_t designator_maximum;
    155         /** */ 
     268
     269        /** Minimal valid physical value*/     
    156270        int32_t physical_minimum;
    157         /** */ 
     271
     272        /** Maximal valid physical value */     
    158273        int32_t physical_maximum;
    159274
    160         /** */ 
     275        /** Items attributes*/ 
    161276        uint8_t item_flags;
    162277
     278        /** Report type */
    163279        usb_hid_report_type_t type;
    164280
    165281        /** current collection path*/   
    166282        usb_hid_report_path_t *usage_path;
    167         /** */ 
     283
     284        /** Unused*/   
    168285        link_t link;
    169286
    170287        int in_delimiter;
    171288} usb_hid_report_item_t;
    172 
    173 /** HID parser callbacks for IN items. */
    174 typedef struct {
    175         /** Callback for keyboard.
    176          *
    177          * @param key_codes Array of pressed key (including modifiers).
    178          * @param count Length of @p key_codes.
    179          * @param arg Custom argument.
    180          */
    181         void (*keyboard)(const uint8_t *key_codes, size_t count, const uint8_t report_id, void *arg);
    182 } usb_hid_report_in_callbacks_t;
    183 
    184 
     289/*---------------------------------------------------------------------------*/
     290/**
     291 * Enum of the keyboard modifiers
     292 */
    185293typedef enum {
    186294        USB_HID_MOD_LCTRL = 0x01,
     
    206314        USB_HID_MOD_RGUI
    207315};
     316/*---------------------------------------------------------------------------*/
     317
    208318
    209319#endif
  • uspace/lib/usbhid/include/usb/hid/iface.h

    re8f826b r400735e  
    3838#include <sys/types.h>
    3939
    40 int usbhid_dev_get_event_length(int);
    41 int usbhid_dev_get_event(int, uint16_t *, uint16_t *, size_t, size_t *,
     40int usbhid_dev_get_event_length(int, size_t *);
     41int usbhid_dev_get_event(int, uint8_t *, size_t, size_t *, int *,
    4242    unsigned int);
     43int usbhid_dev_get_report_descriptor_length(int, size_t *);
     44int usbhid_dev_get_report_descriptor(int, uint8_t *, size_t, size_t *);
    4345
    4446#endif
  • uspace/lib/usbhid/include/usb/hid/usages/consumer.h

    re8f826b r400735e  
    11/*
    2  * Copyright (c) 2011 Jan Vesely
     2 * Copyright (c) 2011 Lubos Slovak
    33 * All rights reserved.
    44 *
     
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
    28 /** @addtogroup drvusbuhcihc
     28
     29/** @addtogroup libusbhid
    2930 * @{
    3031 */
    3132/** @file
    32  * @brief UHCI driver
     33 * USB multimedia key usage to string mapping.
    3334 */
    34 #ifndef DRV_UHCI_UTILS_SLAB_H
    35 #define DRV_UHCI_UTILS_SLAB_H
    3635
    37 #include <bool.h>
     36#ifndef LIBUSBHID_CONSUMER_H_
     37#define LIBUSBHID_CONSUMER_H_
    3838
    39 #define SLAB_ELEMENT_SIZE 1024
     39const char *usbhid_multimedia_usage_to_str(int usage);
    4040
    41 void * slab_malloc_g(void);
     41#endif /* LIBUSBHID_CONSUMER_H_ */
    4242
    43 void slab_free_g(void *addr);
    44 
    45 bool slab_in_range_g(void *addr);
    46 
    47 #endif
    4843/**
    4944 * @}
  • uspace/lib/usbhid/src/hiddescriptor.c

    re8f826b r400735e  
    4141#include <assert.h>
    4242
    43 
     43/*---------------------------------------------------------------------------*/
     44/*
     45 * Constants defining current parsing mode for correct parsing of the set of
     46 * local tags (usage) enclosed in delimter tags.
     47 */
     48/**
     49 * Second delimiter tag was read. The set of local items (usage) ended.
     50 */
    4451#define OUTSIDE_DELIMITER_SET   0
     52
     53/**
     54 * First delimiter tag was read. The set of local items (usage) started.
     55 */
    4556#define START_DELIMITER_SET     1
     57
     58/**
     59 * Parser is in the set of local items.
     60 */
    4661#define INSIDE_DELIMITER_SET    2
     62
     63/*---------------------------------------------------------------------------*/
    4764       
    4865/** The new report item flag. Used to determine when the item is completly
     
    6178#define USB_HID_UNKNOWN_TAG             -99
    6279
    63 usb_hid_report_path_t *usb_hid_report_path_try_insert(usb_hid_report_t *report, usb_hid_report_path_t *cmp_path)
    64 {
    65         /* find or append current collection path to the list */
    66         //link_t *path_it = report->collection_paths.next;
     80/*---------------------------------------------------------------------------*/
     81/**
     82 * Checks if given collection path is already present in report structure and
     83 * inserts it if not.
     84 *
     85 * @param report Report structure
     86 * @param cmp_path The collection path
     87 * @return Pointer to the result collection path in report structure.
     88 * @retval NULL If some error occurs
     89 */
     90usb_hid_report_path_t *usb_hid_report_path_try_insert(
     91                usb_hid_report_t *report, usb_hid_report_path_t *cmp_path) {
     92       
    6793        link_t *path_it = report->collection_paths.prev->next;
    6894        usb_hid_report_path_t *path = NULL;
    6995       
     96        if((report == NULL) || (cmp_path == NULL)) {
     97                return NULL;
     98        }
    7099       
    71100        while(path_it != &report->collection_paths) {
    72                 path = list_get_instance(path_it, usb_hid_report_path_t, link);
    73                
    74                 if(usb_hid_report_compare_usage_path(path, cmp_path, USB_HID_PATH_COMPARE_STRICT) == EOK){
     101                path = list_get_instance(path_it, usb_hid_report_path_t,
     102                                link);
     103               
     104                if(usb_hid_report_compare_usage_path(path, cmp_path,
     105                                        USB_HID_PATH_COMPARE_STRICT) == EOK){
    75106                        break;
    76107                }                       
     
    78109        }
    79110        if(path_it == &report->collection_paths) {
    80                 path = usb_hid_report_path_clone(cmp_path);                     
     111                path = usb_hid_report_path_clone(cmp_path);
     112                if(path == NULL) {
     113                        return NULL;
     114                }
    81115                list_append(&path->link, &report->collection_paths);                                   
    82116                report->collection_paths_count++;
     
    85119        }
    86120        else {
    87                 return list_get_instance(path_it, usb_hid_report_path_t, link);
    88         }
    89 }
    90 
     121                return list_get_instance(path_it, usb_hid_report_path_t,
     122                                link);
     123        }
     124}
     125
     126/*---------------------------------------------------------------------------*/
    91127/**
    92128 * Initialize the report descriptor parser structure
     
    94130 * @param parser Report descriptor parser structure
    95131 * @return Error code
     132 * @retval EINVAL If no report structure was given
     133 * @retval EOK If report structure was successfully initialized
    96134 */
    97135int usb_hid_report_init(usb_hid_report_t *report)
     
    109147}
    110148
    111 
    112 /*
    113  *
    114  *
    115  */
    116 int usb_hid_report_append_fields(usb_hid_report_t *report, usb_hid_report_item_t *report_item)
    117 {
     149/*---------------------------------------------------------------------------*/
     150
     151/**
     152 *
     153 *
     154 * @param report Report structure in which the new report items should be
     155 *               stored
     156 * @param report_item Current report descriptor's parsing state table
     157 * @return Error code
     158 * @retval EOK If all fields were successfully append to report
     159 * @retval EINVAL If invalid parameters (NULL) was given
     160 * @retval ENOMEM If there is no memmory to store new report description
     161 *
     162 */
     163int usb_hid_report_append_fields(usb_hid_report_t *report,
     164                usb_hid_report_item_t *report_item) {
     165
    118166        usb_hid_report_field_t *field;
    119167        int i;
     
    121169        uint32_t *usages;
    122170        int usages_used=0;
     171
     172        if((report == NULL) || (report_item == NULL)) {
     173                return EINVAL;
     174        }
     175
    123176        if(report_item->usages_count > 0){
    124177                usages = malloc(sizeof(int32_t) * report_item->usages_count);
    125                 memcpy(usages, report_item->usages, sizeof(int32_t) * report_item->usages_count);
     178                memcpy(usages, report_item->usages, sizeof(int32_t) *
     179                                report_item->usages_count);
    126180        }
    127181        else {
     
    144198                if(USB_HID_ITEM_FLAG_VARIABLE(report_item->item_flags) == 0){
    145199                        /*
    146                                 Store usage array. The Correct Usage Page and Usage is depending
    147                                 on data in report and will be filled later
     200                        Store usage array. The Correct Usage Page and Usage is
     201                        depending on data in report and will be filled later
    148202                        */
    149203                        field->usage = 0;
     
    162216                        }
    163217                        else {
    164                                 usage = report_item->usages[report_item->usages_count - 1];
     218                                usage = report_item->usages[
     219                                        report_item->usages_count- 1];
    165220                        }
    166221
    167222                        if(USB_HID_IS_EXTENDED_USAGE(usage)){
    168223                                field->usage = USB_HID_EXTENDED_USAGE(usage);
    169                                 field->usage_page = USB_HID_EXTENDED_USAGE_PAGE(usage);
     224                                field->usage_page =
     225                                        USB_HID_EXTENDED_USAGE_PAGE(usage);
    170226                        }
    171227                        else {
     
    176232                }
    177233               
    178                 usb_hid_report_set_last_item(path, USB_HID_TAG_CLASS_GLOBAL, field->usage_page);
    179                 usb_hid_report_set_last_item(path, USB_HID_TAG_CLASS_LOCAL, field->usage);
    180 
    181                 field->collection_path = usb_hid_report_path_try_insert(report, path);
     234                usb_hid_report_set_last_item(path, USB_HID_TAG_CLASS_GLOBAL,
     235                                field->usage_page);
     236                usb_hid_report_set_last_item(path, USB_HID_TAG_CLASS_LOCAL,
     237                                field->usage);
     238
     239                field->collection_path =
     240                        usb_hid_report_path_try_insert(report, path);
    182241
    183242                field->size = report_item->size;
    184243               
    185                 size_t offset_byte = (report_item->offset + (i * report_item->size)) / 8;
    186                 size_t offset_bit = 8 - ((report_item->offset + (i * report_item->size)) % 8) - report_item->size;
     244                size_t offset_byte = (report_item->offset + (i *
     245                        report_item->size)) / 8;
     246
     247                size_t offset_bit = 8 - ((report_item->offset + (i *
     248                        report_item->size)) % 8) - report_item->size;
    187249
    188250                field->offset = 8 * offset_byte + offset_bit;
     
    195257                /* find the right report list*/
    196258                usb_hid_report_description_t *report_des;
    197                 report_des = usb_hid_report_find_description(report, report_item->id, report_item->type);
     259                report_des = usb_hid_report_find_description(report,
     260                        report_item->id, report_item->type);
     261               
    198262                if(report_des == NULL){
    199                         report_des = malloc(sizeof(usb_hid_report_description_t));
    200                         memset(report_des, 0, sizeof(usb_hid_report_description_t));
     263                        report_des = malloc(
     264                                sizeof(usb_hid_report_description_t));
     265                        if(report_des == NULL) {
     266                                return ENOMEM;
     267                        }
     268
     269                        memset(report_des, 0,
     270                                sizeof(usb_hid_report_description_t));
    201271
    202272                        report_des->type = report_item->type;
    203273                        report_des->report_id = report_item->id;
     274                        if(report_des->report_id != 0) {
     275                                /* set up the bit length by report_id field */
     276                                report_des->bit_length = 8;
     277                        }
     278
    204279                        list_initialize (&report_des->link);
    205280                        list_initialize (&report_des->report_items);
     
    225300        return EOK;
    226301}
    227 
    228 usb_hid_report_description_t * usb_hid_report_find_description(const usb_hid_report_t *report, uint8_t report_id, usb_hid_report_type_t type)
    229 {
     302/*---------------------------------------------------------------------------*/
     303/**
     304 * Finds description of report with given report_id and of given type in
     305 * opaque report structure.
     306 *
     307 * @param report Opaque structure containing the parsed report descriptor
     308 * @param report_id ReportId of report we are searching
     309 * @param type Type of report we are searching
     310 * @return Pointer to the particular report description
     311 * @retval NULL If no description is founded
     312 */
     313usb_hid_report_description_t * usb_hid_report_find_description(
     314                const usb_hid_report_t *report, uint8_t report_id,
     315                usb_hid_report_type_t type) {
     316
    230317        link_t *report_it = report->reports.next;
    231318        usb_hid_report_description_t *report_des = NULL;
    232319       
    233320        while(report_it != &report->reports) {
    234                 report_des = list_get_instance(report_it, usb_hid_report_description_t, link);
    235 
    236                 if((report_des->report_id == report_id) && (report_des->type == type)){
     321                report_des = list_get_instance(report_it,
     322                                usb_hid_report_description_t, link);
     323
     324                if((report_des->report_id == report_id) &&
     325                   (report_des->type == type)) {
    237326                        return report_des;
    238327                }
     
    243332        return NULL;
    244333}
     334/*---------------------------------------------------------------------------*/
    245335
    246336/** Parse HID report descriptor.
     
    249339 * @param data Data describing the report.
    250340 * @return Error code.
     341 * @retval ENOMEM If no more memmory is available
     342 * @retval EINVAL If invalid data are founded
     343 * @retval EOK If report descriptor is successfully parsed
    251344 */
    252345int usb_hid_parse_report_descriptor(usb_hid_report_t *report,
     
    299392                       
    300393                        ret = usb_hid_report_parse_tag(tag,class,data+i+1,
    301                                                        item_size,report_item, usage_path);
     394                                item_size,report_item, usage_path);
     395
    302396                        switch(ret){
    303                                 case USB_HID_NEW_REPORT_ITEM:
    304                                         // store report item to report and create the new one
    305                                         // store current collection path
    306                                         report_item->usage_path = usage_path;
     397                        case USB_HID_NEW_REPORT_ITEM:
     398                                /* store report item to report and create the
     399                                 * new one store current collection path
     400                                 */
     401                                report_item->usage_path = usage_path;
    307402                                       
    308                                         usb_hid_report_path_set_report_id(report_item->usage_path, report_item->id);   
    309                                         if(report_item->id != 0){
    310                                                 report->use_report_ids = 1;
    311                                         }
     403                                usb_hid_report_path_set_report_id(
     404                                     report_item->usage_path, report_item->id);
     405                               
     406                                if(report_item->id != 0){
     407                                        report->use_report_ids = 1;
     408                                }
    312409                                       
    313                                         switch(tag) {
    314                                                 case USB_HID_REPORT_TAG_INPUT:
    315                                                         report_item->type = USB_HID_REPORT_TYPE_INPUT;
    316                                                         report_item->offset = offset_input;
    317                                                         offset_input += report_item->count * report_item->size;
    318                                                         break;
    319                                                 case USB_HID_REPORT_TAG_OUTPUT:
    320                                                         report_item->type = USB_HID_REPORT_TYPE_OUTPUT;
    321                                                         report_item->offset = offset_output;
    322                                                         offset_output += report_item->count * report_item->size;
    323 
    324                                                         break;
    325                                                 case USB_HID_REPORT_TAG_FEATURE:
    326                                                         report_item->type = USB_HID_REPORT_TYPE_FEATURE;
    327                                                         report_item->offset = offset_feature;
    328                                                         offset_feature += report_item->count * report_item->size;
    329                                                         break;
    330                                                 default:
    331                                                     usb_log_debug("\tjump over - tag %X\n", tag);
    332                                                     break;
    333                                         }
     410                                switch(tag) {
     411                                case USB_HID_REPORT_TAG_INPUT:
     412                                        report_item->type =
     413                                            USB_HID_REPORT_TYPE_INPUT;
     414
     415                                        report_item->offset = offset_input;
     416                                        offset_input += report_item->count *
     417                                            report_item->size;
     418                                        break;
     419       
     420                                case USB_HID_REPORT_TAG_OUTPUT:
     421                                        report_item->type =
     422                                            USB_HID_REPORT_TYPE_OUTPUT;
    334423                                       
    335                                         /*
    336                                          * append new fields to the report
    337                                          * structure                                     
    338                                          */
    339                                         usb_hid_report_append_fields(report, report_item);
    340 
    341                                         /* reset local items */
    342                                         usb_hid_report_reset_local_items (report_item);
    343 
     424                                        report_item->offset = offset_output;
     425                                        offset_output += report_item->count *
     426                                            report_item->size;
    344427                                        break;
    345 
    346                                 case USB_HID_RESET_OFFSET:
    347                                         offset_input = 0;
    348                                         offset_output = 0;
    349                                         offset_feature = 0;
    350                                         usb_hid_report_path_set_report_id (usage_path, report_item->id);
     428       
     429                                case USB_HID_REPORT_TAG_FEATURE:
     430                                        report_item->type =
     431                                            USB_HID_REPORT_TYPE_FEATURE;
     432
     433                                        report_item->offset = offset_feature;
     434                                        offset_feature += report_item->count *
     435                                                report_item->size;
    351436                                        break;
    352 
    353                                 case USB_HID_REPORT_TAG_PUSH:
    354                                         // push current state to stack
    355                                         new_report_item = usb_hid_report_item_clone(report_item);
    356                                         usb_hid_report_path_t *tmp_path = usb_hid_report_path_clone(usage_path);
    357                                         new_report_item->usage_path = tmp_path;
    358 
    359                                         list_prepend (&new_report_item->link, &stack);
    360                                         break;
    361                                 case USB_HID_REPORT_TAG_POP:
    362                                         // restore current state from stack
    363                                         if(list_empty (&stack)) {
    364                                                 return EINVAL;
    365                                         }
    366                                         free(report_item);
     437       
     438                                default:
     439                                        usb_log_debug2(
     440                                            "\tjump over - tag %X\n", tag);
     441                                        break;
     442                                }
     443                                       
     444                                /*
     445                                 * append new fields to the report structure                                     
     446                                 */
     447                                usb_hid_report_append_fields(report,
     448                                    report_item);
     449
     450                                /* reset local items */
     451                                usb_hid_report_reset_local_items (report_item);
     452                                break;
     453
     454                        case USB_HID_RESET_OFFSET:
     455                                offset_input = 0;
     456                                offset_output = 0;
     457                                offset_feature = 0;
     458                                usb_hid_report_path_set_report_id (usage_path,
     459                                    report_item->id);
     460                                break;
     461
     462                        case USB_HID_REPORT_TAG_PUSH:
     463                                // push current state to stack
     464                                new_report_item = usb_hid_report_item_clone(
     465                                    report_item);
     466                               
     467                                usb_hid_report_path_t *tmp_path =
     468                                    usb_hid_report_path_clone(usage_path);
     469
     470                                new_report_item->usage_path = tmp_path;
     471
     472                                list_prepend (&new_report_item->link, &stack);
     473                                break;
     474                        case USB_HID_REPORT_TAG_POP:
     475                                // restore current state from stack
     476                                if(list_empty (&stack)) {
     477                                        return EINVAL;
     478                                }
     479                                free(report_item);
    367480                                               
    368                                         report_item = list_get_instance(stack.next, usb_hid_report_item_t, link);
     481                                report_item = list_get_instance(stack.next,
     482                                    usb_hid_report_item_t, link);
    369483                                       
    370                                         usb_hid_report_usage_path_t *tmp_usage_path;
    371                                         tmp_usage_path = list_get_instance(report_item->usage_path->link.prev, usb_hid_report_usage_path_t, link);
     484                                usb_hid_report_usage_path_t *tmp_usage_path;
     485                                tmp_usage_path = list_get_instance(
     486                                    report_item->usage_path->link.prev,
     487                                    usb_hid_report_usage_path_t, link);
    372488                                       
    373                                         usb_hid_report_set_last_item(usage_path, USB_HID_TAG_CLASS_GLOBAL, tmp_usage_path->usage_page);
    374                                         usb_hid_report_set_last_item(usage_path, USB_HID_TAG_CLASS_LOCAL, tmp_usage_path->usage);
    375 
    376                                         usb_hid_report_path_free(report_item->usage_path);
    377                                         list_initialize(&report_item->usage_path->link);
    378                                         list_remove (stack.next);
     489                                usb_hid_report_set_last_item(usage_path,
     490                                    USB_HID_TAG_CLASS_GLOBAL, tmp_usage_path->usage_page);
     491                               
     492                                usb_hid_report_set_last_item(usage_path,
     493                                    USB_HID_TAG_CLASS_LOCAL, tmp_usage_path->usage);
     494
     495                                usb_hid_report_path_free(report_item->usage_path);
     496                                list_initialize(&report_item->usage_path->link);
     497                                list_remove (stack.next);
    379498                                       
    380                                         break;
     499                                break;
    381500                                       
    382                                 default:
    383                                         // nothing special to do                                       
    384                                         break;
     501                        default:
     502                                // nothing special to do                                       
     503                                break;
    385504                        }
    386505
     
    399518}
    400519
     520/*---------------------------------------------------------------------------*/
    401521
    402522/**
     
    409529 * @return Code of action to be done next
    410530 */
    411 int usb_hid_report_parse_tag(uint8_t tag, uint8_t class, const uint8_t *data, size_t item_size,
    412                              usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path)
    413 {       
     531int usb_hid_report_parse_tag(uint8_t tag, uint8_t class, const uint8_t *data,
     532        size_t item_size, usb_hid_report_item_t *report_item,
     533        usb_hid_report_path_t *usage_path) {   
     534       
    414535        int ret;
    415536       
    416537        switch(class){
    417                 case USB_HID_TAG_CLASS_MAIN:
    418 
    419                         if((ret=usb_hid_report_parse_main_tag(tag,data,item_size,report_item, usage_path)) == EOK) {
    420                                 return USB_HID_NEW_REPORT_ITEM;
    421                         }
    422                         else {
    423                                 /*TODO process the error */
    424                                 return ret;
    425                            }
    426                         break;
    427 
    428                 case USB_HID_TAG_CLASS_GLOBAL: 
    429                         return usb_hid_report_parse_global_tag(tag,data,item_size,report_item, usage_path);
    430                         break;
    431 
    432                 case USB_HID_TAG_CLASS_LOCAL:                   
    433                         return usb_hid_report_parse_local_tag(tag,data,item_size,report_item, usage_path);
    434                         break;
    435                 default:
    436                         return USB_HID_NO_ACTION;
     538        case USB_HID_TAG_CLASS_MAIN:
     539
     540                if((ret=usb_hid_report_parse_main_tag(tag, data, item_size,
     541                        report_item, usage_path)) == EOK) {
     542
     543                        return USB_HID_NEW_REPORT_ITEM;
     544                }
     545                else {
     546                        return ret;
     547                }
     548                break;
     549
     550        case USB_HID_TAG_CLASS_GLOBAL: 
     551                return usb_hid_report_parse_global_tag(tag, data, item_size,
     552                        report_item, usage_path);
     553                break;
     554
     555        case USB_HID_TAG_CLASS_LOCAL:                   
     556                return usb_hid_report_parse_local_tag(tag, data, item_size,
     557                        report_item, usage_path);
     558                break;
     559       
     560        default:
     561                return USB_HID_NO_ACTION;
    437562        }
    438563}
     
    448573 */
    449574
    450 int usb_hid_report_parse_main_tag(uint8_t tag, const uint8_t *data, size_t item_size,
    451                              usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path)
     575int usb_hid_report_parse_main_tag(uint8_t tag, const uint8_t *data,
     576        size_t item_size, usb_hid_report_item_t *report_item,
     577        usb_hid_report_path_t *usage_path)
    452578{
    453579        usb_hid_report_usage_path_t *path_item;
     
    455581        switch(tag)
    456582        {
    457                 case USB_HID_REPORT_TAG_INPUT:
    458                 case USB_HID_REPORT_TAG_OUTPUT:
    459                 case USB_HID_REPORT_TAG_FEATURE:
    460                         report_item->item_flags = *data;                       
    461                         return EOK;                     
    462                         break;
     583        case USB_HID_REPORT_TAG_INPUT:
     584        case USB_HID_REPORT_TAG_OUTPUT:
     585        case USB_HID_REPORT_TAG_FEATURE:
     586                report_item->item_flags = *data;                       
     587                return EOK;                     
     588                break;
    463589                       
    464                 case USB_HID_REPORT_TAG_COLLECTION:
    465 
    466                         // store collection atributes
    467                         path_item = list_get_instance(usage_path->head.prev, usb_hid_report_usage_path_t, link);
    468                         path_item->flags = *data;       
     590        case USB_HID_REPORT_TAG_COLLECTION:
     591
     592                /* store collection atributes */
     593                path_item = list_get_instance(usage_path->head.prev,
     594                        usb_hid_report_usage_path_t, link);
     595                path_item->flags = *data;       
    469596                       
    470                         // set last item
    471                         usb_hid_report_set_last_item(usage_path,
    472                                                      USB_HID_TAG_CLASS_GLOBAL,
    473                                                      USB_HID_EXTENDED_USAGE_PAGE(report_item->usages[report_item->usages_count-1]));
    474                         usb_hid_report_set_last_item(usage_path,
    475                                                      USB_HID_TAG_CLASS_LOCAL,
    476                                                      USB_HID_EXTENDED_USAGE(report_item->usages[report_item->usages_count-1]));
     597                /* set last item */
     598                usb_hid_report_set_last_item(usage_path,
     599                        USB_HID_TAG_CLASS_GLOBAL,
     600                        USB_HID_EXTENDED_USAGE_PAGE(report_item->usages[
     601                                report_item->usages_count-1]));
     602
     603                usb_hid_report_set_last_item(usage_path,
     604                        USB_HID_TAG_CLASS_LOCAL,
     605                        USB_HID_EXTENDED_USAGE(report_item->usages[
     606                                report_item->usages_count-1]));
    477607                       
    478                         // append the new one which will be set by common
    479                         // usage/usage page
    480                         usb_hid_report_path_append_item(usage_path, report_item->usage_page, report_item->usages[report_item->usages_count-1]);
    481                         usb_hid_report_reset_local_items (report_item);
    482                         return USB_HID_NO_ACTION;
    483                         break;
     608                /* append the new one which will be set by common usage/usage
     609                 * page */
     610                usb_hid_report_path_append_item(usage_path,
     611                        report_item->usage_page,
     612                        report_item->usages[report_item->usages_count-1]);
     613
     614                usb_hid_report_reset_local_items (report_item);
     615                return USB_HID_NO_ACTION;
     616                break;
    484617                       
    485                 case USB_HID_REPORT_TAG_END_COLLECTION:
    486                         usb_hid_report_remove_last_item(usage_path);
    487                         return USB_HID_NO_ACTION;
    488                         break;
    489                 default:
    490                         return USB_HID_NO_ACTION;
     618        case USB_HID_REPORT_TAG_END_COLLECTION:
     619                usb_hid_report_remove_last_item(usage_path);
     620                return USB_HID_NO_ACTION;
     621                break;
     622
     623        default:
     624                return USB_HID_NO_ACTION;
    491625        }
    492626
     
    503637 * @return Error code
    504638 */
    505 int usb_hid_report_parse_global_tag(uint8_t tag, const uint8_t *data, size_t item_size,
    506                              usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path)
    507 {
    508         // TODO take care about the bit length of data
     639int usb_hid_report_parse_global_tag(uint8_t tag, const uint8_t *data,
     640        size_t item_size, usb_hid_report_item_t *report_item,
     641        usb_hid_report_path_t *usage_path) {
     642       
    509643        switch(tag)
    510644        {
    511                 case USB_HID_REPORT_TAG_USAGE_PAGE:
    512                         report_item->usage_page = usb_hid_report_tag_data_uint32(data, item_size);
    513                         break;
    514                 case USB_HID_REPORT_TAG_LOGICAL_MINIMUM:
    515                         report_item->logical_minimum = USB_HID_UINT32_TO_INT32(usb_hid_report_tag_data_uint32(data,item_size), item_size * 8);
    516                         break;
    517                 case USB_HID_REPORT_TAG_LOGICAL_MAXIMUM:
    518                         report_item->logical_maximum = USB_HID_UINT32_TO_INT32(usb_hid_report_tag_data_uint32(data,item_size), item_size * 8);
    519                         break;
    520                 case USB_HID_REPORT_TAG_PHYSICAL_MINIMUM:
    521                         report_item->physical_minimum = USB_HID_UINT32_TO_INT32(usb_hid_report_tag_data_uint32(data,item_size), item_size * 8);
    522                         break;                 
    523                 case USB_HID_REPORT_TAG_PHYSICAL_MAXIMUM:
    524                         report_item->physical_maximum = USB_HID_UINT32_TO_INT32(usb_hid_report_tag_data_uint32(data,item_size), item_size * 8);
    525 
    526                         break;
    527                 case USB_HID_REPORT_TAG_UNIT_EXPONENT:
    528                         report_item->unit_exponent = usb_hid_report_tag_data_uint32(data,item_size);
    529                         break;
    530                 case USB_HID_REPORT_TAG_UNIT:
    531                         report_item->unit = usb_hid_report_tag_data_uint32(data,item_size);
    532                         break;
    533                 case USB_HID_REPORT_TAG_REPORT_SIZE:
    534                         report_item->size = usb_hid_report_tag_data_uint32(data,item_size);
    535                         break;
    536                 case USB_HID_REPORT_TAG_REPORT_COUNT:
    537                         report_item->count = usb_hid_report_tag_data_uint32(data,item_size);
    538                         break;
    539                 case USB_HID_REPORT_TAG_REPORT_ID:
    540                         report_item->id = usb_hid_report_tag_data_uint32(data,item_size);
    541                         return USB_HID_RESET_OFFSET;
    542                         break;
    543                 case USB_HID_REPORT_TAG_PUSH:
    544                 case USB_HID_REPORT_TAG_POP:
    545                         /*
    546                          * stack operations are done in top level parsing
    547                          * function
    548                          */
    549                         return tag;
    550                         break;
     645        case USB_HID_REPORT_TAG_USAGE_PAGE:
     646                report_item->usage_page =
     647                        usb_hid_report_tag_data_uint32(data, item_size);
     648                break;
     649
     650        case USB_HID_REPORT_TAG_LOGICAL_MINIMUM:
     651                report_item->logical_minimum = USB_HID_UINT32_TO_INT32(
     652                        usb_hid_report_tag_data_uint32(data,item_size),
     653                        item_size * 8);
     654                break;
     655
     656        case USB_HID_REPORT_TAG_LOGICAL_MAXIMUM:
     657                report_item->logical_maximum = USB_HID_UINT32_TO_INT32(
     658                        usb_hid_report_tag_data_uint32(data,item_size),
     659                        item_size * 8);
     660                break;
     661
     662        case USB_HID_REPORT_TAG_PHYSICAL_MINIMUM:
     663                report_item->physical_minimum = USB_HID_UINT32_TO_INT32(
     664                        usb_hid_report_tag_data_uint32(data,item_size),
     665                        item_size * 8);
     666                break;                 
     667
     668        case USB_HID_REPORT_TAG_PHYSICAL_MAXIMUM:
     669                report_item->physical_maximum = USB_HID_UINT32_TO_INT32(
     670                        usb_hid_report_tag_data_uint32(data,item_size),
     671                        item_size * 8);
     672                break;
     673
     674        case USB_HID_REPORT_TAG_UNIT_EXPONENT:
     675                report_item->unit_exponent = usb_hid_report_tag_data_uint32(
     676                        data,item_size);
     677                break;
     678
     679        case USB_HID_REPORT_TAG_UNIT:
     680                report_item->unit = usb_hid_report_tag_data_uint32(
     681                        data,item_size);
     682                break;
     683
     684        case USB_HID_REPORT_TAG_REPORT_SIZE:
     685                report_item->size = usb_hid_report_tag_data_uint32(
     686                        data,item_size);
     687                break;
     688
     689        case USB_HID_REPORT_TAG_REPORT_COUNT:
     690                report_item->count = usb_hid_report_tag_data_uint32(
     691                        data,item_size);
     692                break;
     693
     694        case USB_HID_REPORT_TAG_REPORT_ID:
     695                report_item->id = usb_hid_report_tag_data_uint32(data,
     696                        item_size);
     697                return USB_HID_RESET_OFFSET;
     698                break;
     699       
     700        case USB_HID_REPORT_TAG_PUSH:
     701        case USB_HID_REPORT_TAG_POP:
     702                /*
     703                 * stack operations are done in top level parsing
     704                 * function
     705                 */
     706                return tag;
     707                break;
    551708                       
    552                 default:
    553                         return USB_HID_NO_ACTION;
     709        default:
     710                return USB_HID_NO_ACTION;
    554711        }
    555712
     
    566723 * @return Error code
    567724 */
    568 int usb_hid_report_parse_local_tag(uint8_t tag, const uint8_t *data, size_t item_size,
    569                              usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path)
     725int usb_hid_report_parse_local_tag(uint8_t tag, const uint8_t *data,
     726        size_t item_size, usb_hid_report_item_t *report_item,
     727        usb_hid_report_path_t *usage_path)
    570728{
    571729        int32_t extended_usage;
    572730       
    573731        switch(tag) {
    574                 case USB_HID_REPORT_TAG_USAGE:
    575                         switch(report_item->in_delimiter) {
    576                                 case INSIDE_DELIMITER_SET:
    577                                         // nothing to do
    578                                         break;
    579                                 case START_DELIMITER_SET:
    580                                         report_item->in_delimiter = INSIDE_DELIMITER_SET;
    581                                 case OUTSIDE_DELIMITER_SET:
    582                                         extended_usage = ((report_item->usage_page) << 16);
    583                                         extended_usage += usb_hid_report_tag_data_uint32(data,item_size);
    584                                         report_item->usages[report_item->usages_count] = extended_usage;
    585                                         report_item->usages_count++;
    586                                         break;
     732        case USB_HID_REPORT_TAG_USAGE:
     733                switch(report_item->in_delimiter) {
     734                case INSIDE_DELIMITER_SET:
     735                        /* nothing to do
     736                         * we catch only the first one
     737                         */
     738                        break;
     739       
     740                case START_DELIMITER_SET:
     741                        report_item->in_delimiter = INSIDE_DELIMITER_SET;
     742                case OUTSIDE_DELIMITER_SET:
     743                        extended_usage = ((report_item->usage_page) << 16);
     744                        extended_usage += usb_hid_report_tag_data_uint32(
     745                                data,item_size);
     746
     747                        report_item->usages[report_item->usages_count] =
     748                                extended_usage;
     749
     750                        report_item->usages_count++;
     751                        break;
     752                }
     753                break;
     754               
     755        case USB_HID_REPORT_TAG_USAGE_MINIMUM:                 
     756                if (item_size == 3) {
     757                        // usage extended usages
     758                        report_item->extended_usage_page =
     759                            USB_HID_EXTENDED_USAGE_PAGE(
     760                            usb_hid_report_tag_data_uint32(data,item_size));
     761                           
     762
     763                        report_item->usage_minimum =
     764                            USB_HID_EXTENDED_USAGE(
     765                            usb_hid_report_tag_data_uint32(data,item_size));
     766                }
     767                else {
     768                        report_item->usage_minimum =
     769                            usb_hid_report_tag_data_uint32(data,item_size);
     770                }
     771                break;
     772       
     773        case USB_HID_REPORT_TAG_USAGE_MAXIMUM:
     774                if (item_size == 3) {
     775                        if(report_item->extended_usage_page !=
     776                            USB_HID_EXTENDED_USAGE_PAGE(       
     777                            usb_hid_report_tag_data_uint32(data,item_size))) {
     778                               
     779                                return EINVAL;
    587780                        }
    588                         break;
    589                 case USB_HID_REPORT_TAG_USAGE_MINIMUM:                 
    590                         if (item_size == 3) {
    591                                 // usage extended usages
    592                                 report_item->extended_usage_page = (usb_hid_report_tag_data_uint32(data,item_size) & 0xFF00) >> 16;
    593                                 report_item->usage_minimum = usb_hid_report_tag_data_uint32(data,item_size) & 0xFF;
     781                               
     782                        // usage extended usages
     783                        report_item->extended_usage_page =
     784                                USB_HID_EXTENDED_USAGE_PAGE(
     785                                usb_hid_report_tag_data_uint32(data,item_size));
     786
     787                        report_item->usage_maximum =
     788                                USB_HID_EXTENDED_USAGE(
     789                                usb_hid_report_tag_data_uint32(data,item_size));
     790                }
     791                else {
     792                        report_item->usage_maximum =
     793                                usb_hid_report_tag_data_uint32(data,item_size);
     794                }
     795
     796                // vlozit zaznamy do pole usages
     797                int32_t i;
     798                for(i = report_item->usage_minimum;
     799                    i <= report_item->usage_maximum; i++) {
     800
     801                        if(report_item->extended_usage_page) {
     802                            report_item->usages[report_item->usages_count++] =
     803                                (report_item->extended_usage_page << 16) + i;
    594804                        }
    595                         else {
    596                                 report_item->usage_minimum = usb_hid_report_tag_data_uint32(data,item_size);
     805                        else {                 
     806                            report_item->usages[report_item->usages_count++] =
     807                                (report_item->usage_page << 16) + i;
    597808                        }
    598                         break;
    599                 case USB_HID_REPORT_TAG_USAGE_MAXIMUM:
    600                         if (item_size == 3) {
    601 
    602                                 if(report_item->extended_usage_page != ((usb_hid_report_tag_data_uint32(data,item_size) & 0xFF00) >> 16)) {
    603                                         return EINVAL;
    604                                 }
    605                                
    606                                 // usage extended usages
    607                                 report_item->extended_usage_page = (usb_hid_report_tag_data_uint32(data,item_size) & 0xFF00) >> 16;
    608                                 report_item->usage_maximum = usb_hid_report_tag_data_uint32(data,item_size) & 0xFF;
    609                         }
    610                         else {
    611                                 report_item->usage_maximum = usb_hid_report_tag_data_uint32(data,item_size);
    612                         }
    613 
    614                         // vlozit zaznamy do pole usages
    615                         int32_t i;
    616                         for(i=report_item->usage_minimum; i<=report_item->usage_maximum; i++) {
    617                                 if(report_item->extended_usage_page) {
    618                                         report_item->usages[report_item->usages_count++] = (report_item->extended_usage_page << 16) + i;
    619                                 }
    620                                 else {
    621                                        
    622                                         report_item->usages[report_item->usages_count++] = (report_item->usage_page << 16) + i;
    623                                 }
    624                         }
    625                         report_item->extended_usage_page = 0;
     809                }
     810                report_item->extended_usage_page = 0;
    626811                       
    627                         break;
    628                 case USB_HID_REPORT_TAG_DESIGNATOR_INDEX:
    629                         report_item->designator_index = usb_hid_report_tag_data_uint32(data,item_size);
    630                         break;
    631                 case USB_HID_REPORT_TAG_DESIGNATOR_MINIMUM:
    632                         report_item->designator_minimum = usb_hid_report_tag_data_uint32(data,item_size);
    633                         break;
    634                 case USB_HID_REPORT_TAG_DESIGNATOR_MAXIMUM:
    635                         report_item->designator_maximum = usb_hid_report_tag_data_uint32(data,item_size);
    636                         break;
    637                 case USB_HID_REPORT_TAG_STRING_INDEX:
    638                         report_item->string_index = usb_hid_report_tag_data_uint32(data,item_size);
    639                         break;
    640                 case USB_HID_REPORT_TAG_STRING_MINIMUM:
    641                         report_item->string_minimum = usb_hid_report_tag_data_uint32(data,item_size);
    642                         break;
    643                 case USB_HID_REPORT_TAG_STRING_MAXIMUM:
    644                         report_item->string_maximum = usb_hid_report_tag_data_uint32(data,item_size);
    645                         break;                 
    646                 case USB_HID_REPORT_TAG_DELIMITER:
    647                         report_item->in_delimiter = usb_hid_report_tag_data_uint32(data,item_size);
    648                         break;
    649 
    650                 default:
    651                         return USB_HID_NO_ACTION;
     812                break;
     813               
     814        case USB_HID_REPORT_TAG_DESIGNATOR_INDEX:
     815                report_item->designator_index =
     816                        usb_hid_report_tag_data_uint32(data,item_size);
     817                break;
     818       
     819        case USB_HID_REPORT_TAG_DESIGNATOR_MINIMUM:
     820                report_item->designator_minimum =
     821                        usb_hid_report_tag_data_uint32(data,item_size);
     822                break;
     823
     824        case USB_HID_REPORT_TAG_DESIGNATOR_MAXIMUM:
     825                report_item->designator_maximum =
     826                        usb_hid_report_tag_data_uint32(data,item_size);
     827                break;
     828
     829        case USB_HID_REPORT_TAG_STRING_INDEX:
     830                report_item->string_index =
     831                        usb_hid_report_tag_data_uint32(data,item_size);
     832                break;
     833
     834        case USB_HID_REPORT_TAG_STRING_MINIMUM:
     835                report_item->string_minimum =
     836                        usb_hid_report_tag_data_uint32(data,item_size);
     837                break;
     838
     839        case USB_HID_REPORT_TAG_STRING_MAXIMUM:
     840                report_item->string_maximum =
     841                        usb_hid_report_tag_data_uint32(data,item_size);
     842                break;                 
     843
     844        case USB_HID_REPORT_TAG_DELIMITER:
     845                report_item->in_delimiter =
     846                        usb_hid_report_tag_data_uint32(data,item_size);
     847                break;
     848
     849        default:
     850                return USB_HID_NO_ACTION;
    652851        }
    653852
    654853        return EOK;
    655854}
     855/*---------------------------------------------------------------------------*/
    656856
    657857/**
     
    674874        return result;
    675875}
     876/*---------------------------------------------------------------------------*/
    676877
    677878/**
     
    694895        for(item = head->next; item != head; item = item->next) {
    695896               
    696                 report_item = list_get_instance(item, usb_hid_report_field_t, link);
     897                report_item = list_get_instance(item, usb_hid_report_field_t,
     898                                link);
    697899
    698900                usb_log_debug("\t\tOFFSET: %X\n", report_item->offset);
    699                 usb_log_debug("\t\tSIZE: %zu\n", report_item->size);                           
    700                 usb_log_debug("\t\tLOGMIN: %d\n", report_item->logical_minimum);
    701                 usb_log_debug("\t\tLOGMAX: %d\n", report_item->logical_maximum);               
    702                 usb_log_debug("\t\tPHYMIN: %d\n", report_item->physical_minimum);               
    703                 usb_log_debug("\t\tPHYMAX: %d\n", report_item->physical_maximum);                               
    704                 usb_log_debug("\t\ttUSAGEMIN: %X\n", report_item->usage_minimum);
    705                 usb_log_debug("\t\tUSAGEMAX: %X\n", report_item->usage_maximum);
    706                 usb_log_debug("\t\tUSAGES COUNT: %zu\n", report_item->usages_count);
     901                usb_log_debug("\t\tSIZE: %zu\n", report_item->size);
     902                usb_log_debug("\t\tLOGMIN: %d\n",
     903                        report_item->logical_minimum);
     904                usb_log_debug("\t\tLOGMAX: %d\n",
     905                        report_item->logical_maximum);         
     906                usb_log_debug("\t\tPHYMIN: %d\n",
     907                        report_item->physical_minimum);         
     908                usb_log_debug("\t\tPHYMAX: %d\n",
     909                        report_item->physical_maximum);                         
     910                usb_log_debug("\t\ttUSAGEMIN: %X\n",
     911                        report_item->usage_minimum);
     912                usb_log_debug("\t\tUSAGEMAX: %X\n",
     913                               report_item->usage_maximum);
     914                usb_log_debug("\t\tUSAGES COUNT: %zu\n",
     915                        report_item->usages_count);
    707916
    708917                usb_log_debug("\t\tVALUE: %X\n", report_item->value);
     
    716925        }
    717926
    718 
    719 }
     927}
     928/*---------------------------------------------------------------------------*/
     929
    720930/**
    721931 * Prints content of given report descriptor in human readable format.
     
    734944
    735945        while(report_it != &report->reports) {
    736                 report_des = list_get_instance(report_it, usb_hid_report_description_t, link);
     946                report_des = list_get_instance(report_it,
     947                        usb_hid_report_description_t, link);
    737948                usb_log_debug("Report ID: %d\n", report_des->report_id);
    738949                usb_log_debug("\tType: %d\n", report_des->type);
    739950                usb_log_debug("\tLength: %zu\n", report_des->bit_length);               
     951                usb_log_debug("\tB Size: %zu\n",
     952                        usb_hid_report_byte_size(report,
     953                                report_des->report_id,
     954                                report_des->type));
    740955                usb_log_debug("\tItems: %zu\n", report_des->item_length);               
    741956
    742957                usb_hid_descriptor_print_list(&report_des->report_items);
    743958
    744 /*
    745                 link_t *path_it = report->collection_paths.next;
    746                 while(path_it != &report->collection_paths) {
    747                         usb_hid_print_usage_path (list_get_instance(path_it, usb_hid_report_path_t, link));
    748                         path_it = path_it->next;
    749                 }
    750 */             
    751959                report_it = report_it->next;
    752960        }
    753961}
     962/*---------------------------------------------------------------------------*/
    754963
    755964/**
     
    776985
    777986                while(!list_empty(&report_item->usage_path->link)) {
    778                         usb_hid_report_remove_last_item(report_item->usage_path);
     987                    usb_hid_report_remove_last_item(report_item->usage_path);
    779988                }
    780989
     
    788997       
    789998}
     999/*---------------------------------------------------------------------------*/
    7901000
    7911001/** Frees the HID report descriptor parser structure
     
    8031013        usb_hid_report_path_t *path;
    8041014        while(!list_empty(&report->collection_paths)) {
    805                 path = list_get_instance(report->collection_paths.next, usb_hid_report_path_t, link);
     1015                path = list_get_instance(report->collection_paths.next,
     1016                                usb_hid_report_path_t, link);
     1017
    8061018                usb_hid_report_path_free(path);         
    8071019        }
     
    8111023        usb_hid_report_field_t *field;
    8121024        while(!list_empty(&report->reports)) {
    813                 report_des = list_get_instance(report->reports.next, usb_hid_report_description_t, link);
     1025                report_des = list_get_instance(report->reports.next,
     1026                                usb_hid_report_description_t, link);
     1027
    8141028                list_remove(&report_des->link);
    8151029               
    8161030                while(!list_empty(&report_des->report_items)) {
    817                         field = list_get_instance(report_des->report_items.next, usb_hid_report_field_t, link);
     1031                        field = list_get_instance(
     1032                                report_des->report_items.next,
     1033                                usb_hid_report_field_t, link);
     1034
    8181035                        list_remove(&field->link);
    8191036
     
    8261043        return;
    8271044}
     1045/*---------------------------------------------------------------------------*/
    8281046
    8291047/**
  • uspace/lib/usbhid/src/hidiface.c

    re8f826b r400735e  
    4646 * @return Number of usages returned or negative error code.
    4747 */
    48 int usbhid_dev_get_event_length(int dev_phone)
     48int usbhid_dev_get_event_length(int dev_phone, size_t *size)
    4949{
    5050        if (dev_phone < 0) {
     
    5656            IPC_M_USBHID_GET_EVENT_LENGTH, &len);
    5757        if (rc == EOK) {
    58                 return (int) len;
    59         } else {
    60                 return rc;
    61         }
     58                if (size != NULL) {
     59                        *size = (size_t) len;
     60                }
     61        }
     62       
     63        return rc;
    6264}
    6365
     
    7476 * @return Error code.
    7577 */
    76 int usbhid_dev_get_event(int dev_phone, uint16_t *usage_pages, uint16_t *usages,
    77     size_t usage_count, size_t *actual_usage_count, unsigned int flags)
    78 {
    79         if (dev_phone < 0) {
    80                 return EINVAL;
    81         }
    82         if ((usage_pages == NULL) || (usages == NULL)) {
    83                 return ENOMEM;
    84         }
    85         if (usage_count == 0) {
    86                 return EINVAL;
    87         }
    88 
    89         size_t buffer_size = sizeof(uint16_t) * usage_count * 2;
    90         uint16_t *buffer = malloc(buffer_size);
     78int usbhid_dev_get_event(int dev_phone, uint8_t *buf,
     79    size_t size, size_t *actual_size, int *event_nr, unsigned int flags)
     80{
     81        if (dev_phone < 0) {
     82                return EINVAL;
     83        }
     84        if ((buf == NULL)) {
     85                return ENOMEM;
     86        }
     87        if (size == 0) {
     88                return EINVAL;
     89        }
     90       
     91//      if (size == 0) {
     92//              return EOK;
     93//      }
     94
     95        size_t buffer_size =  size;
     96        uint8_t *buffer = malloc(buffer_size);
    9197        if (buffer == NULL) {
    9298                return ENOMEM;
    9399        }
    94100
     101        ipc_call_t opening_request_call;
    95102        aid_t opening_request = async_send_2(dev_phone,
    96103            DEV_IFACE_ID(USBHID_DEV_IFACE), IPC_M_USBHID_GET_EVENT,
    97             flags, NULL);
     104            flags, &opening_request_call);
    98105        if (opening_request == 0) {
    99106                free(buffer);
     
    128135        }
    129136
    130         size_t actual_size = IPC_GET_ARG2(data_request_call);
    131         size_t items = actual_size / 2;
     137        size_t act_size = IPC_GET_ARG2(data_request_call);
    132138
    133139        /* Copy the individual items. */
    134         memcpy(usage_pages, buffer, items * sizeof(uint16_t));
    135         memcpy(usages, buffer + items, items * sizeof(uint16_t));
    136 
    137         if (actual_usage_count != NULL) {
    138                 *actual_usage_count = items;
     140        memcpy(buf, buffer, act_size);
     141//      memcpy(usages, buffer + items, items * sizeof(int32_t));
     142
     143        if (actual_size != NULL) {
     144                *actual_size = act_size;
     145        }
     146       
     147        if (event_nr != NULL) {
     148                *event_nr = IPC_GET_ARG1(opening_request_call);
     149        }
     150
     151        return EOK;
     152}
     153
     154
     155int usbhid_dev_get_report_descriptor_length(int dev_phone, size_t *size)
     156{
     157        if (dev_phone < 0) {
     158                return EINVAL;
     159        }
     160
     161        sysarg_t arg_size;
     162        int rc = async_req_1_1(dev_phone, DEV_IFACE_ID(USBHID_DEV_IFACE),
     163            IPC_M_USBHID_GET_REPORT_DESCRIPTOR_LENGTH, &arg_size);
     164        if (rc == EOK) {
     165                if (size != NULL) {
     166                        *size = (size_t) arg_size;
     167                }
     168        }
     169        return rc;
     170}
     171
     172int usbhid_dev_get_report_descriptor(int dev_phone, uint8_t *buf, size_t size,
     173    size_t *actual_size)
     174{
     175        if (dev_phone < 0) {
     176                return EINVAL;
     177        }
     178        if ((buf == NULL)) {
     179                return ENOMEM;
     180        }
     181        if (size == 0) {
     182                return EINVAL;
     183        }
     184
     185        aid_t opening_request = async_send_1(dev_phone,
     186            DEV_IFACE_ID(USBHID_DEV_IFACE), IPC_M_USBHID_GET_REPORT_DESCRIPTOR,
     187            NULL);
     188        if (opening_request == 0) {
     189                return ENOMEM;
     190        }
     191
     192        ipc_call_t data_request_call;
     193        aid_t data_request = async_data_read(dev_phone, buf, size,
     194            &data_request_call);
     195        if (data_request == 0) {
     196                async_wait_for(opening_request, NULL);
     197                return ENOMEM;
     198        }
     199
     200        sysarg_t data_request_rc;
     201        sysarg_t opening_request_rc;
     202        async_wait_for(data_request, &data_request_rc);
     203        async_wait_for(opening_request, &opening_request_rc);
     204
     205        if (data_request_rc != EOK) {
     206                /* Prefer return code of the opening request. */
     207                if (opening_request_rc != EOK) {
     208                        return (int) opening_request_rc;
     209                } else {
     210                        return (int) data_request_rc;
     211                }
     212        }
     213
     214        if (opening_request_rc != EOK) {
     215                return (int) opening_request_rc;
     216        }
     217
     218        size_t act_size = IPC_GET_ARG2(data_request_call);
     219
     220        if (actual_size != NULL) {
     221                *actual_size = act_size;
    139222        }
    140223