Changeset df6ded8 in mainline for uspace/lib/usbhid/src


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

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

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

Notable additions and features:

  • new host controller driver has been implemented to control various xHC models (among others, NEC Renesas uPD720200)
  • isochronous data transfer mode
  • support for explicit USB device removal
  • USB tablet driver
Location:
uspace/lib/usbhid/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbhid/src/hiddescriptor.c

    rf5e5f73 rdf6ded8  
    11/*
    22 * Copyright (c) 2011 Matej Klonfar
     3 * Copyright (c) 2018 Ondrej Hlavaty
    34 * All rights reserved.
    45 *
     
    176177
    177178        if(report_item->usages_count > 0){
    178                 usages = malloc(sizeof(int32_t) * report_item->usages_count);
     179                usages = malloc(sizeof(uint32_t) * report_item->usages_count);
    179180                memcpy(usages, report_item->usages, sizeof(int32_t) *
    180181                                report_item->usages_count);
     
    247248                field->size = report_item->size;
    248249
    249                 if(report_item->type == USB_HID_REPORT_TYPE_INPUT) {
    250                         int offset = report_item->offset + report_item->size * i;
    251                         int field_offset = (offset/8)*8 + (offset/8 + 1) * 8 -
    252                                 offset - report_item->size;
    253                         if(field_offset < 0) {
    254                                 field->offset = 0;
    255                         }
    256                         else {
    257                                 field->offset = field_offset;
    258                         }
    259                 }
    260                 else {
    261                         field->offset = report_item->offset + (i * report_item->size);
    262                 }
    263 
     250                field->offset = report_item->offset + (i * report_item->size);
    264251
    265252                if(report->use_report_ids != 0) {
     
    896883{
    897884        if(list == NULL || list_empty(list)) {
    898             usb_log_debug("\tempty\n");
     885            usb_log_debug("\tempty");
    899886            return;
    900887        }
     
    902889        list_foreach(*list, ritems_link, usb_hid_report_field_t,
    903890            report_item) {
    904                 usb_log_debug("\t\tOFFSET: %X\n", report_item->offset);
    905                 usb_log_debug("\t\tSIZE: %zu\n", report_item->size);
    906                 usb_log_debug("\t\tLOGMIN: %d\n",
     891                usb_log_debug("\t\tOFFSET: %u", report_item->offset);
     892                usb_log_debug("\t\tSIZE: %zu", report_item->size);
     893                usb_log_debug("\t\tLOGMIN: %d",
    907894                        report_item->logical_minimum);
    908                 usb_log_debug("\t\tLOGMAX: %d\n",
     895                usb_log_debug("\t\tLOGMAX: %d",
    909896                        report_item->logical_maximum);
    910                 usb_log_debug("\t\tPHYMIN: %d\n",
     897                usb_log_debug("\t\tPHYMIN: %d",
    911898                        report_item->physical_minimum);
    912                 usb_log_debug("\t\tPHYMAX: %d\n",
     899                usb_log_debug("\t\tPHYMAX: %d",
    913900                        report_item->physical_maximum);
    914                 usb_log_debug("\t\ttUSAGEMIN: %X\n",
     901                usb_log_debug("\t\ttUSAGEMIN: %X",
    915902                        report_item->usage_minimum);
    916                 usb_log_debug("\t\tUSAGEMAX: %X\n",
     903                usb_log_debug("\t\tUSAGEMAX: %X",
    917904                               report_item->usage_maximum);
    918                 usb_log_debug("\t\tUSAGES COUNT: %zu\n",
     905                usb_log_debug("\t\tUSAGES COUNT: %zu",
    919906                        report_item->usages_count);
    920907
    921                 usb_log_debug("\t\tVALUE: %X\n", report_item->value);
    922                 usb_log_debug("\t\ttUSAGE: %X\n", report_item->usage);
    923                 usb_log_debug("\t\tUSAGE PAGE: %X\n", report_item->usage_page);
     908                usb_log_debug("\t\tVALUE: %X", report_item->value);
     909                usb_log_debug("\t\ttUSAGE: %X", report_item->usage);
     910                usb_log_debug("\t\tUSAGE PAGE: %X", report_item->usage_page);
    924911
    925912                usb_hid_print_usage_path(report_item->collection_path);
    926 
    927                 usb_log_debug("\n");
    928913        }
    929914}
     
    943928        list_foreach(report->reports, reports_link,
    944929            usb_hid_report_description_t, report_des) {
    945                 usb_log_debug("Report ID: %d\n", report_des->report_id);
    946                 usb_log_debug("\tType: %d\n", report_des->type);
    947                 usb_log_debug("\tLength: %zu\n", report_des->bit_length);
    948                 usb_log_debug("\tB Size: %zu\n",
     930                usb_log_debug("Report ID: %d", report_des->report_id);
     931                usb_log_debug("\tType: %d", report_des->type);
     932                usb_log_debug("\tLength: %zu", report_des->bit_length);
     933                usb_log_debug("\tB Size: %zu",
    949934                        usb_hid_report_byte_size(report,
    950935                                report_des->report_id,
    951936                                report_des->type));
    952                 usb_log_debug("\tItems: %zu\n", report_des->item_length);
     937                usb_log_debug("\tItems: %zu", report_des->item_length);
    953938
    954939                usb_hid_descriptor_print_list(&report_des->report_items);
  • uspace/lib/usbhid/src/hidparser.c

    rf5e5f73 rdf6ded8  
    11/*
    22 * Copyright (c) 2011 Matej Klonfar
     3 * Copyright (c) 2018 Ondrej Hlavaty
    34 * All rights reserved.
    45 *
     
    4041#include <usb/debug.h>
    4142#include <assert.h>
     43#include <bitops.h>
     44#include <macros.h>
    4245
    4346
     
    4952int usb_hid_translate_data(usb_hid_report_field_t *item, const uint8_t *data);
    5053
    51 uint32_t usb_hid_translate_data_reverse(usb_hid_report_field_t *item, 
    52         int32_t value);
     54uint32_t usb_hid_translate_data_reverse(usb_hid_report_field_t *item,
     55    int32_t value);
    5356
    5457
     
    7376 *
    7477 * @param parser Opaque report parser structure
    75  * @param report_id 
     78 * @param report_id
    7679 * @param type
    7780 * @return Number of items in specified report
    7881 */
    79 size_t usb_hid_report_size(usb_hid_report_t *report, uint8_t report_id, 
     82size_t usb_hid_report_size(usb_hid_report_t *report, uint8_t report_id,
    8083    usb_hid_report_type_t type)
    8184{
     
    97100 *
    98101 * @param parser Opaque report parser structure
    99  * @param report_id 
     102 * @param report_id
    100103 * @param type
    101104 * @return Number of items in specified report
    102105 */
    103 size_t usb_hid_report_byte_size(usb_hid_report_t *report, uint8_t report_id, 
     106size_t usb_hid_report_byte_size(usb_hid_report_t *report, uint8_t report_id,
    104107    usb_hid_report_type_t type)
    105108{
     
    114117                return 0;
    115118        } else {
    116                 return ((report_des->bit_length + 7) / 8) ;
     119                return ((report_des->bit_length + 7) / 8);
    117120        }
    118121}
     
    126129 * @param data Data for the report.
    127130 * @return Error code.
    128  */ 
    129 errno_t usb_hid_parse_report(const usb_hid_report_t *report, const uint8_t *data, 
     131 */
     132errno_t usb_hid_parse_report(const usb_hid_report_t *report, const uint8_t *data,
    130133    size_t size, uint8_t *report_id)
    131134{
    132135        usb_hid_report_description_t *report_des;
    133136        usb_hid_report_type_t type = USB_HID_REPORT_TYPE_INPUT;
    134        
     137
    135138        if (report == NULL) {
    136139                return EINVAL;
     
    143146        }
    144147
    145         report_des = usb_hid_report_find_description(report, *report_id, 
     148        report_des = usb_hid_report_find_description(report, *report_id,
    146149            type);
    147150
     
    155158
    156159                if (USB_HID_ITEM_FLAG_CONSTANT(item->item_flags) == 0) {
    157                        
     160
    158161                        if (USB_HID_ITEM_FLAG_VARIABLE(item->item_flags) == 0) {
    159162                                /* array */
    160                                 item->value = 
    161                                         usb_hid_translate_data(item, data);
    162                                
     163                                item->value =
     164                                    usb_hid_translate_data(item, data);
     165
    163166                                item->usage = USB_HID_EXTENDED_USAGE(
    164167                                    item->usages[item->value -
    165168                                    item->physical_minimum]);
    166169
    167                                 item->usage_page = 
     170                                item->usage_page =
    168171                                    USB_HID_EXTENDED_USAGE_PAGE(
    169172                                    item->usages[item->value -
     
    171174
    172175                                usb_hid_report_set_last_item(
    173                                     item->collection_path, 
    174                                     USB_HID_TAG_CLASS_GLOBAL, 
     176                                    item->collection_path,
     177                                    USB_HID_TAG_CLASS_GLOBAL,
    175178                                    item->usage_page);
    176179
    177180                                usb_hid_report_set_last_item(
    178                                     item->collection_path, 
     181                                    item->collection_path,
    179182                                    USB_HID_TAG_CLASS_LOCAL, item->usage);
    180183                        } else {
    181184                                /* variable item */
    182                                 item->value = usb_hid_translate_data(item, 
     185                                item->value = usb_hid_translate_data(item,
    183186                                    data);
    184187                        }
    185188                }
    186189        }
    187        
     190
    188191        return EOK;
    189192}
     
    199202int usb_hid_translate_data(usb_hid_report_field_t *item, const uint8_t *data)
    200203{
    201         int resolution;
    202         int offset;
    203         int part_size;
    204        
    205         int32_t value = 0;
    206         int32_t mask = 0;
    207         const uint8_t *foo = 0;
    208 
    209204        /* now only short tags are allowed */
    210205        if (item->size > 32) {
     
    214209        if ((item->physical_minimum == 0) && (item->physical_maximum == 0)) {
    215210                item->physical_minimum = item->logical_minimum;
    216                 item->physical_maximum = item->logical_maximum;                 
    217         }
    218        
    219 
     211                item->physical_maximum = item->logical_maximum;
     212        }
     213
     214        int resolution;
    220215        if (item->physical_maximum == item->physical_minimum) {
    221             resolution = 1;
    222         } else {
    223             resolution = (item->logical_maximum - item->logical_minimum) /
    224                 ((item->physical_maximum - item->physical_minimum) *
    225                 (usb_pow(10, (item->unit_exponent))));
    226         }
    227 
    228         offset = item->offset;
    229         // FIXME
    230         if ((size_t) (offset / 8) != (size_t) ((offset+item->size - 1) / 8)) {
    231                
    232                 part_size = 0;
    233 
    234                 size_t i = 0;
    235                 for (i = (size_t) (offset / 8);
    236                     i <= (size_t) (offset + item->size - 1) / 8; i++) {
    237                         if (i == (size_t) (offset / 8)) {
    238                                 /* the higher one */
    239                                 part_size = 8 - (offset % 8);
    240                                 foo = data + i;
    241                                 mask =  ((1 << (item->size - part_size)) - 1);
    242                                 value = (*foo & mask);
    243                         } else if (i == ((offset + item->size - 1) / 8)) {
    244                                 /* the lower one */
    245                                 foo = data + i;
    246                                 mask = ((1 << (item->size - part_size)) - 1) <<
    247                                     (8 - (item->size - part_size));
    248 
    249                                 value = (((*foo & mask) >> (8 -
    250                                     (item->size - part_size))) << part_size) +
    251                                     value;
    252                         } else {
    253                                 value = (*(data + 1) << (part_size + 8)) +
    254                                     value;
    255                                 part_size += 8;
    256                         }
    257                 }
    258         } else {               
    259                 foo = data + (offset / 8);
    260                 mask = ((1 << item->size) - 1) <<
    261                     (8 - ((offset % 8) + item->size));
    262                 value = (*foo & mask) >> (8 - ((offset % 8) + item->size));
     216                resolution = 1;
     217        } else {
     218                resolution = (item->logical_maximum - item->logical_minimum) /
     219                    ((item->physical_maximum - item->physical_minimum) *
     220                    (usb_pow(10, (item->unit_exponent))));
     221        }
     222
     223        int32_t value = 0;
     224
     225        /* First, skip all bytes we don't care */
     226        data += item->offset / 8;
     227
     228        int bits = item->size;
     229        int taken = 0;
     230
     231        /* Than we take the higher bits from the LSB */
     232        const unsigned bit_offset = item->offset % 8;
     233        const int lsb_bits = min(bits, 8);
     234
     235        value |= (*data >> bit_offset) & BIT_RRANGE(uint8_t, lsb_bits);
     236        bits -= lsb_bits;
     237        taken += lsb_bits;
     238        data++;
     239
     240        /* Then there may be bytes, which we take as a whole. */
     241        while (bits > 8) {
     242                value |= *data << taken;
     243                taken += 8;
     244                bits -= 8;
     245                data++;
     246        }
     247
     248        /* And, finally, lower bits from HSB. */
     249        if (bits > 0) {
     250                value |= (*data & BIT_RRANGE(uint8_t, bits)) << taken;
    263251        }
    264252
     
    267255        }
    268256
    269         return (int) (((value - item->logical_minimum) / resolution) + 
     257        return (int) (((value - item->logical_minimum) / resolution) +
    270258            item->physical_minimum);
    271259}
     
    274262/* OUTPUT API */
    275263
    276 /** 
     264/**
    277265 * Allocates output report buffer for output report
    278266 *
     
    282270 * @return Returns allocated output buffer for specified output
    283271 */
    284 uint8_t *usb_hid_report_output(usb_hid_report_t *report, size_t *size, 
     272uint8_t *usb_hid_report_output(usb_hid_report_t *report, size_t *size,
    285273    uint8_t report_id)
    286274{
     
    334322 * @return Error code
    335323 */
    336 errno_t usb_hid_report_output_translate(usb_hid_report_t *report, 
     324errno_t usb_hid_report_output_translate(usb_hid_report_t *report,
    337325    uint8_t report_id, uint8_t *buffer, size_t size)
    338326{
     
    341329        int length;
    342330        int32_t tmp_value;
    343        
     331
    344332        if (report == NULL) {
    345333                return EINVAL;
     
    351339
    352340        usb_hid_report_description_t *report_des;
    353         report_des = usb_hid_report_find_description(report, report_id, 
     341        report_des = usb_hid_report_find_description(report, report_id,
    354342            USB_HID_REPORT_TYPE_OUTPUT);
    355        
     343
    356344        if (report_des == NULL) {
    357345                return EINVAL;
     
    360348        list_foreach(report_des->report_items, ritems_link,
    361349            usb_hid_report_field_t, report_item) {
    362                 value = usb_hid_translate_data_reverse(report_item, 
     350                value = usb_hid_translate_data_reverse(report_item,
    363351                    report_item->value);
    364352
    365353                offset = report_des->bit_length - report_item->offset - 1;
    366354                length = report_item->size;
    367                
    368                 usb_log_debug("\ttranslated value: %x\n", value);
     355
     356                usb_log_debug("\ttranslated value: %x", value);
    369357
    370358                if ((offset / 8) == ((offset + length - 1) / 8)) {
    371                         if (((size_t) (offset / 8) >= size) || 
     359                        if (((size_t) (offset / 8) >= size) ||
    372360                            ((size_t) (offset + length - 1) / 8) >= size) {
    373361                                break; // TODO ErrorCode
     
    376364                        value = value << shift;
    377365                        value = value & (((1 << length) - 1) << shift);
    378                        
     366
    379367                        uint8_t mask = 0;
    380368                        mask = 0xff - (((1 << length) - 1) << shift);
     
    388376                                if (i == (offset / 8)) {
    389377                                        tmp_value = value;
    390                                         tmp_value = tmp_value & 
     378                                        tmp_value = tmp_value &
    391379                                            ((1 << (8 - (offset % 8))) - 1);
    392380
    393381                                        tmp_value = tmp_value << (offset % 8);
    394                                        
     382
    395383                                        mask = ~(((1 << (8 - (offset % 8))) - 1)
    396384                                            << (offset % 8));
    397385
    398                                         buffer[i] = (buffer[i] & mask) | 
     386                                        buffer[i] = (buffer[i] & mask) |
    399387                                            tmp_value;
    400388                                } else if (i == ((offset + length - 1) / 8)) {
    401                                        
    402                                         value = value >> (length - 
     389
     390                                        value = value >> (length -
    403391                                            ((offset + length) % 8));
    404392
    405                                         value = value & ((1 << (length - 
     393                                        value = value & ((1 << (length -
    406394                                            ((offset + length) % 8))) - 1);
    407                                        
    408                                         mask = (1 << (length - 
     395
     396                                        mask = (1 << (length -
    409397                                            ((offset + length) % 8))) - 1;
    410398
     
    419407                report_item->value = 0;
    420408        }
    421        
     409
    422410        return EOK;
    423411}
     
    430418 * @return ranslated value
    431419 */
    432 uint32_t usb_hid_translate_data_reverse(usb_hid_report_field_t *item, 
     420uint32_t usb_hid_translate_data_reverse(usb_hid_report_field_t *item,
    433421    int value)
    434422{
     
    437425
    438426        if (USB_HID_ITEM_FLAG_CONSTANT(item->item_flags)) {
    439                 ret = item->logical_minimum;
     427                return item->logical_minimum;
    440428        }
    441429
    442430        if ((item->physical_minimum == 0) && (item->physical_maximum == 0)) {
    443431                item->physical_minimum = item->logical_minimum;
    444                 item->physical_maximum = item->logical_maximum;                 
    445         }
    446        
     432                item->physical_maximum = item->logical_maximum;
     433        }
     434
    447435        /* variable item */
    448436        if (item->physical_maximum == item->physical_minimum) {
    449             resolution = 1;
    450         } else {
    451             resolution = (item->logical_maximum - item->logical_minimum) /
    452                 ((item->physical_maximum - item->physical_minimum) *
    453                 (usb_pow(10, (item->unit_exponent))));
    454         }
    455 
    456         ret = ((value - item->physical_minimum) * resolution) + 
     437                resolution = 1;
     438        } else {
     439                resolution = (item->logical_maximum - item->logical_minimum) /
     440                    ((item->physical_maximum - item->physical_minimum) *
     441                    (usb_pow(10, (item->unit_exponent))));
     442        }
     443
     444        ret = ((value - item->physical_minimum) * resolution) +
    457445            item->logical_minimum;
    458446
    459447        usb_log_debug("\tvalue(%x), resolution(%x), phymin(%x) logmin(%x), "
    460             "ret(%x)\n", value, resolution, item->physical_minimum, 
     448            "ret(%x)\n", value, resolution, item->physical_minimum,
    461449            item->logical_minimum, ret);
    462        
     450
    463451        if ((item->logical_minimum < 0) || (item->logical_maximum < 0)) {
    464452                return USB_HID_INT32_TO_UINT32(ret, item->size);
     
    479467{
    480468        usb_hid_report_item_t *new_report_item;
    481        
     469
    482470        if (!(new_report_item = malloc(sizeof(usb_hid_report_item_t)))) {
    483471                return NULL;
    484         }                                       
     472        }
    485473        memcpy(new_report_item,item, sizeof(usb_hid_report_item_t));
    486474        link_initialize(&(new_report_item->link));
     
    497485 * @param field Current field. If NULL is given, the first one in the report
    498486 * is returned. Otherwise the next one i nthe list is returned.
    499  * @param path Usage path specifying which fields wa are interested in. 
     487 * @param path Usage path specifying which fields wa are interested in.
    500488 * @param flags Flags defining mode of usage paths comparison
    501489 * @param type Type of report we search.
     
    503491 * @retval Pointer to the founded report structure when founded
    504492 */
    505 usb_hid_report_field_t *usb_hid_report_get_sibling(usb_hid_report_t *report, 
    506     usb_hid_report_field_t *field, usb_hid_report_path_t *path, int flags, 
     493usb_hid_report_field_t *usb_hid_report_get_sibling(usb_hid_report_t *report,
     494    usb_hid_report_field_t *field, usb_hid_report_path_t *path, int flags,
    507495    usb_hid_report_type_t type)
    508496{
    509         usb_hid_report_description_t *report_des = 
     497        usb_hid_report_description_t *report_des =
    510498            usb_hid_report_find_description(report, path->report_id, type);
    511499
    512500        link_t *field_it;
    513        
     501
    514502        if (report_des == NULL) {
    515503                return NULL;
     
    523511
    524512        while (field_it != &report_des->report_items.head) {
    525                 field = list_get_instance(field_it, usb_hid_report_field_t, 
     513                field = list_get_instance(field_it, usb_hid_report_field_t,
    526514                    ritems_link);
    527515
     
    565553        usb_hid_report_description_t *report_des;
    566554        link_t *report_it;
    567        
     555
    568556        if (report_id > 0) {
    569                 report_des = usb_hid_report_find_description(report, report_id, 
     557                report_des = usb_hid_report_find_description(report, report_id,
    570558                    type);
    571559                if (report_des == NULL) {
     
    573561                } else {
    574562                        report_it = report_des->reports_link.next;
    575                 }       
     563                }
    576564        } else {
    577565                report_it = report->reports.head.next;
     
    579567
    580568        while (report_it != &report->reports.head) {
    581                 report_des = list_get_instance(report_it, 
     569                report_des = list_get_instance(report_it,
    582570                    usb_hid_report_description_t, reports_link);
    583571
     
    606594                return;
    607595        }
    608        
     596
    609597        report_item->usages_count = 0;
    610598        memset(report_item->usages, 0, USB_HID_MAX_USAGES);
    611        
     599
    612600        report_item->extended_usage_page = 0;
    613601        report_item->usage_minimum = 0;
  • uspace/lib/usbhid/src/hidpath.c

    rf5e5f73 rdf6ded8  
    7373 * @return Error code
    7474 */
    75 errno_t usb_hid_report_path_append_item(usb_hid_report_path_t *usage_path, 
    76                                     int32_t usage_page, int32_t usage)
    77 {       
    78         usb_hid_report_usage_path_t *item
    79                 = malloc(sizeof(usb_hid_report_usage_path_t));
     75errno_t usb_hid_report_path_append_item(usb_hid_report_path_t *usage_path,
     76    int32_t usage_page, int32_t usage)
     77{
     78        usb_hid_report_usage_path_t *item =
     79            malloc(sizeof(usb_hid_report_usage_path_t));
    8080
    8181        if (item == NULL) {
     
    8787        item->usage_page = usage_page;
    8888        item->flags = 0;
    89        
     89
    9090        list_append (&item->rpath_items_link, &usage_path->items);
    9191        usage_path->depth++;
     
    9696/**
    9797 * Removes last item from the usage path structure
    98  * @param usage_path 
     98 * @param usage_path
    9999 * @return void
    100100 */
     
    103103        link_t *item_link;
    104104        usb_hid_report_usage_path_t *item;
    105        
    106         if(!list_empty(&usage_path->items)){
     105
     106        if (!list_empty(&usage_path->items)) {
    107107                item_link = list_last(&usage_path->items);
    108108                item = list_get_instance(item_link,
     
    124124{
    125125        usb_hid_report_usage_path_t *item;
    126        
    127         if(!list_empty(&usage_path->items)){
     126
     127        if (!list_empty(&usage_path->items)) {
    128128                item = list_get_instance(list_last(&usage_path->items),
    129                         usb_hid_report_usage_path_t, rpath_items_link);
     129                    usb_hid_report_usage_path_t, rpath_items_link);
    130130
    131131                memset(item, 0, sizeof(usb_hid_report_usage_path_t));
     
    143143 * @return void
    144144 */
    145 void usb_hid_report_set_last_item(usb_hid_report_path_t *usage_path, 
    146                                   int32_t tag, int32_t data)
     145void usb_hid_report_set_last_item(usb_hid_report_path_t *usage_path,
     146    int32_t tag, int32_t data)
    147147{
    148148        usb_hid_report_usage_path_t *item;
    149        
    150         if(!list_empty(&usage_path->items)){
     149
     150        if (!list_empty(&usage_path->items)) {
    151151                item = list_get_instance(list_last(&usage_path->items),
    152152                     usb_hid_report_usage_path_t, rpath_items_link);
    153153
    154                 switch(tag) {
    155                         case USB_HID_TAG_CLASS_GLOBAL:
    156                                 item->usage_page = data;
    157                                 break;
    158                         case USB_HID_TAG_CLASS_LOCAL:
    159                                 item->usage = data;
    160                                 break;
    161                 }
    162         }
    163        
    164 }
    165 
    166 
    167 /**
    168  *
    169  *
    170  *
    171  *
    172  */
     154                switch (tag) {
     155                case USB_HID_TAG_CLASS_GLOBAL:
     156                        item->usage_page = data;
     157                        break;
     158                case USB_HID_TAG_CLASS_LOCAL:
     159                        item->usage = data;
     160                        break;
     161                }
     162        }
     163}
     164
    173165void usb_hid_print_usage_path(usb_hid_report_path_t *path)
    174166{
    175         usb_log_debug("USAGE_PATH FOR RId(%d):\n", path->report_id);
    176         usb_log_debug("\tLENGTH: %d\n", path->depth);
     167        usb_log_debug("USAGE_PATH FOR RId(%d):", path->report_id);
     168        usb_log_debug("\tLENGTH: %d", path->depth);
    177169
    178170        list_foreach(path->items, rpath_items_link,
    179171            usb_hid_report_usage_path_t, path_item) {
    180172
    181                 usb_log_debug("\tUSAGE_PAGE: %X\n", path_item->usage_page);
    182                 usb_log_debug("\tUSAGE: %X\n", path_item->usage);
    183                 usb_log_debug("\tFLAGS: %d\n", path_item->flags);
     173                usb_log_debug("\tUSAGE_PAGE: %X", path_item->usage_page);
     174                usb_log_debug("\tUSAGE: %X", path_item->usage);
     175                usb_log_debug("\tFLAGS: %d", path_item->flags);
    184176        }
    185177}
     
    199191        usb_hid_report_usage_path_t *report_item;
    200192        usb_hid_report_usage_path_t *path_item;
    201        
     193
    202194        link_t *report_link;
    203195        link_t *path_link;
    204        
     196
    205197        int only_page;
    206        
     198
    207199        if (report_path->report_id != path->report_id) {
    208200                if (path->report_id != 0) {
     
    210202                }
    211203        }
    212        
     204
    213205        // Empty path match all others
    214206        if (path->depth == 0) {
    215207                return 0;
    216208        }
    217        
     209
    218210        if ((only_page = flags & USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY) != 0) {
    219211                flags -= USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY;
    220212        }
    221        
     213
    222214        switch (flags) {
    223215        /* Path is somewhere in report_path */
     
    226218                        return 1;
    227219                }
    228                
     220
    229221                path_link = list_first(&path->items);
    230222                path_item = list_get_instance(path_link,
    231223                    usb_hid_report_usage_path_t, rpath_items_link);
    232                
     224
    233225                list_foreach(report_path->items, rpath_items_link,
    234226                    usb_hid_report_usage_path_t, report_item) {
    235227                        if (USB_HID_SAME_USAGE_PAGE(report_item->usage_page,
    236228                            path_item->usage_page)) {
    237                                
     229
    238230                                if (only_page == 0) {
    239231                                        if (USB_HID_SAME_USAGE(report_item->usage,
     
    245237                        }
    246238                }
    247                
     239
    248240                return 1;
    249241                break;
    250        
     242
    251243        /* The paths must be identical */
    252244        case USB_HID_PATH_COMPARE_STRICT:
     
    255247                }
    256248                /* Fallthrough */
    257        
     249
    258250        /* Path is prefix of the report_path */
    259251        case USB_HID_PATH_COMPARE_BEGIN:
    260252                report_link = report_path->items.head.next;
    261253                path_link = path->items.head.next;
    262                
     254
    263255                while ((report_link != &report_path->items.head) &&
    264256                    (path_link != &path->items.head)) {
    265                        
     257
    266258                        report_item = list_get_instance(report_link,
    267259                            usb_hid_report_usage_path_t, rpath_items_link);
    268                        
     260
    269261                        path_item = list_get_instance(path_link,
    270262                            usb_hid_report_usage_path_t, rpath_items_link);
    271                        
     263
    272264                        if (!USB_HID_SAME_USAGE_PAGE(report_item->usage_page,
    273265                            path_item->usage_page) || ((only_page == 0) &&
     
    280272                        }
    281273                }
    282                
     274
    283275                if ((((flags & USB_HID_PATH_COMPARE_BEGIN) != 0) &&
    284276                    (path_link == &path->items.head)) ||
     
    290282                }
    291283                break;
    292        
     284
    293285        /* Path is suffix of report_path */
    294286        case USB_HID_PATH_COMPARE_END:
    295287                report_link = report_path->items.head.prev;
    296288                path_link = path->items.head.prev;
    297                
     289
    298290                if (list_empty(&path->items)) {
    299291                        return 0;
    300292                }
    301                
     293
    302294                while ((report_link != &report_path->items.head) &&
    303295                      (path_link != &path->items.head)) {
    304296                        report_item = list_get_instance(report_link,
    305297                            usb_hid_report_usage_path_t, rpath_items_link);
    306                        
     298
    307299                        path_item = list_get_instance(path_link,
    308300                            usb_hid_report_usage_path_t, rpath_items_link);
    309                        
     301
    310302                        if (!USB_HID_SAME_USAGE_PAGE(report_item->usage_page,
    311303                            path_item->usage_page) || ((only_page == 0) &&
     
    318310                        }
    319311                }
    320                
     312
    321313                if (path_link == &path->items.head) {
    322314                        return 0;
     
    325317                }
    326318                break;
    327        
     319
    328320        default:
    329321                return -1;
     
    340332        usb_hid_report_path_t *path;
    341333        path = malloc(sizeof(usb_hid_report_path_t));
    342         if(path == NULL){
     334        if (path == NULL) {
    343335                return NULL;
    344336        }
     
    363355        if (path == NULL)
    364356                return;
    365         while(!list_empty(&path->items)){
     357        while (!list_empty(&path->items)) {
    366358                usb_hid_report_remove_last_item(path);
    367359        }
     
    379371 */
    380372usb_hid_report_path_t *usb_hid_report_path_clone(
    381         usb_hid_report_path_t *usage_path)
     373    usb_hid_report_path_t *usage_path)
    382374{
    383375        usb_hid_report_usage_path_t *new_path_item;
    384376        usb_hid_report_path_t *new_usage_path = usb_hid_report_path ();
    385377
    386         if(new_usage_path == NULL){
     378        if (new_usage_path == NULL) {
    387379                return NULL;
    388380        }
    389381
    390382        new_usage_path->report_id = usage_path->report_id;
    391        
    392         if(list_empty(&usage_path->items)){
     383
     384        if (list_empty(&usage_path->items)) {
    393385                return new_usage_path;
    394386        }
     
    398390
    399391                new_path_item = malloc(sizeof(usb_hid_report_usage_path_t));
    400                 if(new_path_item == NULL) {
     392                if (new_path_item == NULL) {
    401393                        return NULL;
    402394                }
    403                
     395
    404396                link_initialize(&new_path_item->rpath_items_link);
    405397                new_path_item->usage_page = path_item->usage_page;
    406                 new_path_item->usage = path_item->usage;               
    407                 new_path_item->flags = path_item->flags;               
    408                
     398                new_path_item->usage = path_item->usage;
     399                new_path_item->flags = path_item->flags;
     400
    409401                list_append(&new_path_item->rpath_items_link,
    410402                    &new_usage_path->items);
     
    423415 * @return Error code
    424416 */
    425 errno_t usb_hid_report_path_set_report_id(usb_hid_report_path_t *path, 
    426         uint8_t report_id)
    427 {
    428         if(path == NULL){
     417errno_t usb_hid_report_path_set_report_id(usb_hid_report_path_t *path,
     418    uint8_t report_id)
     419{
     420        if (path == NULL) {
    429421                return EINVAL;
    430422        }
  • uspace/lib/usbhid/src/hidreport.c

    rf5e5f73 rdf6ded8  
    7171        const uint8_t *d =
    7272            usb_dp_get_nested_descriptor(&parser, &parser_data,
    73                 usb_device_descriptors(dev)->full_config);
     73            usb_device_descriptors(dev)->full_config);
    7474       
    7575        /*
     
    8484       
    8585        if (d == NULL) {
    86                 usb_log_error("The %d. interface descriptor not found!\n",
     86                usb_log_error("The %d. interface descriptor not found!",
    8787                    usb_device_get_iface_number(dev));
    8888                return ENOENT;
     
    104104       
    105105        if (d == NULL) {
    106                 usb_log_fatal("No HID descriptor found!\n");
     106                usb_log_fatal("No HID descriptor found!");
    107107                return ENOENT;
    108108        }
     
    130130        }
    131131       
    132         usb_log_debug("Getting Report descriptor, expected size: %u\n", length);
     132        usb_log_debug("Getting Report descriptor, expected size: %u", length);
    133133       
    134134        /*
     
    156156        *size = length;
    157157       
    158         usb_log_debug("Done.\n");
     158        usb_log_debug("Done.");
    159159       
    160160        return EOK;
     
    163163
    164164
    165 errno_t usb_hid_process_report_descriptor(usb_device_t *dev, 
     165errno_t usb_hid_process_report_descriptor(usb_device_t *dev,
    166166    usb_hid_report_t *report, uint8_t **report_desc, size_t *report_size)
    167167{
     
    178178       
    179179        if (rc != EOK) {
    180                 usb_log_error("Problem with getting Report descriptor: %s.\n",
     180                usb_log_error("Problem with getting Report descriptor: %s.",
    181181                    str_error(rc));
    182182                if (*report_desc != NULL) {
     
    191191        rc = usb_hid_parse_report_descriptor(report, *report_desc, *report_size);
    192192        if (rc != EOK) {
    193                 usb_log_error("Problem parsing Report descriptor: %s.\n",
     193                usb_log_error("Problem parsing Report descriptor: %s.",
    194194                    str_error(rc));
    195195                free(*report_desc);
  • uspace/lib/usbhid/src/hidreq.c

    rf5e5f73 rdf6ded8  
    6262{
    6363        if (ctrl_pipe == NULL) {
    64                 usb_log_warning("usbhid_req_set_report(): no pipe given.\n");
    65                 return EINVAL;
    66         }
    67        
    68         if (iface_no < 0) {
    69                 usb_log_warning("usbhid_req_set_report(): no interface given."
    70                     "\n");
    71                 return EINVAL;
    72         }
    73        
    74         /*
    75          * No need for checking other parameters, as they are checked in
    76          * the called function (usb_control_request_set()).
    77          */
    78        
    79         errno_t rc;
    80        
     64                usb_log_warning("usbhid_req_set_report(): no pipe given.");
     65                return EINVAL;
     66        }
     67
     68        if (iface_no < 0) {
     69                usb_log_warning("usbhid_req_set_report(): no interface given."
     70                    "\n");
     71                return EINVAL;
     72        }
     73
     74        /*
     75         * No need for checking other parameters, as they are checked in
     76         * the called function (usb_control_request_set()).
     77         */
     78
     79        errno_t rc;
     80
    8181        uint16_t value = 0;
    8282        value |= (type << 8);
    8383
    84         usb_log_debug("Sending Set Report request to the device.\n");
    85        
     84        usb_log_debug("Sending Set Report request to the device.");
     85
    8686        rc = usb_control_request_set(ctrl_pipe,
    8787            USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE,
     
    9393                return rc;
    9494        }
    95        
     95
    9696        return EOK;
    9797}
     
    112112{
    113113        if (ctrl_pipe == NULL) {
    114                 usb_log_warning("usbhid_req_set_report(): no pipe given.\n");
    115                 return EINVAL;
    116         }
    117        
    118         if (iface_no < 0) {
    119                 usb_log_warning("usbhid_req_set_report(): no interface given."
    120                     "\n");
    121                 return EINVAL;
    122         }
    123        
    124         /*
    125          * No need for checking other parameters, as they are checked in
    126          * the called function (usb_control_request_set()).
    127          */
    128        
     114                usb_log_warning("usbhid_req_set_report(): no pipe given.");
     115                return EINVAL;
     116        }
     117
     118        if (iface_no < 0) {
     119                usb_log_warning("usbhid_req_set_report(): no interface given."
     120                    "\n");
     121                return EINVAL;
     122        }
     123
     124        /*
     125         * No need for checking other parameters, as they are checked in
     126         * the called function (usb_control_request_set()).
     127         */
     128
    129129        errno_t rc;
    130130
    131131        usb_log_debug("Sending Set Protocol request to the device ("
    132132            "protocol: %d, iface: %d).\n", protocol, iface_no);
    133        
    134         rc = usb_control_request_set(ctrl_pipe, 
    135             USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE, 
     133
     134        rc = usb_control_request_set(ctrl_pipe,
     135            USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE,
    136136            USB_HIDREQ_SET_PROTOCOL, protocol, iface_no, NULL, 0);
    137137
     
    141141                return rc;
    142142        }
    143        
     143
    144144        return EOK;
    145145}
     
    160160{
    161161        if (ctrl_pipe == NULL) {
    162                 usb_log_warning("usbhid_req_set_report(): no pipe given.\n");
    163                 return EINVAL;
    164         }
    165        
    166         if (iface_no < 0) {
    167                 usb_log_warning("usbhid_req_set_report(): no interface given."
    168                     "\n");
    169                 return EINVAL;
    170         }
    171        
    172         /*
    173          * No need for checking other parameters, as they are checked in
    174          * the called function (usb_control_request_set()).
    175          */
    176        
     162                usb_log_warning("usbhid_req_set_report(): no pipe given.");
     163                return EINVAL;
     164        }
     165
     166        if (iface_no < 0) {
     167                usb_log_warning("usbhid_req_set_report(): no interface given."
     168                    "\n");
     169                return EINVAL;
     170        }
     171
     172        /*
     173         * No need for checking other parameters, as they are checked in
     174         * the called function (usb_control_request_set()).
     175         */
     176
    177177        errno_t rc;
    178178
    179179        usb_log_debug("Sending Set Idle request to the device ("
    180180            "duration: %u, iface: %d).\n", duration, iface_no);
    181        
     181
    182182        uint16_t value = duration << 8;
    183        
     183
    184184        rc = usb_control_request_set(ctrl_pipe,
    185185            USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE,
     
    191191                return rc;
    192192        }
    193        
     193
    194194        return EOK;
    195195}
     
    203203 * @param[in][out] buffer Buffer for the report data.
    204204 * @param[in] buf_size Size of the buffer (in bytes).
    205  * @param[out] actual_size Actual size of report received from the device 
     205 * @param[out] actual_size Actual size of report received from the device
    206206 *                         (in bytes).
    207207 *
     
    210210 * @return Other value inherited from function usb_control_request_set().
    211211 */
    212 errno_t usbhid_req_get_report(usb_pipe_t *ctrl_pipe, int iface_no, 
    213     usb_hid_report_type_t type, uint8_t *buffer, size_t buf_size, 
     212errno_t usbhid_req_get_report(usb_pipe_t *ctrl_pipe, int iface_no,
     213    usb_hid_report_type_t type, uint8_t *buffer, size_t buf_size,
    214214    size_t *actual_size)
    215215{
    216216        if (ctrl_pipe == NULL) {
    217                 usb_log_warning("usbhid_req_set_report(): no pipe given.\n");
    218                 return EINVAL;
    219         }
    220        
    221         if (iface_no < 0) {
    222                 usb_log_warning("usbhid_req_set_report(): no interface given."
    223                     "\n");
    224                 return EINVAL;
    225         }
    226        
    227         /*
    228          * No need for checking other parameters, as they are checked in
    229          * the called function (usb_control_request_set()).
    230          */
    231        
     217                usb_log_warning("usbhid_req_set_report(): no pipe given.");
     218                return EINVAL;
     219        }
     220
     221        if (iface_no < 0) {
     222                usb_log_warning("usbhid_req_set_report(): no interface given."
     223                    "\n");
     224                return EINVAL;
     225        }
     226
     227        /*
     228         * No need for checking other parameters, as they are checked in
     229         * the called function (usb_control_request_set()).
     230         */
     231
    232232        errno_t rc;
    233233
    234234        uint16_t value = 0;
    235235        value |= (type << 8);
    236        
    237         usb_log_debug("Sending Get Report request to the device.\n");
    238        
    239         rc = usb_control_request_get(ctrl_pipe, 
    240             USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE, 
     236
     237        usb_log_debug("Sending Get Report request to the device.");
     238
     239        rc = usb_control_request_get(ctrl_pipe,
     240            USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE,
    241241            USB_HIDREQ_GET_REPORT, value, iface_no, buffer, buf_size,
    242242            actual_size);
     
    247247                return rc;
    248248        }
    249        
     249
    250250        return EOK;
    251251}
     
    262262 * @return Other value inherited from function usb_control_request_set().
    263263 */
    264 errno_t usbhid_req_get_protocol(usb_pipe_t *ctrl_pipe, int iface_no, 
     264errno_t usbhid_req_get_protocol(usb_pipe_t *ctrl_pipe, int iface_no,
    265265    usb_hid_protocol_t *protocol)
    266266{
    267267        if (ctrl_pipe == NULL) {
    268                 usb_log_warning("usbhid_req_set_report(): no pipe given.\n");
    269                 return EINVAL;
    270         }
    271        
    272         if (iface_no < 0) {
    273                 usb_log_warning("usbhid_req_set_report(): no interface given."
    274                     "\n");
    275                 return EINVAL;
    276         }
    277        
    278         /*
    279          * No need for checking other parameters, as they are checked in
    280          * the called function (usb_control_request_set()).
    281          */
    282        
    283         errno_t rc;     
     268                usb_log_warning("usbhid_req_set_report(): no pipe given.");
     269                return EINVAL;
     270        }
     271
     272        if (iface_no < 0) {
     273                usb_log_warning("usbhid_req_set_report(): no interface given."
     274                    "\n");
     275                return EINVAL;
     276        }
     277
     278        /*
     279         * No need for checking other parameters, as they are checked in
     280         * the called function (usb_control_request_set()).
     281         */
     282
     283        errno_t rc;
    284284
    285285        usb_log_debug("Sending Get Protocol request to the device ("
    286286            "iface: %d).\n", iface_no);
    287        
     287
    288288        uint8_t buffer[1];
    289289        size_t actual_size = 0;
    290        
    291         rc = usb_control_request_get(ctrl_pipe, 
    292             USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE, 
     290
     291        rc = usb_control_request_get(ctrl_pipe,
     292            USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE,
    293293            USB_HIDREQ_GET_PROTOCOL, 0, iface_no, buffer, 1, &actual_size);
    294294
     
    298298                return rc;
    299299        }
    300        
     300
    301301        if (actual_size != 1) {
    302                 usb_log_warning("Wrong data size: %zu, expected: 1.\n",
    303                         actual_size);
     302                usb_log_warning("Wrong data size: %zu, expected: 1.",
     303                    actual_size);
    304304                return ELIMIT;
    305305        }
    306        
     306
    307307        *protocol = buffer[0];
    308        
     308
    309309        return EOK;
    310310}
     
    320320 * @retval EOK if successful.
    321321 * @retval EINVAL if no HID device is given.
    322  * @return Other value inherited from one of functions 
     322 * @return Other value inherited from one of functions
    323323 *         usb_pipe_start_session(), usb_pipe_end_session(),
    324324 *         usb_control_request_set().
    325325 */
    326 errno_t usbhid_req_get_idle(usb_pipe_t *ctrl_pipe, int iface_no, uint8_t *duration)
    327 {
    328         if (ctrl_pipe == NULL) {
    329                 usb_log_warning("usbhid_req_set_report(): no pipe given.\n");
    330                 return EINVAL;
    331         }
    332        
    333         if (iface_no < 0) {
    334                 usb_log_warning("usbhid_req_set_report(): no interface given."
    335                     "\n");
    336                 return EINVAL;
    337         }
    338        
    339         /*
    340          * No need for checking other parameters, as they are checked in
    341          * the called function (usb_control_request_set()).
    342          */
    343        
     326errno_t usbhid_req_get_idle(usb_pipe_t *ctrl_pipe, int iface_no,
     327    uint8_t *duration)
     328{
     329        if (ctrl_pipe == NULL) {
     330                usb_log_warning("usbhid_req_set_report(): no pipe given.");
     331                return EINVAL;
     332        }
     333
     334        if (iface_no < 0) {
     335                usb_log_warning("usbhid_req_set_report(): no interface given."
     336                    "\n");
     337                return EINVAL;
     338        }
     339
     340        /*
     341         * No need for checking other parameters, as they are checked in
     342         * the called function (usb_control_request_set()).
     343         */
     344
    344345        errno_t rc;
    345346
    346347        usb_log_debug("Sending Get Idle request to the device ("
    347348            "iface: %d).\n", iface_no);
    348        
     349
    349350        uint16_t value = 0;
    350351        uint8_t buffer[1];
    351352        size_t actual_size = 0;
    352        
    353         rc = usb_control_request_get(ctrl_pipe, 
    354             USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE, 
    355             USB_HIDREQ_GET_IDLE, value, iface_no, buffer, 1, 
     353
     354        rc = usb_control_request_get(ctrl_pipe,
     355            USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE,
     356            USB_HIDREQ_GET_IDLE, value, iface_no, buffer, 1,
    356357            &actual_size);
    357358
     
    361362                return rc;
    362363        }
    363        
     364
    364365        if (actual_size != 1) {
    365                 usb_log_warning("Wrong data size: %zu, expected: 1.\n",
    366                         actual_size);
     366                usb_log_warning("Wrong data size: %zu, expected: 1.",
     367                    actual_size);
    367368                return ELIMIT;
    368369        }
    369        
     370
    370371        *duration = buffer[0];
    371        
     372
    372373        return EOK;
    373374}
Note: See TracChangeset for help on using the changeset viewer.