Changeset 1553cbf in mainline
- Timestamp:
- 2011-04-22T09:15:43Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- cf2ccd4
- Parents:
- 2020927
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usb/src/hidparser.c
r2020927 r1553cbf 79 79 * Data translation private functions 80 80 */ 81 int32_t usb_hid_report_tag_data_int32(const uint8_t *data, size_t size);81 uint32_t usb_hid_report_tag_data_uint32(const uint8_t *data, size_t size); 82 82 inline size_t usb_hid_count_item_offset(usb_hid_report_item_t * report_item, size_t offset); 83 83 int usb_hid_translate_data(usb_hid_report_field_t *item, const uint8_t *data); … … 85 85 int usb_pow(int a, int b); 86 86 87 #define USB_HID_UINT32_TO_INT32(x, size) ((((x) & (1 << ((size) - 1))) != 0) ? -(~(x - 1) & ((1 << size) - 1)) : (x)) //(-(~((x) - 1))) 88 #define USB_HID_INT32_TO_UINT32(x, size) (((x) < 0 ) ? ((1 << (size)) + (x)) : (x)) 87 89 // TODO: tohle ma bejt asi jinde 88 90 int usb_pow(int a, int b) … … 173 175 if(report_item->usages_count > 0 && ((report_item->usage_minimum == 0) && (report_item->usage_maximum == 0))) { 174 176 uint32_t usage; 175 if(report_item->type == USB_HID_REPORT_TYPE_INPUT) {177 if(report_item->type != USB_HID_REPORT_TYPE_INPUT) { 176 178 if(i < report_item->usages_count){ 177 179 usage = report_item->usages[i]; … … 515 517 { 516 518 case USB_HID_REPORT_TAG_USAGE_PAGE: 517 report_item->usage_page = usb_hid_report_tag_data_ int32(data, item_size);519 report_item->usage_page = usb_hid_report_tag_data_uint32(data, item_size); 518 520 break; 519 521 case USB_HID_REPORT_TAG_LOGICAL_MINIMUM: 520 report_item->logical_minimum = usb_hid_report_tag_data_int32(data,item_size);522 report_item->logical_minimum = USB_HID_UINT32_TO_INT32(usb_hid_report_tag_data_uint32(data,item_size), item_size * 8); 521 523 break; 522 524 case USB_HID_REPORT_TAG_LOGICAL_MAXIMUM: 523 report_item->logical_maximum = usb_hid_report_tag_data_int32(data,item_size);525 report_item->logical_maximum = USB_HID_UINT32_TO_INT32(usb_hid_report_tag_data_uint32(data,item_size), item_size * 8); 524 526 break; 525 527 case USB_HID_REPORT_TAG_PHYSICAL_MINIMUM: 526 report_item->physical_minimum = usb_hid_report_tag_data_int32(data,item_size);528 report_item->physical_minimum = USB_HID_UINT32_TO_INT32(usb_hid_report_tag_data_uint32(data,item_size), item_size * 8); 527 529 break; 528 530 case USB_HID_REPORT_TAG_PHYSICAL_MAXIMUM: 529 report_item->physical_maximum = usb_hid_report_tag_data_int32(data,item_size); 531 report_item->physical_maximum = USB_HID_UINT32_TO_INT32(usb_hid_report_tag_data_uint32(data,item_size), item_size * 8); 532 530 533 break; 531 534 case USB_HID_REPORT_TAG_UNIT_EXPONENT: 532 report_item->unit_exponent = usb_hid_report_tag_data_ int32(data,item_size);535 report_item->unit_exponent = usb_hid_report_tag_data_uint32(data,item_size); 533 536 break; 534 537 case USB_HID_REPORT_TAG_UNIT: 535 report_item->unit = usb_hid_report_tag_data_ int32(data,item_size);538 report_item->unit = usb_hid_report_tag_data_uint32(data,item_size); 536 539 break; 537 540 case USB_HID_REPORT_TAG_REPORT_SIZE: 538 report_item->size = usb_hid_report_tag_data_ int32(data,item_size);541 report_item->size = usb_hid_report_tag_data_uint32(data,item_size); 539 542 break; 540 543 case USB_HID_REPORT_TAG_REPORT_COUNT: 541 report_item->count = usb_hid_report_tag_data_ int32(data,item_size);544 report_item->count = usb_hid_report_tag_data_uint32(data,item_size); 542 545 break; 543 546 case USB_HID_REPORT_TAG_REPORT_ID: 544 report_item->id = usb_hid_report_tag_data_ int32(data,item_size);547 report_item->id = usb_hid_report_tag_data_uint32(data,item_size); 545 548 return USB_HID_RESET_OFFSET; 546 549 break; … … 557 560 return USB_HID_NO_ACTION; 558 561 } 559 562 560 563 return EOK; 561 564 } … … 576 579 { 577 580 case USB_HID_REPORT_TAG_USAGE: 578 report_item->usages[report_item->usages_count] = usb_hid_report_tag_data_ int32(data,item_size);581 report_item->usages[report_item->usages_count] = usb_hid_report_tag_data_uint32(data,item_size); 579 582 report_item->usages_count++; 580 583 break; … … 582 585 if (item_size == 3) { 583 586 // usage extended usages 584 report_item->extended_usage_page = (usb_hid_report_tag_data_ int32(data,item_size) & 0xFF00) >> 16;585 report_item->usage_minimum = usb_hid_report_tag_data_ int32(data,item_size) & 0xFF;587 report_item->extended_usage_page = (usb_hid_report_tag_data_uint32(data,item_size) & 0xFF00) >> 16; 588 report_item->usage_minimum = usb_hid_report_tag_data_uint32(data,item_size) & 0xFF; 586 589 } 587 590 else { 588 report_item->usage_minimum = usb_hid_report_tag_data_ int32(data,item_size);591 report_item->usage_minimum = usb_hid_report_tag_data_uint32(data,item_size); 589 592 } 590 593 break; … … 592 595 if (item_size == 3) { 593 596 // usage extended usages 594 report_item->extended_usage_page = (usb_hid_report_tag_data_ int32(data,item_size) & 0xFF00) >> 16;595 report_item->usage_maximum = usb_hid_report_tag_data_ int32(data,item_size) & 0xFF;597 report_item->extended_usage_page = (usb_hid_report_tag_data_uint32(data,item_size) & 0xFF00) >> 16; 598 report_item->usage_maximum = usb_hid_report_tag_data_uint32(data,item_size) & 0xFF; 596 599 } 597 600 else { 598 report_item->usage_maximum = usb_hid_report_tag_data_ int32(data,item_size);601 report_item->usage_maximum = usb_hid_report_tag_data_uint32(data,item_size); 599 602 } 600 603 break; 601 604 case USB_HID_REPORT_TAG_DESIGNATOR_INDEX: 602 report_item->designator_index = usb_hid_report_tag_data_ int32(data,item_size);605 report_item->designator_index = usb_hid_report_tag_data_uint32(data,item_size); 603 606 break; 604 607 case USB_HID_REPORT_TAG_DESIGNATOR_MINIMUM: 605 report_item->designator_minimum = usb_hid_report_tag_data_ int32(data,item_size);608 report_item->designator_minimum = usb_hid_report_tag_data_uint32(data,item_size); 606 609 break; 607 610 case USB_HID_REPORT_TAG_DESIGNATOR_MAXIMUM: 608 report_item->designator_maximum = usb_hid_report_tag_data_ int32(data,item_size);611 report_item->designator_maximum = usb_hid_report_tag_data_uint32(data,item_size); 609 612 break; 610 613 case USB_HID_REPORT_TAG_STRING_INDEX: 611 report_item->string_index = usb_hid_report_tag_data_ int32(data,item_size);614 report_item->string_index = usb_hid_report_tag_data_uint32(data,item_size); 612 615 break; 613 616 case USB_HID_REPORT_TAG_STRING_MINIMUM: 614 report_item->string_minimum = usb_hid_report_tag_data_ int32(data,item_size);617 report_item->string_minimum = usb_hid_report_tag_data_uint32(data,item_size); 615 618 break; 616 619 case USB_HID_REPORT_TAG_STRING_MAXIMUM: 617 report_item->string_maximum = usb_hid_report_tag_data_ int32(data,item_size);620 report_item->string_maximum = usb_hid_report_tag_data_uint32(data,item_size); 618 621 break; 619 622 case USB_HID_REPORT_TAG_DELIMITER: 620 //report_item->delimiter = usb_hid_report_tag_data_ int32(data,item_size);623 //report_item->delimiter = usb_hid_report_tag_data_uint32(data,item_size); 621 624 //TODO: 622 625 // DELIMITER STUFF … … 631 634 632 635 /** 633 * Converts raw data to int32 (thats the maximum length of short item data)636 * Converts raw data to uint32 (thats the maximum length of short item data) 634 637 * 635 638 * @param Data buffer … … 637 640 * @return Converted int32 number 638 641 */ 639 int32_t usb_hid_report_tag_data_int32(const uint8_t *data, size_t size)642 uint32_t usb_hid_report_tag_data_uint32(const uint8_t *data, size_t size) 640 643 { 641 644 unsigned int i; 642 int32_t result;645 uint32_t result; 643 646 644 647 result = 0; … … 649 652 return result; 650 653 } 651 652 653 654 654 655 /** … … 675 676 usb_log_debug("\t\tOFFSET: %X\n", report_item->offset); 676 677 usb_log_debug("\t\tSIZE: %X\n", report_item->size); 677 usb_log_debug("\t\tLOGMIN: % X\n", report_item->logical_minimum);678 usb_log_debug("\t\tLOGMAX: % X\n", report_item->logical_maximum);679 usb_log_debug("\t\tPHYMIN: % X\n", report_item->physical_minimum);680 usb_log_debug("\t\tPHYMAX: % X\n", report_item->physical_maximum);678 usb_log_debug("\t\tLOGMIN: %d\n", report_item->logical_minimum); 679 usb_log_debug("\t\tLOGMAX: %d\n", report_item->logical_maximum); 680 usb_log_debug("\t\tPHYMIN: %d\n", report_item->physical_minimum); 681 usb_log_debug("\t\tPHYMAX: %d\n", report_item->physical_maximum); 681 682 usb_log_debug("\t\ttUSAGEMIN: %X\n", report_item->usage_minimum); 682 683 usb_log_debug("\t\tUSAGEMAX: %X\n", report_item->usage_maximum); … … 928 929 } 929 930 930 if(!(item->logical_minimum >= 0 && item->logical_maximum >= 0)){ 931 value = (int32_t)value; 932 } 933 else { 934 value = (uint32_t)value; 931 if((item->logical_minimum < 0) || (item->logical_maximum < 0)){ 932 value = USB_HID_UINT32_TO_INT32(value, item->size); 935 933 } 936 934 … … 1539 1537 } 1540 1538 1541 1542 return (uint32_t)ret; 1539 if((item->logical_minimum < 0) || (item->logical_maximum < 0)){ 1540 return USB_HID_INT32_TO_UINT32(ret, item->size); 1541 } 1542 return (int32_t)ret; 1543 1543 } 1544 1544
Note:
See TracChangeset
for help on using the changeset viewer.