Changeset b72efe8 in mainline for uspace/lib/usbhid/src
- Timestamp:
- 2011-06-19T14:38:59Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 74464e8
- Parents:
- 1d1bb0f
- Location:
- uspace/lib/usbhid/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbhid/src/hiddescriptor.c
r1d1bb0f rb72efe8 88 88 * @retval NULL If some error occurs 89 89 */ 90 usb_hid_report_path_t *usb_hid_report_path_try_insert( 91 usb_hid_report_t *report, usb_hid_report_path_t *cmp_path) { 92 93 link_t *path_it = report->collection_paths. next;90 usb_hid_report_path_t *usb_hid_report_path_try_insert(usb_hid_report_t *report, 91 usb_hid_report_path_t *cmp_path) 92 { 93 link_t *path_it = report->collection_paths.head.next; 94 94 usb_hid_report_path_t *path = NULL; 95 95 … … 98 98 } 99 99 100 while(path_it != &report->collection_paths ) {100 while(path_it != &report->collection_paths.head) { 101 101 path = list_get_instance(path_it, usb_hid_report_path_t, 102 link);102 cpath_link); 103 103 104 104 if(usb_hid_report_compare_usage_path(path, cmp_path, 105 105 USB_HID_PATH_COMPARE_STRICT) == EOK){ 106 106 break; 107 } 107 } 108 108 path_it = path_it->next; 109 109 } 110 if(path_it == &report->collection_paths ) {110 if(path_it == &report->collection_paths.head) { 111 111 path = usb_hid_report_path_clone(cmp_path); 112 112 if(path == NULL) { 113 113 return NULL; 114 114 } 115 list_append(&path-> link, &report->collection_paths);115 list_append(&path->cpath_link, &report->collection_paths); 116 116 report->collection_paths_count++; 117 117 … … 120 120 else { 121 121 return list_get_instance(path_it, usb_hid_report_path_t, 122 link);122 cpath_link); 123 123 } 124 124 } … … 192 192 193 193 memset(field, 0, sizeof(usb_hid_report_field_t)); 194 li st_initialize(&field->link);194 link_initialize(&field->ritems_link); 195 195 196 196 /* fill the attributes */ … … 291 291 } 292 292 293 li st_initialize (&report_des->link);293 link_initialize (&report_des->reports_link); 294 294 list_initialize (&report_des->report_items); 295 295 296 list_append(&report_des-> link, &report->reports);296 list_append(&report_des->reports_link, &report->reports); 297 297 report->report_count++; 298 298 } 299 299 300 300 /* append this field to the end of founded report list */ 301 list_append (&field->link, &report_des->report_items);301 list_append(&field->ritems_link, &report_des->report_items); 302 302 303 303 /* update the sizes */ … … 333 333 } 334 334 335 link_t *report_it = report->reports.next;336 335 usb_hid_report_description_t *report_des = NULL; 337 336 338 while(report_it != &report->reports) {337 list_foreach(report->reports, report_it) { 339 338 report_des = list_get_instance(report_it, 340 usb_hid_report_description_t, link);339 usb_hid_report_description_t, reports_link); 341 340 342 341 // if report id not set, return the first of the type … … 345 344 return report_des; 346 345 } 347 348 report_it = report_it->next;349 346 } 350 347 … … 377 374 size_t offset_output=0; 378 375 size_t offset_feature=0; 379 380 link_t stack; 381 list_initialize(&stack); 376 377 link_t *item_link; 378 379 list_t stack; 380 list_initialize(&stack); 382 381 383 382 /* parser structure initialization*/ … … 391 390 } 392 391 memset(report_item, 0, sizeof(usb_hid_report_item_t)); 393 li st_initialize(&(report_item->link));392 link_initialize(&(report_item->link)); 394 393 395 394 /* usage path context initialization */ … … 493 492 case USB_HID_REPORT_TAG_POP: 494 493 // restore current state from stack 495 if(list_empty (&stack)) { 494 item_link = list_first(&stack); 495 if (item_link == NULL) { 496 496 return EINVAL; 497 497 } 498 498 free(report_item); 499 500 report_item = list_get_instance( stack.next,499 500 report_item = list_get_instance(item_link, 501 501 usb_hid_report_item_t, link); 502 502 503 503 usb_hid_report_usage_path_t *tmp_usage_path; 504 504 tmp_usage_path = list_get_instance( 505 report_item->usage_path-> link.prev,506 usb_hid_report_usage_path_t, link);507 505 report_item->usage_path->cpath_link.prev, 506 usb_hid_report_usage_path_t, rpath_items_link); 507 508 508 usb_hid_report_set_last_item(usage_path, 509 509 USB_HID_TAG_CLASS_GLOBAL, tmp_usage_path->usage_page); … … 513 513 514 514 usb_hid_report_path_free(report_item->usage_path); 515 list_remove ( stack.next);515 list_remove (item_link); 516 516 517 517 break; … … 609 609 610 610 /* store collection atributes */ 611 path_item = list_get_instance( usage_path->head.prev,612 usb_hid_report_usage_path_t, link);613 path_item->flags = *data; 611 path_item = list_get_instance(list_first(&usage_path->items), 612 usb_hid_report_usage_path_t, rpath_items_link); 613 path_item->flags = *data; 614 614 615 615 /* set last item */ … … 900 900 * @return void 901 901 */ 902 void usb_hid_descriptor_print_list(li nk_t *head)902 void usb_hid_descriptor_print_list(list_t *list) 903 903 { 904 904 usb_hid_report_field_t *report_item; 905 link_t *item; 906 907 908 if(head == NULL || list_empty(head)) { 905 906 if(list == NULL || list_empty(list)) { 909 907 usb_log_debug("\tempty\n"); 910 908 return; 911 909 } 912 913 for(item = head->next; item != head; item = item->next) { 914 915 report_item = list_get_instance(item, usb_hid_report_field_t, 916 link); 910 911 list_foreach(*list, item) { 912 report_item = list_get_instance(item, usb_hid_report_field_t, 913 ritems_link); 917 914 918 915 usb_log_debug("\t\tOFFSET: %X\n", report_item->offset); 919 916 usb_log_debug("\t\tSIZE: %zu\n", report_item->size); 920 usb_log_debug("\t\tLOGMIN: %d\n", 917 usb_log_debug("\t\tLOGMIN: %d\n", 921 918 report_item->logical_minimum); 922 usb_log_debug("\t\tLOGMAX: %d\n", 923 report_item->logical_maximum); 924 usb_log_debug("\t\tPHYMIN: %d\n", 925 report_item->physical_minimum); 926 usb_log_debug("\t\tPHYMAX: %d\n", 927 report_item->physical_maximum); 928 usb_log_debug("\t\ttUSAGEMIN: %X\n", 919 usb_log_debug("\t\tLOGMAX: %d\n", 920 report_item->logical_maximum); 921 usb_log_debug("\t\tPHYMIN: %d\n", 922 report_item->physical_minimum); 923 usb_log_debug("\t\tPHYMAX: %d\n", 924 report_item->physical_maximum); 925 usb_log_debug("\t\ttUSAGEMIN: %X\n", 929 926 report_item->usage_minimum); 930 927 usb_log_debug("\t\tUSAGEMAX: %X\n", 931 928 report_item->usage_maximum); 932 usb_log_debug("\t\tUSAGES COUNT: %zu\n", 929 usb_log_debug("\t\tUSAGES COUNT: %zu\n", 933 930 report_item->usages_count); 934 931 … … 936 933 usb_log_debug("\t\ttUSAGE: %X\n", report_item->usage); 937 934 usb_log_debug("\t\tUSAGE PAGE: %X\n", report_item->usage_page); 938 935 939 936 usb_hid_print_usage_path(report_item->collection_path); 940 937 941 usb_log_debug("\n"); 938 usb_log_debug("\n"); 942 939 943 940 } … … 958 955 } 959 956 960 link_t *report_it = report->reports.next;961 957 usb_hid_report_description_t *report_des; 962 958 963 while(report_it != &report->reports) {964 report_des = list_get_instance(report_it, 965 usb_hid_report_description_t, link);959 list_foreach(report->reports, report_it) { 960 report_des = list_get_instance(report_it, 961 usb_hid_report_description_t, reports_link); 966 962 usb_log_debug("Report ID: %d\n", report_des->report_id); 967 963 usb_log_debug("\tType: %d\n", report_des->type); 968 usb_log_debug("\tLength: %zu\n", report_des->bit_length); 964 usb_log_debug("\tLength: %zu\n", report_des->bit_length); 969 965 usb_log_debug("\tB Size: %zu\n", 970 usb_hid_report_byte_size(report, 971 report_des->report_id, 966 usb_hid_report_byte_size(report, 967 report_des->report_id, 972 968 report_des->type)); 973 usb_log_debug("\tItems: %zu\n", report_des->item_length); 969 usb_log_debug("\tItems: %zu\n", report_des->item_length); 974 970 975 971 usb_hid_descriptor_print_list(&report_des->report_items); 976 977 report_it = report_it->next;978 972 } 979 973 } … … 983 977 * Releases whole linked list of report items 984 978 * 985 * @param head Head of list of report descriptor items (usb_hid_report_item_t)979 * @param list List of report descriptor items (usb_hid_report_item_t) 986 980 * @return void 987 981 */ 988 void usb_hid_free_report_list(li nk_t *head)982 void usb_hid_free_report_list(list_t *list) 989 983 { 990 return; 991 992 usb_hid_report_item_t *report_item;984 return; /* XXX What's this? */ 985 986 /* usb_hid_report_item_t *report_item; 993 987 link_t *next; 994 988 995 if( head == NULL || list_empty(head)) {989 if(list == NULL || list_empty(list)) { 996 990 return; 997 991 } 998 992 999 next = head->next;1000 while (next !=head) {1001 1002 report_item = list_get_instance(next, usb_hid_report_item_t,link);993 next = list->head.next; 994 while (next != &list->head) { 995 report_item = list_get_instance(next, usb_hid_report_item_t, 996 rpath_items_link); 1003 997 1004 998 while(!list_empty(&report_item->usage_path->link)) { 1005 999 usb_hid_report_remove_last_item(report_item->usage_path); 1006 1000 } 1007 1001 … … 1013 1007 1014 1008 return; 1015 1009 */ 1016 1010 } 1017 1011 /*---------------------------------------------------------------------------*/ … … 1029 1023 1030 1024 // free collection paths 1025 link_t *path_link; 1031 1026 usb_hid_report_path_t *path; 1032 1027 while(!list_empty(&report->collection_paths)) { 1033 path = list_get_instance(report->collection_paths.next, 1034 usb_hid_report_path_t, link); 1035 1036 usb_hid_report_path_free(path); 1028 path_link = list_first(&report->collection_paths); 1029 path = list_get_instance(path_link, 1030 usb_hid_report_path_t, cpath_link); 1031 1032 list_remove(path_link); 1033 usb_hid_report_path_free(path); 1037 1034 } 1038 1035 … … 1041 1038 usb_hid_report_field_t *field; 1042 1039 while(!list_empty(&report->reports)) { 1043 report_des = list_get_instance( report->reports.next,1044 usb_hid_report_description_t, link);1045 1046 list_remove(&report_des-> link);1040 report_des = list_get_instance(list_first(&report->reports), 1041 usb_hid_report_description_t, reports_link); 1042 1043 list_remove(&report_des->reports_link); 1047 1044 1048 1045 while(!list_empty(&report_des->report_items)) { 1049 1046 field = list_get_instance( 1050 report_des->report_items.next,1051 usb_hid_report_field_t,link);1052 1053 list_remove(&field-> link);1047 list_first(&report_des->report_items), 1048 usb_hid_report_field_t, ritems_link); 1049 1050 list_remove(&field->ritems_link); 1054 1051 1055 1052 free(field); -
uspace/lib/usbhid/src/hidparser.c
r1d1bb0f rb72efe8 135 135 size_t size, uint8_t *report_id) 136 136 { 137 link_t *list_item;138 137 usb_hid_report_field_t *item; 139 138 … … 161 160 162 161 /* read data */ 163 list_item = report_des->report_items.next; 164 while(list_item != &(report_des->report_items)) { 165 162 list_foreach(report_des->report_items, list_item) { 166 163 item = list_get_instance(list_item, usb_hid_report_field_t, 167 link);164 ritems_link); 168 165 169 166 if(USB_HID_ITEM_FLAG_CONSTANT(item->item_flags) == 0) { … … 200 197 } 201 198 } 202 list_item = list_item->next;203 199 } 204 200 … … 310 306 } 311 307 312 link_t *report_it = report->reports.next;313 308 usb_hid_report_description_t *report_des = NULL; 314 while(report_it != &report->reports) { 315 report_des = list_get_instance(report_it, 316 usb_hid_report_description_t, link); 309 310 list_foreach(report->reports, report_it) { 311 report_des = list_get_instance(report_it, 312 usb_hid_report_description_t, reports_link); 317 313 318 if((report_des->report_id == report_id) && 314 if((report_des->report_id == report_id) && 319 315 (report_des->type == USB_HID_REPORT_TYPE_OUTPUT)){ 320 316 break; 321 317 } 322 323 report_it = report_it->next;324 318 } 325 319 … … 362 356 uint8_t report_id, uint8_t *buffer, size_t size) 363 357 { 364 link_t *item;365 358 int32_t value=0; 366 359 int offset; … … 384 377 } 385 378 386 usb_hid_report_field_t *report_item; 387 item = report_des->report_items.next; 388 while(item != &report_des->report_items) { 389 report_item = list_get_instance(item, usb_hid_report_field_t, link); 379 usb_hid_report_field_t *report_item; 380 381 list_foreach(report_des->report_items, item) { 382 report_item = list_get_instance(item, usb_hid_report_field_t, 383 ritems_link); 390 384 391 385 value = usb_hid_translate_data_reverse(report_item, … … 449 443 // reset value 450 444 report_item->value = 0; 451 452 item = item->next;453 445 } 454 446 … … 550 542 551 543 if(field == NULL){ 552 field_it = report_des->report_items. next;553 } 554 else { 555 field_it = field-> link.next;556 } 557 558 while(field_it != &report_des->report_items ) {544 field_it = report_des->report_items.head.next; 545 } 546 else { 547 field_it = field->ritems_link.next; 548 } 549 550 while(field_it != &report_des->report_items.head) { 559 551 field = list_get_instance(field_it, usb_hid_report_field_t, 560 link);552 ritems_link); 561 553 562 554 if(USB_HID_ITEM_FLAG_CONSTANT(field->item_flags) == 0) { … … 611 603 } 612 604 else { 613 report_it = report_des-> link.next;605 report_it = report_des->reports_link.next; 614 606 } 615 607 } 616 608 else { 617 report_it = report->reports. next;618 } 619 620 while(report_it != &report->reports ) {609 report_it = report->reports.head.next; 610 } 611 612 while(report_it != &report->reports.head) { 621 613 report_des = list_get_instance(report_it, 622 usb_hid_report_description_t, link);614 usb_hid_report_description_t, reports_link); 623 615 624 616 if(report_des->type == type){ -
uspace/lib/usbhid/src/hidpath.c
r1d1bb0f rb72efe8 81 81 return ENOMEM; 82 82 } 83 li st_initialize(&item->link);83 link_initialize(&item->rpath_items_link); 84 84 85 85 item->usage = usage; … … 87 87 item->flags = 0; 88 88 89 list_append (&item-> link, &usage_path->head);89 list_append (&item->rpath_items_link, &usage_path->items); 90 90 usage_path->depth++; 91 91 return EOK; … … 100 100 void usb_hid_report_remove_last_item(usb_hid_report_path_t *usage_path) 101 101 { 102 link_t *item_link; 102 103 usb_hid_report_usage_path_t *item; 103 104 104 if(!list_empty(&usage_path->head)){ 105 item = list_get_instance(usage_path->head.prev, 106 usb_hid_report_usage_path_t, link); 107 list_remove(usage_path->head.prev); 105 if(!list_empty(&usage_path->items)){ 106 item_link = list_last(&usage_path->items); 107 item = list_get_instance(item_link, 108 usb_hid_report_usage_path_t, rpath_items_link); 109 list_remove(item_link); 108 110 usage_path->depth--; 109 111 free(item); … … 122 124 usb_hid_report_usage_path_t *item; 123 125 124 if(!list_empty(&usage_path-> head)){125 item = list_get_instance( usage_path->head.prev,126 usb_hid_report_usage_path_t, link);126 if(!list_empty(&usage_path->items)){ 127 item = list_get_instance(list_last(&usage_path->items), 128 usb_hid_report_usage_path_t, rpath_items_link); 127 129 128 130 memset(item, 0, sizeof(usb_hid_report_usage_path_t)); … … 145 147 usb_hid_report_usage_path_t *item; 146 148 147 if(!list_empty(&usage_path-> head)){148 item = list_get_instance( usage_path->head.prev,149 usb_hid_report_usage_path_t,link);149 if(!list_empty(&usage_path->items)){ 150 item = list_get_instance(list_last(&usage_path->items), 151 usb_hid_report_usage_path_t, rpath_items_link); 150 152 151 153 switch(tag) { … … 173 175 usb_log_debug("\tLENGTH: %d\n", path->depth); 174 176 175 link_t *item = path->head.next;176 177 usb_hid_report_usage_path_t *path_item; 177 while(item != &path->head) { 178 179 path_item = list_get_instance(item, usb_hid_report_usage_path_t, 180 link);178 179 list_foreach(path->items, item) { 180 path_item = list_get_instance(item, usb_hid_report_usage_path_t, 181 rpath_items_link); 181 182 182 183 usb_log_debug("\tUSAGE_PAGE: %X\n", path_item->usage_page); 183 184 usb_log_debug("\tUSAGE: %X\n", path_item->usage); 184 usb_log_debug("\tFLAGS: %d\n", path_item->flags); 185 186 item = item->next; 185 usb_log_debug("\tFLAGS: %d\n", path_item->flags); 187 186 } 188 187 } … … 233 232 } 234 233 235 report_link = report_path->head.next; 236 path_link = path->head.next; 237 path_item = list_get_instance(path_link, 238 usb_hid_report_usage_path_t, link); 239 240 while(report_link != &report_path->head) { 241 report_item = list_get_instance(report_link, 242 usb_hid_report_usage_path_t, link); 234 path_link = list_first(&path->items); 235 path_item = list_get_instance(path_link, 236 usb_hid_report_usage_path_t, rpath_items_link); 237 238 list_foreach(report_path->items, report_link) { 239 report_item = list_get_instance(report_link, 240 usb_hid_report_usage_path_t, rpath_items_link); 243 241 244 if(USB_HID_SAME_USAGE_PAGE(report_item->usage_page, 242 if(USB_HID_SAME_USAGE_PAGE(report_item->usage_page, 245 243 path_item->usage_page)){ 246 244 … … 257 255 } 258 256 } 259 260 report_link = report_link->next;261 257 } 262 258 … … 273 269 case USB_HID_PATH_COMPARE_BEGIN: 274 270 275 report_link = report_path-> head.next;276 path_link = path-> head.next;271 report_link = report_path->items.head.next; 272 path_link = path->items.head.next; 277 273 278 while((report_link != &report_path-> head) &&279 (path_link != &path-> head)) {274 while((report_link != &report_path->items.head) && 275 (path_link != &path->items.head)) { 280 276 281 277 report_item = list_get_instance(report_link, 282 usb_hid_report_usage_path_t, link);278 usb_hid_report_usage_path_t, rpath_items_link); 283 279 284 280 path_item = list_get_instance(path_link, 285 usb_hid_report_usage_path_t, link);281 usb_hid_report_usage_path_t, rpath_items_link); 286 282 287 283 if(!USB_HID_SAME_USAGE_PAGE(report_item->usage_page, … … 297 293 } 298 294 299 295 } 300 296 301 297 if((((flags & USB_HID_PATH_COMPARE_BEGIN) != 0) && 302 (path_link == &path-> head)) ||303 ((report_link == &report_path-> head) &&304 (path_link == &path-> head))) {298 (path_link == &path->items.head)) || 299 ((report_link == &report_path->items.head) && 300 (path_link == &path->items.head))) { 305 301 306 302 return EOK; … … 314 310 case USB_HID_PATH_COMPARE_END: 315 311 316 report_link = report_path-> head.prev;317 path_link = path-> head.prev;318 319 if(list_empty(&path-> head)){312 report_link = report_path->items.head.prev; 313 path_link = path->items.head.prev; 314 315 if(list_empty(&path->items)){ 320 316 return EOK; 321 317 } 322 318 323 while((report_link != &report_path-> head) &&324 (path_link != &path-> head)) {319 while((report_link != &report_path->items.head) && 320 (path_link != &path->items.head)) { 325 321 326 report_item = list_get_instance(report_link, 327 usb_hid_report_usage_path_t, link);322 report_item = list_get_instance(report_link, 323 usb_hid_report_usage_path_t, rpath_items_link); 328 324 329 325 path_item = list_get_instance(path_link, 330 usb_hid_report_usage_path_t, link);326 usb_hid_report_usage_path_t, rpath_items_link); 331 327 332 328 if(!USB_HID_SAME_USAGE_PAGE(report_item->usage_page, … … 343 339 } 344 340 345 if(path_link == &path-> head) {341 if(path_link == &path->items.head) { 346 342 return EOK; 347 343 } … … 373 369 path->depth = 0; 374 370 path->report_id = 0; 375 li st_initialize(&path->link);376 list_initialize(&path-> head);371 link_initialize(&path->cpath_link); 372 list_initialize(&path->items); 377 373 return path; 378 374 } … … 388 384 void usb_hid_report_path_free(usb_hid_report_path_t *path) 389 385 { 390 while(!list_empty(&path-> head)){386 while(!list_empty(&path->items)){ 391 387 usb_hid_report_remove_last_item(path); 392 388 } 393 389 394 list_remove(&path->link);390 assert_link_not_used(&path->cpath_link); 395 391 free(path); 396 392 } … … 406 402 usb_hid_report_path_t *usage_path) 407 403 { 408 link_t *path_link;409 404 usb_hid_report_usage_path_t *path_item; 410 405 usb_hid_report_usage_path_t *new_path_item; … … 417 412 new_usage_path->report_id = usage_path->report_id; 418 413 419 if(list_empty(&usage_path-> head)){414 if(list_empty(&usage_path->items)){ 420 415 return new_usage_path; 421 416 } 422 417 423 path_link = usage_path->head.next; 424 while(path_link != &usage_path->head) { 425 path_item = list_get_instance(path_link, 426 usb_hid_report_usage_path_t, link); 418 list_foreach(usage_path->items, path_link) { 419 path_item = list_get_instance(path_link, 420 usb_hid_report_usage_path_t, rpath_items_link); 427 421 428 422 new_path_item = malloc(sizeof(usb_hid_report_usage_path_t)); … … 431 425 } 432 426 433 li st_initialize (&new_path_item->link);427 link_initialize(&new_path_item->rpath_items_link); 434 428 new_path_item->usage_page = path_item->usage_page; 435 429 new_path_item->usage = path_item->usage; 436 430 new_path_item->flags = path_item->flags; 437 431 438 list_append(&new_path_item->link, &new_usage_path->head); 432 list_append(&new_path_item->rpath_items_link, 433 &new_usage_path->items); 439 434 new_usage_path->depth++; 440 441 path_link = path_link->next;442 435 } 443 436
Note:
See TracChangeset
for help on using the changeset viewer.