Changeset ae3a941 in mainline for uspace/lib/usbhid


Ignore:
Timestamp:
2018-02-26T16:51:40Z (8 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e773f58
Parents:
3692678
Message:

usb: cstyle

Location:
uspace/lib/usbhid/src
Files:
4 edited

Legend:

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

    r3692678 rae3a941  
    5252int usb_hid_translate_data(usb_hid_report_field_t *item, const uint8_t *data);
    5353
    54 uint32_t usb_hid_translate_data_reverse(usb_hid_report_field_t *item, 
    55         int32_t value);
     54uint32_t usb_hid_translate_data_reverse(usb_hid_report_field_t *item,
     55    int32_t value);
    5656
    5757
     
    7676 *
    7777 * @param parser Opaque report parser structure
    78  * @param report_id 
     78 * @param report_id
    7979 * @param type
    8080 * @return Number of items in specified report
    8181 */
    82 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,
    8383    usb_hid_report_type_t type)
    8484{
     
    100100 *
    101101 * @param parser Opaque report parser structure
    102  * @param report_id 
     102 * @param report_id
    103103 * @param type
    104104 * @return Number of items in specified report
    105105 */
    106 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,
    107107    usb_hid_report_type_t type)
    108108{
     
    117117                return 0;
    118118        } else {
    119                 return ((report_des->bit_length + 7) / 8) ;
     119                return ((report_des->bit_length + 7) / 8);
    120120        }
    121121}
     
    129129 * @param data Data for the report.
    130130 * @return Error code.
    131  */ 
    132 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,
    133133    size_t size, uint8_t *report_id)
    134134{
    135135        usb_hid_report_description_t *report_des;
    136136        usb_hid_report_type_t type = USB_HID_REPORT_TYPE_INPUT;
    137        
     137
    138138        if (report == NULL) {
    139139                return EINVAL;
     
    146146        }
    147147
    148         report_des = usb_hid_report_find_description(report, *report_id, 
     148        report_des = usb_hid_report_find_description(report, *report_id,
    149149            type);
    150150
     
    158158
    159159                if (USB_HID_ITEM_FLAG_CONSTANT(item->item_flags) == 0) {
    160                        
     160
    161161                        if (USB_HID_ITEM_FLAG_VARIABLE(item->item_flags) == 0) {
    162162                                /* array */
    163                                 item->value = 
    164                                         usb_hid_translate_data(item, data);
    165                                
     163                                item->value =
     164                                    usb_hid_translate_data(item, data);
     165
    166166                                item->usage = USB_HID_EXTENDED_USAGE(
    167167                                    item->usages[item->value -
    168168                                    item->physical_minimum]);
    169169
    170                                 item->usage_page = 
     170                                item->usage_page =
    171171                                    USB_HID_EXTENDED_USAGE_PAGE(
    172172                                    item->usages[item->value -
     
    174174
    175175                                usb_hid_report_set_last_item(
    176                                     item->collection_path, 
    177                                     USB_HID_TAG_CLASS_GLOBAL, 
     176                                    item->collection_path,
     177                                    USB_HID_TAG_CLASS_GLOBAL,
    178178                                    item->usage_page);
    179179
    180180                                usb_hid_report_set_last_item(
    181                                     item->collection_path, 
     181                                    item->collection_path,
    182182                                    USB_HID_TAG_CLASS_LOCAL, item->usage);
    183183                        } else {
    184184                                /* variable item */
    185                                 item->value = usb_hid_translate_data(item, 
     185                                item->value = usb_hid_translate_data(item,
    186186                                    data);
    187187                        }
    188188                }
    189189        }
    190        
     190
    191191        return EOK;
    192192}
     
    214214        int resolution;
    215215        if (item->physical_maximum == item->physical_minimum) {
    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))));
     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))));
    221221        }
    222222
     
    255255        }
    256256
    257         return (int) (((value - item->logical_minimum) / resolution) + 
     257        return (int) (((value - item->logical_minimum) / resolution) +
    258258            item->physical_minimum);
    259259}
     
    262262/* OUTPUT API */
    263263
    264 /** 
     264/**
    265265 * Allocates output report buffer for output report
    266266 *
     
    270270 * @return Returns allocated output buffer for specified output
    271271 */
    272 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,
    273273    uint8_t report_id)
    274274{
     
    322322 * @return Error code
    323323 */
    324 errno_t usb_hid_report_output_translate(usb_hid_report_t *report, 
     324errno_t usb_hid_report_output_translate(usb_hid_report_t *report,
    325325    uint8_t report_id, uint8_t *buffer, size_t size)
    326326{
     
    329329        int length;
    330330        int32_t tmp_value;
    331        
     331
    332332        if (report == NULL) {
    333333                return EINVAL;
     
    339339
    340340        usb_hid_report_description_t *report_des;
    341         report_des = usb_hid_report_find_description(report, report_id, 
     341        report_des = usb_hid_report_find_description(report, report_id,
    342342            USB_HID_REPORT_TYPE_OUTPUT);
    343        
     343
    344344        if (report_des == NULL) {
    345345                return EINVAL;
     
    348348        list_foreach(report_des->report_items, ritems_link,
    349349            usb_hid_report_field_t, report_item) {
    350                 value = usb_hid_translate_data_reverse(report_item, 
     350                value = usb_hid_translate_data_reverse(report_item,
    351351                    report_item->value);
    352352
    353353                offset = report_des->bit_length - report_item->offset - 1;
    354354                length = report_item->size;
    355                
     355
    356356                usb_log_debug("\ttranslated value: %x", value);
    357357
    358358                if ((offset / 8) == ((offset + length - 1) / 8)) {
    359                         if (((size_t) (offset / 8) >= size) || 
     359                        if (((size_t) (offset / 8) >= size) ||
    360360                            ((size_t) (offset + length - 1) / 8) >= size) {
    361361                                break; // TODO ErrorCode
     
    364364                        value = value << shift;
    365365                        value = value & (((1 << length) - 1) << shift);
    366                        
     366
    367367                        uint8_t mask = 0;
    368368                        mask = 0xff - (((1 << length) - 1) << shift);
     
    376376                                if (i == (offset / 8)) {
    377377                                        tmp_value = value;
    378                                         tmp_value = tmp_value & 
     378                                        tmp_value = tmp_value &
    379379                                            ((1 << (8 - (offset % 8))) - 1);
    380380
    381381                                        tmp_value = tmp_value << (offset % 8);
    382                                        
     382
    383383                                        mask = ~(((1 << (8 - (offset % 8))) - 1)
    384384                                            << (offset % 8));
    385385
    386                                         buffer[i] = (buffer[i] & mask) | 
     386                                        buffer[i] = (buffer[i] & mask) |
    387387                                            tmp_value;
    388388                                } else if (i == ((offset + length - 1) / 8)) {
    389                                        
    390                                         value = value >> (length - 
     389
     390                                        value = value >> (length -
    391391                                            ((offset + length) % 8));
    392392
    393                                         value = value & ((1 << (length - 
     393                                        value = value & ((1 << (length -
    394394                                            ((offset + length) % 8))) - 1);
    395                                        
    396                                         mask = (1 << (length - 
     395
     396                                        mask = (1 << (length -
    397397                                            ((offset + length) % 8))) - 1;
    398398
     
    407407                report_item->value = 0;
    408408        }
    409        
     409
    410410        return EOK;
    411411}
     
    418418 * @return ranslated value
    419419 */
    420 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,
    421421    int value)
    422422{
     
    430430        if ((item->physical_minimum == 0) && (item->physical_maximum == 0)) {
    431431                item->physical_minimum = item->logical_minimum;
    432                 item->physical_maximum = item->logical_maximum;                 
    433         }
    434        
     432                item->physical_maximum = item->logical_maximum;
     433        }
     434
    435435        /* variable item */
    436436        if (item->physical_maximum == item->physical_minimum) {
    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) + 
     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) +
    445445            item->logical_minimum;
    446446
    447447        usb_log_debug("\tvalue(%x), resolution(%x), phymin(%x) logmin(%x), "
    448             "ret(%x)\n", value, resolution, item->physical_minimum, 
     448            "ret(%x)\n", value, resolution, item->physical_minimum,
    449449            item->logical_minimum, ret);
    450        
     450
    451451        if ((item->logical_minimum < 0) || (item->logical_maximum < 0)) {
    452452                return USB_HID_INT32_TO_UINT32(ret, item->size);
     
    467467{
    468468        usb_hid_report_item_t *new_report_item;
    469        
     469
    470470        if (!(new_report_item = malloc(sizeof(usb_hid_report_item_t)))) {
    471471                return NULL;
    472         }                                       
     472        }
    473473        memcpy(new_report_item,item, sizeof(usb_hid_report_item_t));
    474474        link_initialize(&(new_report_item->link));
     
    485485 * @param field Current field. If NULL is given, the first one in the report
    486486 * is returned. Otherwise the next one i nthe list is returned.
    487  * @param path Usage path specifying which fields wa are interested in. 
     487 * @param path Usage path specifying which fields wa are interested in.
    488488 * @param flags Flags defining mode of usage paths comparison
    489489 * @param type Type of report we search.
     
    491491 * @retval Pointer to the founded report structure when founded
    492492 */
    493 usb_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, 
     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,
    495495    usb_hid_report_type_t type)
    496496{
    497         usb_hid_report_description_t *report_des = 
     497        usb_hid_report_description_t *report_des =
    498498            usb_hid_report_find_description(report, path->report_id, type);
    499499
    500500        link_t *field_it;
    501        
     501
    502502        if (report_des == NULL) {
    503503                return NULL;
     
    511511
    512512        while (field_it != &report_des->report_items.head) {
    513                 field = list_get_instance(field_it, usb_hid_report_field_t, 
     513                field = list_get_instance(field_it, usb_hid_report_field_t,
    514514                    ritems_link);
    515515
     
    553553        usb_hid_report_description_t *report_des;
    554554        link_t *report_it;
    555        
     555
    556556        if (report_id > 0) {
    557                 report_des = usb_hid_report_find_description(report, report_id, 
     557                report_des = usb_hid_report_find_description(report, report_id,
    558558                    type);
    559559                if (report_des == NULL) {
     
    561561                } else {
    562562                        report_it = report_des->reports_link.next;
    563                 }       
     563                }
    564564        } else {
    565565                report_it = report->reports.head.next;
     
    567567
    568568        while (report_it != &report->reports.head) {
    569                 report_des = list_get_instance(report_it, 
     569                report_des = list_get_instance(report_it,
    570570                    usb_hid_report_description_t, reports_link);
    571571
     
    594594                return;
    595595        }
    596        
     596
    597597        report_item->usages_count = 0;
    598598        memset(report_item->usages, 0, USB_HID_MAX_USAGES);
    599        
     599
    600600        report_item->extended_usage_page = 0;
    601601        report_item->usage_minimum = 0;
  • uspace/lib/usbhid/src/hidpath.c

    r3692678 rae3a941  
    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{
     
    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

    r3692678 rae3a941  
    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        /*
     
    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{
  • uspace/lib/usbhid/src/hidreq.c

    r3692678 rae3a941  
    6565                return EINVAL;
    6666        }
    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        
     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
    8484        usb_log_debug("Sending Set Report request to the device.");
    85        
     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}
     
    115115                return EINVAL;
    116116        }
    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        
     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}
     
    163163                return EINVAL;
    164164        }
    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        
     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{
     
    218218                return EINVAL;
    219219        }
    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        
     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        
     236
    237237        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, 
     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{
     
    269269                return EINVAL;
    270270        }
    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;     
     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) {
    302302                usb_log_warning("Wrong data size: %zu, expected: 1.",
    303                         actual_size);
     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.");
    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) {
    365366                usb_log_warning("Wrong data size: %zu, expected: 1.",
    366                         actual_size);
     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.