Changes in / [f50f722:7b6f116] in mainline


Ignore:
Location:
uspace
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/usbhid/kbd/kbddev.c

    rf50f722 r7b6f116  
    700700       
    701701        while (field != NULL) {
    702                 //usb_log_debug2("FIELD (%p) - VALUE(%d) USAGE(%u)\n",
    703                 //    field, field->value, field->usage);
     702                usb_log_debug2("FIELD (%p) - VALUE(%d) USAGE(%u)\n",
     703                    field, field->value, field->usage);
    704704               
    705705                assert(i < kbd_dev->key_count);
     
    865865        usb_hid_report_path_set_report_id(path, 0);
    866866       
    867         kbd_dev->key_count = usb_hid_report_size(
    868             hid_dev->report, 0, USB_HID_REPORT_TYPE_INPUT);
     867        kbd_dev->key_count = usb_hid_report_input_length(
     868            hid_dev->report, path,
     869            USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY);
    869870        usb_hid_report_path_free(path);
    870871       
     
    907908            kbd_dev->led_path, USB_HIDUT_PAGE_LED, 0);
    908909       
    909         kbd_dev->led_output_size = usb_hid_report_size(hid_dev->report, 0,
    910             USB_HID_REPORT_TYPE_OUTPUT);
     910        kbd_dev->led_output_size = usb_hid_report_output_size(hid_dev->report,
     911            kbd_dev->led_path,
     912            USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY);
    911913       
    912914        usb_log_debug("Output report size (in items): %zu\n",
  • uspace/drv/usbhid/lgtch-ultrax/lgtch-ultrax.c

    rf50f722 r7b6f116  
    300300        usb_hid_report_path_set_report_id(path, 1);
    301301       
    302         lgtch_dev->key_count = usb_hid_report_size(hid_dev->report, 1,
    303                 USB_HID_REPORT_TYPE_INPUT);
    304        
     302        lgtch_dev->key_count = usb_hid_report_input_length(
     303            hid_dev->report, path,
     304            USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY);
    305305        usb_hid_report_path_free(path);
    306306       
  • uspace/drv/usbhid/usbhid.c

    rf50f722 r7b6f116  
    203203       
    204204        usb_log_debug("Compare flags: %d\n", mapping->compare);
    205         size_t size = usb_hid_report_size(hid_dev->report, mapping->report_id,
    206             USB_HID_REPORT_TYPE_INPUT);
     205        size_t size = usb_hid_report_input_length(hid_dev->report, usage_path,
     206            mapping->compare);
    207207        usb_log_debug("Size of the input report: %zuB\n", size);
    208208       
  • uspace/drv/usbkbd/kbddev.c

    rf50f722 r7b6f116  
    771771        usb_hid_report_path_set_report_id(path, 0);
    772772       
    773         kbd_dev->key_count = usb_hid_report_size(
    774             kbd_dev->parser, 0, USB_HID_REPORT_TYPE_INPUT);
     773        kbd_dev->key_count = usb_hid_report_input_length(
     774            kbd_dev->parser, path, USB_HID_PATH_COMPARE_END);
    775775        usb_hid_report_path_free (path);
    776776       
     
    803803        usb_hid_report_path_set_report_id(kbd_dev->led_path, 0x00);
    804804       
    805         kbd_dev->led_output_size = usb_hid_report_size(kbd_dev->parser, 0,
    806             USB_HID_REPORT_TYPE_OUTPUT);
     805        kbd_dev->led_output_size = usb_hid_report_output_size(kbd_dev->parser,
     806            kbd_dev->led_path,
     807            USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY);
    807808       
    808809        usb_log_debug("Output report size (in items): %zu\n",
  • uspace/lib/usb/include/usb/classes/hid_report_items.h

    rf50f722 r7b6f116  
    4646#define USB_HID_ITEM_IS_LONG(data)      (data == 0xFE)
    4747
    48 
    49 /**
    50  * Extended usage macros
    51  */
    52 #define USB_HID_IS_EXTENDED_USAGE(usage)        ((usage & 0xFFFF0000) != 0)
    53 #define USB_HID_EXTENDED_USAGE_PAGE(usage)      ((usage & 0xFFFF0000) >> 16)
    54 #define USB_HID_EXTENDED_USAGE(usage)           (usage & 0xFFFF)
    5548
    5649/**
  • uspace/lib/usb/include/usb/classes/hidparser.h

    rf50f722 r7b6f116  
    5151                         size_t size, uint8_t *report_id);
    5252
     53/** */
     54size_t usb_hid_report_input_length(const usb_hid_report_t *report,
     55        usb_hid_report_path_t *path, int flags);
     56
    5357/*
    5458 * Output report parser functions
     
    6165void usb_hid_report_output_free(uint8_t *output);
    6266
    63 /** Returns size of report in items */
    64 size_t usb_hid_report_size(usb_hid_report_t *report, uint8_t report_id,
    65                            usb_hid_report_type_t type);
     67/** Returns size of output for given usage path */
     68size_t usb_hid_report_output_size(usb_hid_report_t *report,
     69                                  usb_hid_report_path_t *path, int flags);
    6670
    6771/** Makes the output report buffer by translated given data */
  • uspace/lib/usb/include/usb/classes/hidtypes.h

    rf50f722 r7b6f116  
    3939#include <adt/list.h>
    4040
    41 #define USB_HID_MAX_USAGES      0xffff
     41#define USB_HID_MAX_USAGES      20
    4242
    4343#define USB_HID_UINT32_TO_INT32(x, size)        ((((x) & (1 << ((size) - 1))) != 0) ? -(~(x - 1) & ((1 << size) - 1)) : (x)) //(-(~((x) - 1)))
     
    9292        int32_t physical_minimum;
    9393        int32_t physical_maximum;
    94         int32_t usage_minimum;
    95         int32_t usage_maximum;
     94        uint32_t usage_minimum;
     95        uint32_t usage_maximum;
    9696        uint32_t unit;
    9797        uint32_t unit_exponent;
    98 
    99         uint32_t *usages;
    100         size_t usages_count;
     98       
    10199
    102100        int32_t value;
     
    123121
    124122        /** */ 
    125         int32_t usage_minimum;
    126         /** */ 
    127         int32_t usage_maximum;
     123        uint32_t usage_minimum;
     124        /** */ 
     125        uint32_t usage_maximum;
    128126        /** */ 
    129127        int32_t logical_minimum;
  • uspace/lib/usb/src/hiddescriptor.c

    rf50f722 r7b6f116  
    6464{
    6565        /* find or append current collection path to the list */
    66         //link_t *path_it = report->collection_paths.next;
    67         link_t *path_it = report->collection_paths.prev->next;
     66        link_t *path_it = report->collection_paths.next;
    6867        usb_hid_report_path_t *path = NULL;
    69        
    70        
    7168        while(path_it != &report->collection_paths) {
    7269                path = list_get_instance(path_it, usb_hid_report_path_t, link);
     
    119116        int i;
    120117
    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        
     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
    131122        usb_hid_report_path_t *path = report_item->usage_path; 
    132123        for(i=0; i<report_item->count; i++){
     
    142133                field->physical_maximum = report_item->physical_maximum;
    143134
    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;
     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;
    155139                }
    156140                else {
    157                         /* Fill the correct Usage and Usage Page */
    158                         int32_t usage;
    159                         if(i < report_item->usages_count) {
     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){
    160147                                usage = report_item->usages[i];
    161148                        }
     
    164151                        }
    165152
    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);
     153                                               
     154                        if((usage & 0xFFFF0000) != 0){
     155                                field->usage_page = (usage >> 16);                                     
     156                                field->usage = (usage & 0xFFFF);
    169157                        }
    170158                        else {
    171                                 // should not occur
    172159                                field->usage = usage;
    173                                 field->usage_page = report_item->usage_page;
    174                         }
     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;                                 
    175167                }
    176168               
     
    217209        }
    218210
    219         // free only when not used!!!
    220         if(usages && usages_used == 0) {
    221                 free(usages);
    222         }
    223211
    224212        return EOK;
     
    467455                       
    468456                        // set last item
    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]));
     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]);
    475459                       
    476460                        // append the new one which will be set by common
     
    567551                             usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path)
    568552{
    569         int32_t extended_usage;
    570        
    571553        switch(tag) {
    572554                case USB_HID_REPORT_TAG_USAGE:
     
    578560                                        report_item->in_delimiter = INSIDE_DELIMITER_SET;
    579561                                case OUTSIDE_DELIMITER_SET:
    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;
     562                                        report_item->usages[report_item->usages_count] = usb_hid_report_tag_data_uint32(data,item_size);
    583563                                        report_item->usages_count++;
    584564                                        break;
    585565                        }
    586566                        break;
    587                 case USB_HID_REPORT_TAG_USAGE_MINIMUM:                 
     567                case USB_HID_REPORT_TAG_USAGE_MINIMUM:
    588568                        if (item_size == 3) {
    589569                                // usage extended usages
     
    597577                case USB_HID_REPORT_TAG_USAGE_MAXIMUM:
    598578                        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                                
    604579                                // usage extended usages
    605580                                report_item->extended_usage_page = (usb_hid_report_tag_data_uint32(data,item_size) & 0xFF00) >> 16;
     
    609584                                report_item->usage_maximum = usb_hid_report_tag_data_uint32(data,item_size);
    610585                        }
    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                        
    625586                        break;
    626587                case USB_HID_REPORT_TAG_DESIGNATOR_INDEX:
     
    702663                usb_log_debug("\t\ttUSAGEMIN: %X\n", report_item->usage_minimum);
    703664                usb_log_debug("\t\tUSAGEMAX: %X\n", report_item->usage_maximum);
    704                 usb_log_debug("\t\tUSAGES COUNT: %zu\n", report_item->usages_count);
    705665
    706666                usb_log_debug("\t\tVALUE: %X\n", report_item->value);
     
    708668                usb_log_debug("\t\tUSAGE PAGE: %X\n", report_item->usage_page);
    709669               
    710                 usb_hid_print_usage_path(report_item->collection_path);
     670                //usb_hid_print_usage_path(report_item->collection_path);
    711671
    712672                usb_log_debug("\n");           
     
    740700                usb_hid_descriptor_print_list(&report_des->report_items);
    741701
    742 /*
     702
    743703                link_t *path_it = report->collection_paths.next;
    744704                while(path_it != &report->collection_paths) {
     
    746706                        path_it = path_it->next;
    747707                }
    748 */             
     708               
    749709                report_it = report_it->next;
    750710        }
  • uspace/lib/usb/src/hidparser.c

    rf50f722 r7b6f116  
    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  */
    78 size_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 }
    9571
    9672
     
    11187        usb_hid_report_description_t *report_des;
    11288        usb_hid_report_type_t type = USB_HID_REPORT_TYPE_INPUT;
    113        
     89
    11490        if(report == NULL) {
    11591                return EINVAL;
     
    138114                                // array
    139115                                item->value = usb_hid_translate_data(item, data);
    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                                
     116                            item->usage = (item->value - item->physical_minimum) + item->usage_minimum;
    151117                        }
    152118                        else {
     
    157123                list_item = list_item->next;
    158124        }
    159        
     125           
    160126        return EOK;
    161127       
     
    240206}
    241207
     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 */
     216size_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
    242252/*** OUTPUT API **/
    243253
     
    292302                free (output);
    293303        }
     304}
     305
     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 */
     313size_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       
    294346}
    295347
  • uspace/lib/usb/src/hidpath.c

    rf50f722 r7b6f116  
    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 
    4744/**
    4845 * Appends one item (couple of usage_path and usage) into the usage path
     
    206203                        while(report_link != &report_path->head) {
    207204                                report_item = list_get_instance(report_link, usb_hid_report_usage_path_t, link);
    208                                 if(USB_HID_SAME_USAGE_PAGE(report_item->usage_page, path_item->usage_page)){
     205                                if(report_item->usage_page == path_item->usage_page){
    209206                                        if(only_page == 0){
    210                                                 if(USB_HID_SAME_USAGE(report_item->usage, path_item->usage)) {
     207                                                if(report_item->usage == path_item->usage) {
    211208                                                        return EOK;
    212209                                                }
     
    245242                                                                      link);           
    246243
    247                                         if(!USB_HID_SAME_USAGE_PAGE(report_item->usage_page, path_item->usage_page) ||
     244                                        if((report_item->usage_page != path_item->usage_page) ||
    248245                                           ((only_page == 0) &&
    249                                             !USB_HID_SAME_USAGE(report_item->usage, path_item->usage))) {
     246                                            (report_item->usage != path_item->usage))) {
    250247                                                       
    251248                                                   return 1;
     
    285282                                                                      usb_hid_report_usage_path_t,
    286283                                                                      link);           
    287                                                  
    288                                         if(!USB_HID_SAME_USAGE_PAGE(report_item->usage_page, path_item->usage_page) ||
     284
     285                                        if((report_item->usage_page != path_item->usage_page) ||
    289286                                           ((only_page == 0) &&
    290                                             !USB_HID_SAME_USAGE(report_item->usage, path_item->usage))) {
    291                                                         return 1;
     287                                            (report_item->usage != path_item->usage))) {
     288                                                   return 1;
    292289                                        } else {
    293290                                                report_link = report_link->prev;
Note: See TracChangeset for help on using the changeset viewer.