Changeset 3a6e423 in mainline for uspace/lib/usb/src/hidparser.c


Ignore:
Timestamp:
2011-05-08T19:38:24Z (13 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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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                                       
Note: See TracChangeset for help on using the changeset viewer.