Ignore:
File:
1 edited

Legend:

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

    rf90c0d6 r68b614e  
    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                        /* Fill the correct Usage and Usage Page */
     158                        int32_t usage;
     159                        if(i < report_item->usages_count) {
    147160                                usage = report_item->usages[i];
    148161                        }
     
    151164                        }
    152165
    153                                                
    154                         if((usage & 0xFFFF0000) != 0){
    155                                 field->usage_page = (usage >> 16);                                     
    156                                 field->usage = (usage & 0xFFFF);
     166                        if(USB_HID_IS_EXTENDED_USAGE(usage)){
     167                                field->usage = USB_HID_EXTENDED_USAGE(usage);
     168                                field->usage_page = USB_HID_EXTENDED_USAGE_PAGE(usage);
    157169                        }
    158170                        else {
     171                                // should not occur
    159172                                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;                                 
     173                                field->usage_page = report_item->usage_page;
     174                        }
    167175                }
    168176               
     
    209217        }
    210218
     219        // free only when not used!!!
     220        if(usages && usages_used == 0) {
     221                free(usages);
     222        }
    211223
    212224        return EOK;
     
    455467                       
    456468                        // 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]);
     469                        usb_hid_report_set_last_item(usage_path,
     470                                                     USB_HID_TAG_CLASS_GLOBAL,
     471                                                     USB_HID_EXTENDED_USAGE_PAGE(report_item->usages[report_item->usages_count-1]));
     472                        usb_hid_report_set_last_item(usage_path,
     473                                                     USB_HID_TAG_CLASS_LOCAL,
     474                                                     USB_HID_EXTENDED_USAGE(report_item->usages[report_item->usages_count-1]));
    459475                       
    460476                        // append the new one which will be set by common
     
    551567                             usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path)
    552568{
     569        int32_t extended_usage;
     570       
    553571        switch(tag) {
    554572                case USB_HID_REPORT_TAG_USAGE:
     
    560578                                        report_item->in_delimiter = INSIDE_DELIMITER_SET;
    561579                                case OUTSIDE_DELIMITER_SET:
    562                                         report_item->usages[report_item->usages_count] = usb_hid_report_tag_data_uint32(data,item_size);
     580                                        extended_usage = ((report_item->usage_page) << 16);
     581                                        extended_usage += usb_hid_report_tag_data_uint32(data,item_size);
     582                                        report_item->usages[report_item->usages_count] = extended_usage;
    563583                                        report_item->usages_count++;
    564584                                        break;
    565585                        }
    566586                        break;
    567                 case USB_HID_REPORT_TAG_USAGE_MINIMUM:
     587                case USB_HID_REPORT_TAG_USAGE_MINIMUM:                 
    568588                        if (item_size == 3) {
    569589                                // usage extended usages
     
    577597                case USB_HID_REPORT_TAG_USAGE_MAXIMUM:
    578598                        if (item_size == 3) {
     599
     600                                if(report_item->extended_usage_page != ((usb_hid_report_tag_data_uint32(data,item_size) & 0xFF00) >> 16)) {
     601                                        return EINVAL;
     602                                }
     603                               
    579604                                // usage extended usages
    580605                                report_item->extended_usage_page = (usb_hid_report_tag_data_uint32(data,item_size) & 0xFF00) >> 16;
     
    584609                                report_item->usage_maximum = usb_hid_report_tag_data_uint32(data,item_size);
    585610                        }
     611
     612                        // vlozit zaznamy do pole usages
     613                        int32_t i;
     614                        for(i=report_item->usage_minimum; i<=report_item->usage_maximum; i++) {
     615                                if(report_item->extended_usage_page) {
     616                                        report_item->usages[report_item->usages_count++] = (report_item->extended_usage_page << 16) + i;
     617                                }
     618                                else {
     619                                       
     620                                        report_item->usages[report_item->usages_count++] = (report_item->usage_page << 16) + i;
     621                                }
     622                        }
     623                        report_item->extended_usage_page = 0;
     624                       
    586625                        break;
    587626                case USB_HID_REPORT_TAG_DESIGNATOR_INDEX:
     
    663702                usb_log_debug("\t\ttUSAGEMIN: %X\n", report_item->usage_minimum);
    664703                usb_log_debug("\t\tUSAGEMAX: %X\n", report_item->usage_maximum);
     704                usb_log_debug("\t\tUSAGES COUNT: %zu\n", report_item->usages_count);
    665705
    666706                usb_log_debug("\t\tVALUE: %X\n", report_item->value);
     
    668708                usb_log_debug("\t\tUSAGE PAGE: %X\n", report_item->usage_page);
    669709               
    670                 //usb_hid_print_usage_path(report_item->collection_path);
     710                usb_hid_print_usage_path(report_item->collection_path);
    671711
    672712                usb_log_debug("\n");           
     
    700740                usb_hid_descriptor_print_list(&report_des->report_items);
    701741
    702 
     742/*
    703743                link_t *path_it = report->collection_paths.next;
    704744                while(path_it != &report->collection_paths) {
     
    706746                        path_it = path_it->next;
    707747                }
    708                
     748*/             
    709749                report_it = report_it->next;
    710750        }
Note: See TracChangeset for help on using the changeset viewer.