Changeset feeac0d in mainline for uspace/lib/usbhid


Ignore:
Timestamp:
2013-09-10T16:32:35Z (12 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4982d87
Parents:
e8d6ce2
Message:

Simplify use of list_foreach.

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

Legend:

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

    re8d6ce2 rfeeac0d  
    333333        }
    334334
    335         usb_hid_report_description_t *report_des = NULL;
    336        
    337         list_foreach(report->reports, report_it) {
    338                 report_des = list_get_instance(report_it,
    339                                 usb_hid_report_description_t, reports_link);
    340 
     335        list_foreach(report->reports, reports_link,
     336            usb_hid_report_description_t, report_des) {
    341337                // if report id not set, return the first of the type
    342338                if(((report_des->report_id == report_id) || (report_id == 0)) &&
     
    902898void usb_hid_descriptor_print_list(list_t *list)
    903899{
    904         usb_hid_report_field_t *report_item;
    905 
    906900        if(list == NULL || list_empty(list)) {
    907901            usb_log_debug("\tempty\n");
     
    909903        }
    910904
    911         list_foreach(*list, item) {
    912                 report_item = list_get_instance(item, usb_hid_report_field_t,
    913                                 ritems_link);
    914 
     905        list_foreach(*list, ritems_link, usb_hid_report_field_t,
     906            report_item) {
    915907                usb_log_debug("\t\tOFFSET: %X\n", report_item->offset);
    916908                usb_log_debug("\t\tSIZE: %zu\n", report_item->size);
     
    937929
    938930                usb_log_debug("\n");
    939 
    940         }
    941 
     931        }
    942932}
    943933
     
    951941void usb_hid_descriptor_print(usb_hid_report_t *report)
    952942{
    953         if(report == NULL) {
     943        if (report == NULL)
    954944                return;
    955         }
    956 
    957         usb_hid_report_description_t *report_des;
    958 
    959         list_foreach(report->reports, report_it) {
    960                 report_des = list_get_instance(report_it,
    961                         usb_hid_report_description_t, reports_link);
     945
     946        list_foreach(report->reports, reports_link,
     947            usb_hid_report_description_t, report_des) {
    962948                usb_log_debug("Report ID: %d\n", report_des->report_id);
    963949                usb_log_debug("\tType: %d\n", report_des->type);
  • uspace/lib/usbhid/src/hidparser.c

    re8d6ce2 rfeeac0d  
    130130    size_t size, uint8_t *report_id)
    131131{
    132         usb_hid_report_field_t *item;
    133 
    134132        usb_hid_report_description_t *report_des;
    135133        usb_hid_report_type_t type = USB_HID_REPORT_TYPE_INPUT;
    136        
     134
    137135        if (report == NULL) {
    138136                return EINVAL;
     
    153151
    154152        /* read data */
    155         list_foreach(report_des->report_items, list_item) {
    156                 item = list_get_instance(list_item, usb_hid_report_field_t,
    157                     ritems_link);
     153        list_foreach(report_des->report_items, ritems_link,
     154            usb_hid_report_field_t, item) {
    158155
    159156                if (USB_HID_ITEM_FLAG_CONSTANT(item->item_flags) == 0) {
    160                        
     157
    161158                        if (USB_HID_ITEM_FLAG_VARIABLE(item->item_flags) == 0) {
    162159                                /* array */
    163160                                item->value =
    164161                                        usb_hid_translate_data(item, data);
    165                
     162
    166163                                item->usage = USB_HID_EXTENDED_USAGE(
    167164                                    item->usages[item->value -
     
    184181                                /* variable item */
    185182                                item->value = usb_hid_translate_data(item,
    186                                     data);                             
    187                         }                       
     183                                    data);
     184                        }
    188185                }
    189186        }
    190        
     187
    191188        return EOK;
    192189}
     
    295292        usb_hid_report_description_t *report_des = NULL;
    296293
    297         list_foreach(report->reports, report_it) {
    298                 report_des = list_get_instance(report_it,
    299                     usb_hid_report_description_t, reports_link);
    300                
     294        list_foreach(report->reports, reports_link,
     295            usb_hid_report_description_t, report_des) {
    301296                if ((report_des->report_id == report_id) &&
    302297                    (report_des->type == USB_HID_REPORT_TYPE_OUTPUT)) {
     
    345340        int length;
    346341        int32_t tmp_value;
    347        
     342
    348343        if (report == NULL) {
    349344                return EINVAL;
     
    351346
    352347        if (report->use_report_ids != 0) {
    353                 buffer[0] = report_id;         
     348                buffer[0] = report_id;
    354349        }
    355350
     
    357352        report_des = usb_hid_report_find_description(report, report_id,
    358353            USB_HID_REPORT_TYPE_OUTPUT);
    359        
     354
    360355        if (report_des == NULL) {
    361356                return EINVAL;
    362357        }
    363358
    364         usb_hid_report_field_t *report_item;
    365 
    366         list_foreach(report_des->report_items, item) {
    367                 report_item = list_get_instance(item, usb_hid_report_field_t,
    368                     ritems_link);
    369 
     359        list_foreach(report_des->report_items, ritems_link,
     360            usb_hid_report_field_t, report_item) {
    370361                value = usb_hid_translate_data_reverse(report_item,
    371362                    report_item->value);
     
    373364                offset = report_des->bit_length - report_item->offset - 1;
    374365                length = report_item->size;
    375                
     366
    376367                usb_log_debug("\ttranslated value: %x\n", value);
    377368
     
    382373                        }
    383374                        size_t shift = 8 - offset % 8 - length;
    384                         value = value << shift;                                                 
     375                        value = value << shift;
    385376                        value = value & (((1 << length) - 1) << shift);
    386                                
     377
    387378                        uint8_t mask = 0;
    388379                        mask = 0xff - (((1 << length) - 1) << shift);
     
    400391
    401392                                        tmp_value = tmp_value << (offset % 8);
    402        
     393
    403394                                        mask = ~(((1 << (8 - (offset % 8))) - 1)
    404395                                            << (offset % 8));
     
    407398                                            tmp_value;
    408399                                } else if (i == ((offset + length - 1) / 8)) {
    409                                        
     400
    410401                                        value = value >> (length -
    411402                                            ((offset + length) % 8));
     
    413404                                        value = value & ((1 << (length -
    414405                                            ((offset + length) % 8))) - 1);
    415                                
     406
    416407                                        mask = (1 << (length -
    417408                                            ((offset + length) % 8))) - 1;
     
    427418                report_item->value = 0;
    428419        }
    429        
     420
    430421        return EOK;
    431422}
  • uspace/lib/usbhid/src/hidpath.c

    re8d6ce2 rfeeac0d  
    176176        usb_log_debug("\tLENGTH: %d\n", path->depth);
    177177
    178         usb_hid_report_usage_path_t *path_item;
    179 
    180         list_foreach(path->items, item) {
    181                 path_item = list_get_instance(item, usb_hid_report_usage_path_t,
    182                         rpath_items_link);
     178        list_foreach(path->items, rpath_items_link,
     179            usb_hid_report_usage_path_t, path_item) {
    183180
    184181                usb_log_debug("\tUSAGE_PAGE: %X\n", path_item->usage_page);
     
    237234                        usb_hid_report_usage_path_t, rpath_items_link);
    238235
    239                 list_foreach(report_path->items, report_link) {
    240                         report_item = list_get_instance(report_link,
    241                                 usb_hid_report_usage_path_t, rpath_items_link);
    242                                
     236                list_foreach(report_path->items, rpath_items_link,
     237                    usb_hid_report_usage_path_t, report_item) {
     238
    243239                        if(USB_HID_SAME_USAGE_PAGE(report_item->usage_page,
    244240                                path_item->usage_page)){
    245                                        
     241
    246242                                if(only_page == 0){
    247243                                        if(USB_HID_SAME_USAGE(
    248244                                                report_item->usage,
    249245                                                path_item->usage)) {
    250                                                        
     246
    251247                                                return EOK;
    252248                                        }
     
    266262                        return 1;
    267263                }
    268                
     264
    269265        /* path is prefix of the report_path */
    270266        case USB_HID_PATH_COMPARE_BEGIN:
    271        
     267
    272268                report_link = report_path->items.head.next;
    273269                path_link = path->items.head.next;
    274                        
     270
    275271                while((report_link != &report_path->items.head) &&
    276272                      (path_link != &path->items.head)) {
    277                                          
     273
    278274                        report_item = list_get_instance(report_link,
    279275                                usb_hid_report_usage_path_t, rpath_items_link);
    280                                          
     276
    281277                        path_item = list_get_instance(path_link,
    282278                                usb_hid_report_usage_path_t, rpath_items_link);
     
    286282                            !USB_HID_SAME_USAGE(report_item->usage,
    287283                                path_item->usage))) {
    288                        
     284
    289285                                return 1;
    290                         }
    291                         else {
     286                        } else {
    292287                                report_link = report_link->next;
    293                                 path_link = path_link->next;                   
     288                                path_link = path_link->next;
    294289                        }
    295                        
    296290                }
    297291
     
    300294                   ((report_link == &report_path->items.head) &&
    301295                        (path_link == &path->items.head))) {
    302                                
     296
    303297                        return EOK;
    304298                }
     
    405399        usb_hid_report_path_t *usage_path)
    406400{
    407         usb_hid_report_usage_path_t *path_item;
    408401        usb_hid_report_usage_path_t *new_path_item;
    409402        usb_hid_report_path_t *new_usage_path = usb_hid_report_path ();
     
    419412        }
    420413
    421         list_foreach(usage_path->items, path_link) {
    422                 path_item = list_get_instance(path_link,
    423                         usb_hid_report_usage_path_t, rpath_items_link);
     414        list_foreach(usage_path->items, rpath_items_link,
     415            usb_hid_report_usage_path_t, path_item) {
    424416
    425417                new_path_item = malloc(sizeof(usb_hid_report_usage_path_t));
Note: See TracChangeset for help on using the changeset viewer.