Ignore:
File:
1 edited

Legend:

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

    r3b5d5b9d r0a494fe  
    5656#define USB_HID_UNKNOWN_TAG             -99
    5757
    58 usb_hid_report_path_t *usb_hid_report_path_try_insert(usb_hid_report_t *report, usb_hid_report_path_t *cmp_path)
    59 {
     58
     59/**
     60 * Initialize the report descriptor parser structure
     61 *
     62 * @param parser Report descriptor parser structure
     63 * @return Error code
     64 */
     65int usb_hid_report_init(usb_hid_report_t *report)
     66{
     67        if(report == NULL) {
     68                return EINVAL;
     69        }
     70
     71        memset(report, 0, sizeof(usb_hid_report_t));
     72        list_initialize(&report->reports);
     73        list_initialize(&report->collection_paths);
     74
     75        report->use_report_ids = 0;
     76    return EOK;   
     77}
     78
     79int usb_hid_report_append_fields(usb_hid_report_t *report, usb_hid_report_item_t *report_item)
     80{
     81        usb_hid_report_field_t *field;
     82        int i;
     83
     84
    6085        /* find or append current collection path to the list */
    6186        link_t *path_it = report->collection_paths.next;
     
    6489                path = list_get_instance(path_it, usb_hid_report_path_t, link);
    6590               
    66                 if(usb_hid_report_compare_usage_path(path, cmp_path, USB_HID_PATH_COMPARE_STRICT) == EOK){
     91                if(usb_hid_report_compare_usage_path(path, report_item->usage_path, USB_HID_PATH_COMPARE_STRICT) == EOK){
    6792                        break;
    6893                }                       
     
    7095        }
    7196        if(path_it == &report->collection_paths) {
    72                 path = usb_hid_report_path_clone(cmp_path);                     
     97                path = usb_hid_report_path_clone(report_item->usage_path);                     
    7398                list_append(&path->link, &report->collection_paths);                                   
    7499                report->collection_paths_count++;
    75 
    76                 return path;
    77         }
    78         else {
    79                 return list_get_instance(path_it, usb_hid_report_path_t, link);
    80         }
    81 }
    82 
    83 /**
    84  * Initialize the report descriptor parser structure
    85  *
    86  * @param parser Report descriptor parser structure
    87  * @return Error code
    88  */
    89 int usb_hid_report_init(usb_hid_report_t *report)
    90 {
    91         if(report == NULL) {
    92                 return EINVAL;
    93         }
    94 
    95         memset(report, 0, sizeof(usb_hid_report_t));
    96         list_initialize(&report->reports);
    97         list_initialize(&report->collection_paths);
    98 
    99         report->use_report_ids = 0;
    100     return EOK;   
    101 }
    102 
    103 
    104 /*
    105  *
    106  *
    107  */
    108 int usb_hid_report_append_fields(usb_hid_report_t *report, usb_hid_report_item_t *report_item)
    109 {
    110         usb_hid_report_field_t *field;
    111         int i;
     100        }
    112101
    113102        for(i=0; i<report_item->usages_count; i++){
     
    115104        }
    116105
    117         usb_hid_report_path_t *path = report_item->usage_path; 
     106       
    118107        for(i=0; i<report_item->count; i++){
    119108
     
    123112
    124113                /* fill the attributes */               
     114                field->collection_path = path;
    125115                field->logical_minimum = report_item->logical_minimum;
    126116                field->logical_maximum = report_item->logical_maximum;
     
    139129                if(report_item->usages_count > 0 && ((report_item->usage_minimum == 0) && (report_item->usage_maximum == 0))) {
    140130                        uint32_t usage;
    141                         if(i < report_item->usages_count){
    142                                 usage = report_item->usages[i];
     131                        if(report_item->type != USB_HID_REPORT_TYPE_OUTPUT) {
     132                                if(i < report_item->usages_count){
     133                                        usage = report_item->usages[i];
     134                                }
     135                                else {
     136                                        usage = report_item->usages[report_item->usages_count - 1];
     137                                }
    143138                        }
    144139                        else {
    145                                 usage = report_item->usages[report_item->usages_count - 1];
     140                                if((report_item->count - i - 1) < report_item->usages_count){
     141                                        usage = report_item->usages[(report_item->count - i - 1)];
     142                                }
     143                                else {
     144                                        usage = report_item->usages[report_item->usages_count - 1];
     145                                }
    146146                        }
    147147
     
    159159
    160160                if((USB_HID_ITEM_FLAG_VARIABLE(report_item->item_flags) != 0) && (!((report_item->usage_minimum == 0) && (report_item->usage_maximum == 0)))) {
    161                         field->usage = report_item->usage_minimum + i;                                 
    162                 }
    163                
    164                 usb_hid_report_set_last_item(path, USB_HID_TAG_CLASS_GLOBAL, field->usage_page);
    165                 usb_hid_report_set_last_item(path, USB_HID_TAG_CLASS_LOCAL, field->usage);
    166 
    167                 field->collection_path = usb_hid_report_path_try_insert(report, path);
    168 
     161                        if(report_item->type == USB_HID_REPORT_TYPE_INPUT) {
     162                                field->usage = report_item->usage_maximum - i;
     163                        }
     164                        else {
     165                                field->usage = report_item->usage_minimum + i;                                 
     166                        }
     167
     168                }
     169               
    169170                field->size = report_item->size;
    170                
    171                 size_t offset_byte = (report_item->offset + (i * report_item->size)) / 8;
    172                 size_t offset_bit = 8 - ((report_item->offset + (i * report_item->size)) % 8) - report_item->size;
    173 
    174                 field->offset = 8 * offset_byte + offset_bit;
     171                field->offset = report_item->offset + (i * report_item->size);
    175172                if(report_item->id != 0) {
    176173                        field->offset += 8;
     
    352349                                        tmp_usage_path = list_get_instance(report_item->usage_path->link.prev, usb_hid_report_usage_path_t, link);
    353350                                       
    354                                         usb_hid_report_set_last_item(usage_path, USB_HID_TAG_CLASS_GLOBAL, tmp_usage_path->usage_page);
    355                                         usb_hid_report_set_last_item(usage_path, USB_HID_TAG_CLASS_LOCAL, tmp_usage_path->usage);
     351                                        usb_hid_report_set_last_item(usage_path, tmp_usage_path->usage_page, tmp_usage_path->usage);
    356352
    357353                                        usb_hid_report_path_free(report_item->usage_path);
     
    633629
    634630                usb_log_debug("\t\tOFFSET: %X\n", report_item->offset);
    635                 usb_log_debug("\t\tSIZE: %X\n", report_item->size);                             
     631                usb_log_debug("\t\tSIZE: %zu\n", report_item->size);
    636632                usb_log_debug("\t\tLOGMIN: %d\n", report_item->logical_minimum);
    637633                usb_log_debug("\t\tLOGMAX: %d\n", report_item->logical_maximum);               
     
    644640                usb_log_debug("\t\ttUSAGE: %X\n", report_item->usage);
    645641                usb_log_debug("\t\tUSAGE PAGE: %X\n", report_item->usage_page);
    646                
    647                 //usb_hid_print_usage_path(report_item->collection_path);
    648 
    649                 usb_log_debug("\n");           
     642                                               
     643//              usb_log_debug("\n");           
    650644
    651645        }
     
    672666                usb_log_debug("Report ID: %d\n", report_des->report_id);
    673667                usb_log_debug("\tType: %d\n", report_des->type);
    674                 usb_log_debug("\tLength: %d\n", report_des->bit_length);               
    675                 usb_log_debug("\tItems: %d\n", report_des->item_length);               
     668                usb_log_debug("\tLength: %zu\n", report_des->bit_length);
     669                usb_log_debug("\tItems: %zu\n", report_des->item_length);
    676670
    677671                usb_hid_descriptor_print_list(&report_des->report_items);
Note: See TracChangeset for help on using the changeset viewer.