Changeset 3a6e423 in mainline for uspace/lib/usb/src


Ignore:
Timestamp:
2011-05-08T19:38:24Z (14 years ago)
Author:
Matej Klonfar <maklf@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7aaf403e
Parents:
7b6f116
Message:

Parsing of usages in case of array items repaired

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

Legend:

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

    r7b6f116 r3a6e423  
    6464{
    6565        /* find or append current collection path to the list */
    66         link_t *path_it = report->collection_paths.next;
     66        //link_t *path_it = report->collection_paths.next;
     67        link_t *path_it = report->collection_paths.prev->next;
    6768        usb_hid_report_path_t *path = NULL;
     69       
     70       
    6871        while(path_it != &report->collection_paths) {
    6972                path = list_get_instance(path_it, usb_hid_report_path_t, link);
     
    116119        int i;
    117120
    118         for(i=0; i<report_item->usages_count; i++){
    119                 usb_log_debug("usages (%d) - %x\n", i, report_item->usages[i]);
    120         }
    121 
     121        uint32_t *usages;
     122        int usages_used=0;
     123        if(report_item->usages_count > 0){
     124                usages = malloc(sizeof(int32_t) * report_item->usages_count);
     125                memcpy(usages, report_item->usages, sizeof(int32_t) * report_item->usages_count);
     126        }
     127        else {
     128                usages = NULL;
     129        }
     130       
    122131        usb_hid_report_path_t *path = report_item->usage_path; 
    123132        for(i=0; i<report_item->count; i++){
     
    133142                field->physical_maximum = report_item->physical_maximum;
    134143
    135                 field->usage_minimum = report_item->usage_minimum;
    136                 field->usage_maximum = report_item->usage_maximum;
    137                 if(report_item->extended_usage_page != 0){
    138                         field->usage_page = report_item->extended_usage_page;
     144                if(USB_HID_ITEM_FLAG_VARIABLE(report_item->item_flags) == 0){
     145                        /*
     146                                Store usage array. The Correct Usage Page and Usage is depending
     147                                on data in report and will be filled later
     148                        */
     149                        field->usage = 0;
     150                        field->usage_page = 0; //report_item->usage_page;
     151
     152                        field->usages_count = report_item->usages_count;
     153                        field->usages = usages;
     154                        usages_used = 1;
    139155                }
    140156                else {
    141                         field->usage_page = report_item->usage_page;
    142                 }
    143 
    144                 if(report_item->usages_count > 0 && ((report_item->usage_minimum == 0) && (report_item->usage_maximum == 0))) {
    145                         uint32_t usage;
    146                         if(i < report_item->usages_count){
     157
     158                        /* Fill the correct Usage and Usage Page */
     159                        int32_t usage;
     160                        if(i < report_item->usages_count) {
    147161                                usage = report_item->usages[i];
    148162                        }
     
    151165                        }
    152166
    153                                                
    154                         if((usage & 0xFFFF0000) != 0){
    155                                 field->usage_page = (usage >> 16);                                     
    156                                 field->usage = (usage & 0xFFFF);
     167                        if(USB_HID_IS_EXTENDED_USAGE(usage)){
     168                                field->usage = USB_HID_EXTENDED_USAGE(usage);
     169                                field->usage_page = USB_HID_EXTENDED_USAGE_PAGE(usage);
    157170                        }
    158171                        else {
     172                                // should not occur
    159173                                field->usage = usage;
    160                         }
    161 
    162                        
    163                 }       
    164 
    165                 if((USB_HID_ITEM_FLAG_VARIABLE(report_item->item_flags) != 0) && (!((report_item->usage_minimum == 0) && (report_item->usage_maximum == 0)))) {
    166                         field->usage = report_item->usage_minimum + i;                                 
     174                                field->usage_page = report_item->usage_page;
     175                        }
    167176                }
    168177               
     
    209218        }
    210219
     220        // free only when not used!!!
     221        if(usages && usages_used == 0) {
     222                free(usages);
     223        }
    211224
    212225        return EOK;
     
    450463                       
    451464                case USB_HID_REPORT_TAG_COLLECTION:
     465
    452466                        // store collection atributes
    453467                        path_item = list_get_instance(usage_path->head.prev, usb_hid_report_usage_path_t, link);
     
    455469                       
    456470                        // set last item
    457                         usb_hid_report_set_last_item(usage_path, USB_HID_TAG_CLASS_GLOBAL, report_item->usage_page);
    458                         usb_hid_report_set_last_item(usage_path, USB_HID_TAG_CLASS_LOCAL, report_item->usages[report_item->usages_count-1]);
     471                        usb_hid_report_set_last_item(usage_path,
     472                                                     USB_HID_TAG_CLASS_GLOBAL,
     473                                                     USB_HID_EXTENDED_USAGE_PAGE(report_item->usages[report_item->usages_count-1]));
     474                        usb_hid_report_set_last_item(usage_path,
     475                                                     USB_HID_TAG_CLASS_LOCAL,
     476                                                     USB_HID_EXTENDED_USAGE(report_item->usages[report_item->usages_count-1]));
    459477                       
    460478                        // append the new one which will be set by common
     
    551569                             usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path)
    552570{
     571        int32_t extended_usage;
     572       
    553573        switch(tag) {
    554574                case USB_HID_REPORT_TAG_USAGE:
     
    560580                                        report_item->in_delimiter = INSIDE_DELIMITER_SET;
    561581                                case OUTSIDE_DELIMITER_SET:
    562                                         report_item->usages[report_item->usages_count] = usb_hid_report_tag_data_uint32(data,item_size);
     582                                        extended_usage = ((report_item->usage_page) << 16);
     583                                        extended_usage += usb_hid_report_tag_data_uint32(data,item_size);
     584                                        report_item->usages[report_item->usages_count] = extended_usage;
    563585                                        report_item->usages_count++;
    564586                                        break;
    565587                        }
    566588                        break;
    567                 case USB_HID_REPORT_TAG_USAGE_MINIMUM:
     589                case USB_HID_REPORT_TAG_USAGE_MINIMUM:                 
    568590                        if (item_size == 3) {
    569591                                // usage extended usages
     
    577599                case USB_HID_REPORT_TAG_USAGE_MAXIMUM:
    578600                        if (item_size == 3) {
     601
     602                                if(report_item->extended_usage_page != ((usb_hid_report_tag_data_uint32(data,item_size) & 0xFF00) >> 16)) {
     603                                        return EINVAL;
     604                                }
     605                               
    579606                                // usage extended usages
    580607                                report_item->extended_usage_page = (usb_hid_report_tag_data_uint32(data,item_size) & 0xFF00) >> 16;
     
    584611                                report_item->usage_maximum = usb_hid_report_tag_data_uint32(data,item_size);
    585612                        }
     613
     614                        // vlozit zaznamy do pole usages
     615                        int32_t i;
     616                        for(i=report_item->usage_minimum; i<=report_item->usage_maximum; i++) {
     617                                if(report_item->extended_usage_page) {
     618                                        report_item->usages[report_item->usages_count++] = (report_item->extended_usage_page << 16) + i;
     619                                }
     620                                else {
     621                                       
     622                                        report_item->usages[report_item->usages_count++] = (report_item->usage_page << 16) + i;
     623                                }
     624                        }
     625                        report_item->extended_usage_page = 0;
     626                       
    586627                        break;
    587628                case USB_HID_REPORT_TAG_DESIGNATOR_INDEX:
     
    663704                usb_log_debug("\t\ttUSAGEMIN: %X\n", report_item->usage_minimum);
    664705                usb_log_debug("\t\tUSAGEMAX: %X\n", report_item->usage_maximum);
     706                usb_log_debug("\t\tUSAGES COUNT: %zu\n", report_item->usages_count);
    665707
    666708                usb_log_debug("\t\tVALUE: %X\n", report_item->value);
     
    668710                usb_log_debug("\t\tUSAGE PAGE: %X\n", report_item->usage_page);
    669711               
    670                 //usb_hid_print_usage_path(report_item->collection_path);
     712                usb_hid_print_usage_path(report_item->collection_path);
    671713
    672714                usb_log_debug("\n");           
     
    700742                usb_hid_descriptor_print_list(&report_des->report_items);
    701743
    702 
     744/*
    703745                link_t *path_it = report->collection_paths.next;
    704746                while(path_it != &report->collection_paths) {
     
    706748                        path_it = path_it->next;
    707749                }
    708                
     750*/             
    709751                report_it = report_it->next;
    710752        }
  • uspace/lib/usb/src/hidparser.c

    r7b6f116 r3a6e423  
    6969
    7070
     71/** Returns size of report of specified report id and type in items
     72 *
     73 * @param parser Opaque report parser structure
     74 * @param report_id
     75 * @param type
     76 * @return Number of items in specified report
     77 */
     78size_t usb_hid_report_size(usb_hid_report_t *report, uint8_t report_id,
     79                           usb_hid_report_type_t type)
     80{
     81        usb_hid_report_description_t *report_des;
     82
     83        if(report == NULL) {
     84                return 0;
     85        }
     86
     87        report_des = usb_hid_report_find_description (report, report_id, type);
     88        if(report_des == NULL){
     89                return 0;
     90        }
     91        else {
     92                return report_des->item_length;
     93        }
     94}
    7195
    7296
     
    87111        usb_hid_report_description_t *report_des;
    88112        usb_hid_report_type_t type = USB_HID_REPORT_TYPE_INPUT;
    89 
     113       
    90114        if(report == NULL) {
    91115                return EINVAL;
     
    114138                                // array
    115139                                item->value = usb_hid_translate_data(item, data);
    116                             item->usage = (item->value - item->physical_minimum) + item->usage_minimum;
     140               
     141                                item->usage = USB_HID_EXTENDED_USAGE(item->usages[item->value - item->physical_minimum]);
     142                                item->usage_page = USB_HID_EXTENDED_USAGE_PAGE(item->usages[item->value - item->physical_minimum]);                             
     143
     144                                usb_hid_report_set_last_item (item->collection_path,
     145                                                              USB_HID_TAG_CLASS_GLOBAL,
     146                                                              item->usage_page);
     147                                usb_hid_report_set_last_item (item->collection_path,
     148                                                              USB_HID_TAG_CLASS_LOCAL,
     149                                                              item->usage);
     150                               
    117151                        }
    118152                        else {
     
    123157                list_item = list_item->next;
    124158        }
    125            
     159       
    126160        return EOK;
    127161       
     
    206240}
    207241
    208 /**
    209  * Returns number of items in input report which are accessible by given usage path
    210  *
    211  * @param parser Opaque report descriptor structure
    212  * @param path Usage path specification
    213  * @param flags Usage path comparison flags
    214  * @return Number of items in input report
    215  */
    216 size_t usb_hid_report_input_length(const usb_hid_report_t *report,
    217         usb_hid_report_path_t *path, int flags)
    218 {       
    219        
    220         size_t ret = 0;
    221 
    222         if(report == NULL) {
    223                 return 0;
    224         }
    225 
    226         usb_hid_report_description_t *report_des;
    227         report_des = usb_hid_report_find_description (report, path->report_id, USB_HID_REPORT_TYPE_INPUT);
    228         if(report_des == NULL) {
    229                 return 0;
    230         }
    231 
    232         link_t *field_it = report_des->report_items.next;
    233         usb_hid_report_field_t *field;
    234         while(field_it != &report_des->report_items) {
    235 
    236                 field = list_get_instance(field_it, usb_hid_report_field_t, link);
    237                 if(USB_HID_ITEM_FLAG_CONSTANT(field->item_flags) == 0) {
    238                        
    239                         usb_hid_report_path_append_item (field->collection_path, field->usage_page, field->usage);
    240                         if(usb_hid_report_compare_usage_path (field->collection_path, path, flags) == EOK) {
    241                                 ret++;
    242                         }
    243                         usb_hid_report_remove_last_item (field->collection_path);
    244                 }
    245                
    246                 field_it = field_it->next;
    247         }
    248 
    249         return ret;
    250         }
    251 
    252242/*** OUTPUT API **/
    253243
     
    304294}
    305295
    306 /** Returns size of output for given usage path
    307  *
    308  * @param parser Opaque report parser structure
    309  * @param path Usage path specified which items will be thought for the output
    310  * @param flags Flags of usage path structure comparison
    311  * @return Number of items matching the given usage path
    312  */
    313 size_t usb_hid_report_output_size(usb_hid_report_t *report,
    314                                   usb_hid_report_path_t *path, int flags)
    315 {
    316         size_t ret = 0;
    317         usb_hid_report_description_t *report_des;
    318 
    319         if(report == NULL) {
    320                 return 0;
    321         }
    322 
    323         report_des = usb_hid_report_find_description (report, path->report_id, USB_HID_REPORT_TYPE_OUTPUT);
    324         if(report_des == NULL){
    325                 return 0;
    326         }
    327        
    328         link_t *field_it = report_des->report_items.next;
    329         usb_hid_report_field_t *field;
    330         while(field_it != &report_des->report_items) {
    331 
    332                 field = list_get_instance(field_it, usb_hid_report_field_t, link);
    333                 if(USB_HID_ITEM_FLAG_CONSTANT(field->item_flags) == 0){
    334                         usb_hid_report_path_append_item (field->collection_path, field->usage_page, field->usage);
    335                         if(usb_hid_report_compare_usage_path (field->collection_path, path, flags) == EOK) {
    336                                 ret++;
    337                         }
    338                         usb_hid_report_remove_last_item (field->collection_path);
    339                 }
    340                
    341                 field_it = field_it->next;
    342         }
    343 
    344         return ret;
    345        
    346 }
    347 
    348296/** Makes the output report buffer for data given in the report structure
    349297 *
     
    385333                report_item = list_get_instance(item, usb_hid_report_field_t, link);
    386334
     335                usb_log_debug("OUTPUT ITEM usage(%x), value(%x)\n", report_item->usage, report_item->value);
     336               
    387337                        if(USB_HID_ITEM_FLAG_VARIABLE(report_item->item_flags) == 0) {
    388338                                       
  • uspace/lib/usb/src/hidpath.c

    r7b6f116 r3a6e423  
    4242
    4343
     44#define USB_HID_SAME_USAGE(usage1, usage2)      ((usage1 == usage2) || (usage1 == 0) || (usage2 == 0))
     45#define USB_HID_SAME_USAGE_PAGE(page1, page2)   ((page1 == page2) || (page1 == 0) || (page2 == 0))
     46
    4447/**
    4548 * Appends one item (couple of usage_path and usage) into the usage path
     
    203206                        while(report_link != &report_path->head) {
    204207                                report_item = list_get_instance(report_link, usb_hid_report_usage_path_t, link);
    205                                 if(report_item->usage_page == path_item->usage_page){
     208                                if(USB_HID_SAME_USAGE_PAGE(report_item->usage_page, path_item->usage_page)){
    206209                                        if(only_page == 0){
    207                                                 if(report_item->usage == path_item->usage) {
     210                                                if(USB_HID_SAME_USAGE(report_item->usage, path_item->usage)) {
    208211                                                        return EOK;
    209212                                                }
     
    242245                                                                      link);           
    243246
    244                                         if((report_item->usage_page != path_item->usage_page) ||
     247                                        if(!USB_HID_SAME_USAGE_PAGE(report_item->usage_page, path_item->usage_page) ||
    245248                                           ((only_page == 0) &&
    246                                             (report_item->usage != path_item->usage))) {
     249                                            !USB_HID_SAME_USAGE(report_item->usage, path_item->usage))) {
    247250                                                       
    248251                                                   return 1;
     
    282285                                                                      usb_hid_report_usage_path_t,
    283286                                                                      link);           
    284 
    285                                         if((report_item->usage_page != path_item->usage_page) ||
     287                                                 
     288                                        if(!USB_HID_SAME_USAGE_PAGE(report_item->usage_page, path_item->usage_page) ||
    286289                                           ((only_page == 0) &&
    287                                             (report_item->usage != path_item->usage))) {
    288                                                    return 1;
     290                                            !USB_HID_SAME_USAGE(report_item->usage, path_item->usage))) {
     291                                                        return 1;
    289292                                        } else {
    290293                                                report_link = report_link->prev;
Note: See TracChangeset for help on using the changeset viewer.