Changes in / [6c6a95d2:ba17f5b] in mainline
- Location:
- uspace/lib/usb
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usb/include/usb/classes/hiddescriptor.h
r6c6a95d2 rba17f5b 78 78 uint32_t usb_hid_report_tag_data_uint32(const uint8_t *data, size_t size); 79 79 80 usb_hid_report_path_t *usb_hid_report_path_try_insert(usb_hid_report_t *report, usb_hid_report_path_t *cmp_path); 80 81 #endif 81 82 /** -
uspace/lib/usb/include/usb/classes/hidpath.h
r6c6a95d2 rba17f5b 43 43 * Description of path of usage pages and usages in report descriptor 44 44 */ 45 #define USB_HID_PATH_COMPARE_STRICT 0 46 #define USB_HID_PATH_COMPARE_END 1 47 #define USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY 4 48 #define USB_HID_PATH_COMPARE_COLLECTION_ONLY 2 /* porovnava jenom cestu z Kolekci */ 45 /** Wanted usage path must be exactly the same as the searched one */ 46 #define USB_HID_PATH_COMPARE_STRICT 0 47 /** Wanted usage path must be the suffix in the searched one */ 48 #define USB_HID_PATH_COMPARE_END 1 49 /** */ 50 #define USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY 2 51 /** Searched usage page must be prefix of the other one */ 52 #define USB_HID_PATH_COMPARE_BEGIN 4 53 /** Searched couple of usage page and usage can be anywhere in usage path */ 54 #define USB_HID_PATH_COMPARE_ANYWHERE 8 49 55 50 56 -
uspace/lib/usb/include/usb/classes/hidtypes.h
r6c6a95d2 rba17f5b 165 165 /** */ 166 166 link_t link; 167 168 int in_delimiter; 167 169 } usb_hid_report_item_t; 168 170 -
uspace/lib/usb/src/hiddescriptor.c
r6c6a95d2 rba17f5b 41 41 #include <assert.h> 42 42 43 44 #define OUTSIDE_DELIMITER_SET 0 45 #define START_DELIMITER_SET 1 46 #define INSIDE_DELIMITER_SET 2 47 43 48 /** The new report item flag. Used to determine when the item is completly 44 49 * configured and should be added to the report structure … … 56 61 #define USB_HID_UNKNOWN_TAG -99 57 62 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 63 usb_hid_report_path_t *usb_hid_report_path_try_insert(usb_hid_report_t *report, usb_hid_report_path_t *cmp_path) 64 { 85 65 /* find or append current collection path to the list */ 86 66 link_t *path_it = report->collection_paths.next; … … 89 69 path = list_get_instance(path_it, usb_hid_report_path_t, link); 90 70 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){ 92 72 break; 93 73 } … … 95 75 } 96 76 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); 98 78 list_append(&path->link, &report->collection_paths); 99 79 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 */ 94 int 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 */ 113 int 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; 101 117 102 118 for(i=0; i<report_item->usages_count; i++){ … … 104 120 } 105 121 106 122 usb_hid_report_path_t *path = report_item->usage_path; 107 123 for(i=0; i<report_item->count; i++){ 108 124 … … 112 128 113 129 /* fill the attributes */ 114 field->collection_path = path;115 130 field->logical_minimum = report_item->logical_minimum; 116 131 field->logical_maximum = report_item->logical_maximum; … … 129 144 if(report_item->usages_count > 0 && ((report_item->usage_minimum == 0) && (report_item->usage_maximum == 0))) { 130 145 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]; 138 148 } 139 149 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]; 146 151 } 147 152 … … 159 164 160 165 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 170 174 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; 172 180 if(report_item->id != 0) { 173 181 field->offset += 8; … … 264 272 return ENOMEM; 265 273 } 274 usb_hid_report_path_append_item(usage_path, 0, 0); 266 275 267 276 while(i<size){ … … 349 358 tmp_usage_path = list_get_instance(report_item->usage_path->link.prev, usb_hid_report_usage_path_t, link); 350 359 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); 352 362 353 363 usb_hid_report_path_free(report_item->usage_path); … … 427 437 int usb_hid_report_parse_main_tag(uint8_t tag, const uint8_t *data, size_t item_size, 428 438 usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path) 429 { 439 { 440 usb_hid_report_usage_path_t *path_item; 441 430 442 switch(tag) 431 443 { … … 438 450 439 451 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]); 452 // store collection atributes 453 path_item = list_get_instance(usage_path->head.prev, usb_hid_report_usage_path_t, link); 454 path_item->flags = *data; 455 456 // 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]); 459 460 // append the new one which will be set by common 461 // usage/usage page 462 usb_hid_report_path_append_item(usage_path, report_item->usage_page, report_item->usages[report_item->usages_count-1]); 442 463 usb_hid_report_reset_local_items (report_item); 443 464 return USB_HID_NO_ACTION; … … 530 551 usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path) 531 552 { 532 switch(tag) 533 { 553 switch(tag) { 534 554 case USB_HID_REPORT_TAG_USAGE: 535 report_item->usages[report_item->usages_count] = usb_hid_report_tag_data_uint32(data,item_size); 536 report_item->usages_count++; 555 switch(report_item->in_delimiter) { 556 case INSIDE_DELIMITER_SET: 557 // nothing to do 558 break; 559 case START_DELIMITER_SET: 560 report_item->in_delimiter = INSIDE_DELIMITER_SET; 561 case OUTSIDE_DELIMITER_SET: 562 report_item->usages[report_item->usages_count] = usb_hid_report_tag_data_uint32(data,item_size); 563 report_item->usages_count++; 564 break; 565 } 537 566 break; 538 567 case USB_HID_REPORT_TAG_USAGE_MINIMUM: … … 575 604 break; 576 605 case USB_HID_REPORT_TAG_DELIMITER: 577 //report_item->delimiter = usb_hid_report_tag_data_uint32(data,item_size); 578 //TODO: 579 // DELIMITER STUFF 580 break; 581 606 report_item->in_delimiter = usb_hid_report_tag_data_uint32(data,item_size); 607 break; 608 582 609 default: 583 610 return USB_HID_NO_ACTION; 584 611 } 585 612 586 613 return EOK; 587 614 } … … 629 656 630 657 usb_log_debug("\t\tOFFSET: %X\n", report_item->offset); 631 usb_log_debug("\t\tSIZE: % zu\n", report_item->size);658 usb_log_debug("\t\tSIZE: %X\n", report_item->size); 632 659 usb_log_debug("\t\tLOGMIN: %d\n", report_item->logical_minimum); 633 660 usb_log_debug("\t\tLOGMAX: %d\n", report_item->logical_maximum); … … 640 667 usb_log_debug("\t\ttUSAGE: %X\n", report_item->usage); 641 668 usb_log_debug("\t\tUSAGE PAGE: %X\n", report_item->usage_page); 642 643 // usb_log_debug("\n"); 669 670 //usb_hid_print_usage_path(report_item->collection_path); 671 672 usb_log_debug("\n"); 644 673 645 674 } … … 666 695 usb_log_debug("Report ID: %d\n", report_des->report_id); 667 696 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);697 usb_log_debug("\tLength: %d\n", report_des->bit_length); 698 usb_log_debug("\tItems: %d\n", report_des->item_length); 670 699 671 700 usb_hid_descriptor_print_list(&report_des->report_items); -
uspace/lib/usb/src/hidparser.c
r6c6a95d2 rba17f5b 405 405 } 406 406 407 size_t shift = offset%8;407 size_t shift = 8 - offset%8 - length; 408 408 409 409 value = value << shift; -
uspace/lib/usb/src/hidpath.c
r6c6a95d2 rba17f5b 149 149 usb_log_debug("\tFLAGS: %d\n", path_item->flags); 150 150 151 item = item->next;151 item = item->next; 152 152 } 153 153 } … … 156 156 * Compares two usage paths structures 157 157 * 158 * If USB_HID_PATH_COMPARE_COLLECTION_ONLY flag is given, the last item in report_path structure is forgotten 159 * 160 * @param report_path usage path structure to compare 158 * 159 * @param report_path usage path structure to compare with @path 161 160 * @param path usage patrh structure to compare 162 161 * @param flags Flags determining the mode of comparison … … 179 178 } 180 179 180 // Empty path match all others 181 181 if(path->depth == 0){ 182 182 return EOK; … … 189 189 190 190 switch(flags){ 191 /* path must be completly identical */ 191 /* path is somewhere in report_path */ 192 case USB_HID_PATH_COMPARE_ANYWHERE: 193 if(path->depth != 1){ 194 return 1; 195 } 196 197 // projit skrz cestu a kdyz nekde sedi tak vratim EOK 198 // dojduli az za konec tak nnesedi 199 report_link = report_path->head.next; 200 path_link = path->head.next; 201 path_item = list_get_instance(path_link, usb_hid_report_usage_path_t, link); 202 203 while(report_link != &report_path->head) { 204 report_item = list_get_instance(report_link, usb_hid_report_usage_path_t, link); 205 if(report_item->usage_page == path_item->usage_page){ 206 if(only_page == 0){ 207 if(report_item->usage == path_item->usage) { 208 return EOK; 209 } 210 } 211 else { 212 return EOK; 213 } 214 } 215 216 report_link = report_link->next; 217 } 218 219 return 1; 220 break; 221 /* the paths must be identical */ 192 222 case USB_HID_PATH_COMPARE_STRICT: 193 223 if(report_path->depth != path->depth){ 194 224 return 1; 195 225 } 196 226 227 /* path is prefix of the report_path */ 228 case USB_HID_PATH_COMPARE_BEGIN: 229 197 230 report_link = report_path->head.next; 198 231 path_link = path->head.next; … … 221 254 } 222 255 223 if(((report_link == &report_path->head) && (path_link == &path->head)) || 224 (((flags & USB_HID_PATH_COMPARE_COLLECTION_ONLY) != 0) && 225 (path_link = &path->head) && 226 (report_link == report_path->head.prev))) { 256 if((((flags & USB_HID_PATH_COMPARE_BEGIN) != 0) && (path_link == &path->head)) || 257 ((report_link == &report_path->head) && (path_link == &path->head))) { 227 258 return EOK; 228 259 } … … 232 263 break; 233 264 234 /* compare with only the end of path*/265 /* path is suffix of report_path */ 235 266 case USB_HID_PATH_COMPARE_END: 236 267 237 if((flags & USB_HID_PATH_COMPARE_COLLECTION_ONLY) != 0) { 238 report_link = report_path->head.prev->prev; 239 } 240 else { 241 report_link = report_path->head.prev; 242 } 268 report_link = report_path->head.prev; 243 269 path_link = path->head.prev; 244 270
Note:
See TracChangeset
for help on using the changeset viewer.