Changes in / [310c4df:22ded10] in mainline


Ignore:
Location:
uspace/lib/usb
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usb/include/usb/classes/hiddescriptor.h

    r310c4df r22ded10  
    7878uint32_t usb_hid_report_tag_data_uint32(const uint8_t *data, size_t size);
    7979
     80usb_hid_report_path_t *usb_hid_report_path_try_insert(usb_hid_report_t *report, usb_hid_report_path_t *cmp_path);
    8081#endif
    8182/**
  • uspace/lib/usb/include/usb/classes/hidpath.h

    r310c4df r22ded10  
    4343 * Description of path of usage pages and usages in report descriptor
    4444 */
     45/** Wanted usage path must be exactly the same as the searched one */
    4546#define USB_HID_PATH_COMPARE_STRICT                             0
    46 #define USB_HID_PATH_COMPARE_END                                1
     47/** Wanted usage path must be the suffix in the searched one */
     48#define USB_HID_PATH_COMPARE_END                        1
     49/** */
    4750#define USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY    4
    4851#define USB_HID_PATH_COMPARE_COLLECTION_ONLY    2 /* porovnava jenom cestu z Kolekci */
     52/** Searched usage page must be prefix of the other one */
     53#define USB_HID_PATH_COMPARE_BEGIN              8
     54/** Searched couple of usage page and usage can be anywhere in usage path */
     55#define USB_HID_PATH_COMPARE_WHERE              16
     56/**
     57 * TODO
     58 *  * porovnani zacatek - neni to to samy jako COLLECTION ONLY?? -- TEST
     59 *  * porovnani kdekoliv (jenom s delkou 1 at si to moc nekomplikujem)
     60 */
    4961
    5062
  • uspace/lib/usb/include/usb/classes/hidtypes.h

    r310c4df r22ded10  
    165165        /** */ 
    166166        link_t link;
     167
     168        int in_delimiter;
    167169} usb_hid_report_item_t;
    168170
  • uspace/lib/usb/src/hiddescriptor.c

    r310c4df r22ded10  
    4141#include <assert.h>
    4242
     43
     44#define OUTSIDE_DELIMITER_SET   0
     45#define START_DELIMITER_SET     1
     46#define INSIDE_DELIMITER_SET    2
     47       
    4348/** The new report item flag. Used to determine when the item is completly
    4449 * configured and should be added to the report structure
     
    5661#define USB_HID_UNKNOWN_TAG             -99
    5762
    58 
    59 /**
    60  * Initialize the report descriptor parser structure
    61  *
    62  * @param parser Report descriptor parser structure
    63  * @return Error code
    64  */
    65 int 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 
    79 int 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 
     63usb_hid_report_path_t *usb_hid_report_path_try_insert(usb_hid_report_t *report, usb_hid_report_path_t *cmp_path)
     64{
    8565        /* find or append current collection path to the list */
    8666        link_t *path_it = report->collection_paths.next;
     
    8969                path = list_get_instance(path_it, usb_hid_report_path_t, link);
    9070               
    91                 if(usb_hid_report_compare_usage_path(path, report_item->usage_path, USB_HID_PATH_COMPARE_STRICT) == EOK){
     71                if(usb_hid_report_compare_usage_path(path, cmp_path, USB_HID_PATH_COMPARE_STRICT) == EOK){
    9272                        break;
    9373                }                       
     
    9575        }
    9676        if(path_it == &report->collection_paths) {
    97                 path = usb_hid_report_path_clone(report_item->usage_path);                     
     77                path = usb_hid_report_path_clone(cmp_path);                     
    9878                list_append(&path->link, &report->collection_paths);                                   
    9979                report->collection_paths_count++;
    100         }
     80
     81                return path;
     82        }
     83        else {
     84                return list_get_instance(path_it, usb_hid_report_path_t, link);
     85        }
     86}
     87
     88/**
     89 * Initialize the report descriptor parser structure
     90 *
     91 * @param parser Report descriptor parser structure
     92 * @return Error code
     93 */
     94int usb_hid_report_init(usb_hid_report_t *report)
     95{
     96        if(report == NULL) {
     97                return EINVAL;
     98        }
     99
     100        memset(report, 0, sizeof(usb_hid_report_t));
     101        list_initialize(&report->reports);
     102        list_initialize(&report->collection_paths);
     103
     104        report->use_report_ids = 0;
     105    return EOK;   
     106}
     107
     108
     109/*
     110 *
     111 *
     112 */
     113int usb_hid_report_append_fields(usb_hid_report_t *report, usb_hid_report_item_t *report_item)
     114{
     115        usb_hid_report_field_t *field;
     116        int i;
    101117
    102118        for(i=0; i<report_item->usages_count; i++){
     
    104120        }
    105121
    106        
     122        usb_hid_report_path_t *path = report_item->usage_path; 
    107123        for(i=0; i<report_item->count; i++){
    108124
     
    112128
    113129                /* fill the attributes */               
    114                 field->collection_path = path;
    115130                field->logical_minimum = report_item->logical_minimum;
    116131                field->logical_maximum = report_item->logical_maximum;
     
    129144                if(report_item->usages_count > 0 && ((report_item->usage_minimum == 0) && (report_item->usage_maximum == 0))) {
    130145                        uint32_t usage;
    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                                 }
     146                        if(i < report_item->usages_count){
     147                                usage = report_item->usages[i];
    138148                        }
    139149                        else {
    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                                 }
     150                                usage = report_item->usages[report_item->usages_count - 1];
    146151                        }
    147152
     
    159164
    160165                if((USB_HID_ITEM_FLAG_VARIABLE(report_item->item_flags) != 0) && (!((report_item->usage_minimum == 0) && (report_item->usage_maximum == 0)))) {
    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                
     166                        field->usage = report_item->usage_minimum + i;                                 
     167                }
     168               
     169                usb_hid_report_set_last_item(path, USB_HID_TAG_CLASS_GLOBAL, field->usage_page);
     170                usb_hid_report_set_last_item(path, USB_HID_TAG_CLASS_LOCAL, field->usage);
     171
     172                field->collection_path = usb_hid_report_path_try_insert(report, path);
     173
    170174                field->size = report_item->size;
    171                 field->offset = report_item->offset + (i * report_item->size);
     175               
     176                size_t offset_byte = (report_item->offset + (i * report_item->size)) / 8;
     177                size_t offset_bit = 8 - ((report_item->offset + (i * report_item->size)) % 8) - report_item->size;
     178
     179                field->offset = 8 * offset_byte + offset_bit;
    172180                if(report_item->id != 0) {
    173181                        field->offset += 8;
     
    264272                return ENOMEM;
    265273        }
     274        usb_hid_report_path_append_item(usage_path, 0, 0);     
    266275       
    267276        while(i<size){ 
     
    349358                                        tmp_usage_path = list_get_instance(report_item->usage_path->link.prev, usb_hid_report_usage_path_t, link);
    350359                                       
    351                                         usb_hid_report_set_last_item(usage_path, tmp_usage_path->usage_page, tmp_usage_path->usage);
     360                                        usb_hid_report_set_last_item(usage_path, USB_HID_TAG_CLASS_GLOBAL, tmp_usage_path->usage_page);
     361                                        usb_hid_report_set_last_item(usage_path, USB_HID_TAG_CLASS_LOCAL, tmp_usage_path->usage);
    352362
    353363                                        usb_hid_report_path_free(report_item->usage_path);
     
    438448                       
    439449                case USB_HID_REPORT_TAG_COLLECTION:
    440                         // TODO usage_path->flags = *data;
    441                         usb_hid_report_path_append_item(usage_path, report_item->usage_page, report_item->usages[report_item->usages_count-1]);                                         
     450                        //TODO: usage_path->flags = *data;
     451                       
     452                        usb_log_debug("APPENDED ITEM TO USAGE PATH (PAGE %d, USAGE %d\n", report_item->usage_page, report_item->usages[report_item->usages_count-1]);
     453                        usb_hid_print_usage_path(usage_path);
     454
     455                        // set last item
     456                        usb_hid_report_set_last_item(usage_path, USB_HID_TAG_CLASS_GLOBAL, report_item->usage_page);
     457                        usb_hid_report_set_last_item(usage_path, USB_HID_TAG_CLASS_LOCAL, report_item->usages[report_item->usages_count-1]);
     458                        // append the new one which will be set by common
     459                        // usage/usage page
     460                        usb_hid_report_path_append_item(usage_path, report_item->usage_page, report_item->usages[report_item->usages_count-1]);
     461                        usb_hid_print_usage_path(usage_path);
     462
    442463                        usb_hid_report_reset_local_items (report_item);
    443464                        return USB_HID_NO_ACTION;
     
    575596                        break;                 
    576597                case USB_HID_REPORT_TAG_DELIMITER:
    577                         //report_item->delimiter = usb_hid_report_tag_data_uint32(data,item_size);
    578                         //TODO:
    579                         //      DELIMITER STUFF
     598                        if (report_item->in_delimiter == OUTSIDE_DELIMITER_SET) {
     599                                report_item->in_delimiter = START_DELIMITER_SET;
     600                        }
     601                        else {
     602                                report_item->in_delimiter = OUTSIDE_DELIMITER_SET;
     603                        }
     604                       
    580605                        break;
    581606               
     
    629654
    630655                usb_log_debug("\t\tOFFSET: %X\n", report_item->offset);
    631                 usb_log_debug("\t\tSIZE: %zu\n", report_item->size);
     656                usb_log_debug("\t\tSIZE: %X\n", report_item->size);                             
    632657                usb_log_debug("\t\tLOGMIN: %d\n", report_item->logical_minimum);
    633658                usb_log_debug("\t\tLOGMAX: %d\n", report_item->logical_maximum);               
     
    640665                usb_log_debug("\t\ttUSAGE: %X\n", report_item->usage);
    641666                usb_log_debug("\t\tUSAGE PAGE: %X\n", report_item->usage_page);
    642                                                
    643 //              usb_log_debug("\n");           
     667               
     668                //usb_hid_print_usage_path(report_item->collection_path);
     669
     670                usb_log_debug("\n");           
    644671
    645672        }
     
    666693                usb_log_debug("Report ID: %d\n", report_des->report_id);
    667694                usb_log_debug("\tType: %d\n", report_des->type);
    668                 usb_log_debug("\tLength: %zu\n", report_des->bit_length);
    669                 usb_log_debug("\tItems: %zu\n", report_des->item_length);
     695                usb_log_debug("\tLength: %d\n", report_des->bit_length);               
     696                usb_log_debug("\tItems: %d\n", report_des->item_length);               
    670697
    671698                usb_hid_descriptor_print_list(&report_des->report_items);
  • uspace/lib/usb/src/hidparser.c

    r310c4df r22ded10  
    405405                                }
    406406
    407                                 size_t shift = offset%8;
     407                                size_t shift = 8 - offset%8 - length;
    408408
    409409                                value = value << shift;                                                 
Note: See TracChangeset for help on using the changeset viewer.