Changeset c156c2d in mainline
- Timestamp:
- 2011-04-07T20:34:12Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a694a58
- Parents:
- b04967a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usb/src/hidparser.c
rb04967a rc156c2d 70 70 int32_t usb_hid_report_tag_data_int32(const uint8_t *data, size_t size); 71 71 inline size_t usb_hid_count_item_offset(usb_hid_report_item_t * report_item, size_t offset); 72 int usb_hid_translate_data( usb_hid_report_item_t *item, const uint8_t *data, size_t j);72 int usb_hid_translate_data(const usb_hid_report_parser_t *parser, usb_hid_report_item_t *item, const uint8_t *data, size_t j); 73 73 int32_t usb_hid_translate_data_reverse(usb_hid_report_item_t *item, int32_t value); 74 74 int usb_pow(int a, int b); … … 103 103 104 104 list_initialize(&(parser->input)); 105 list_initialize(&(parser->output));106 list_initialize(&(parser->feature));105 list_initialize(&(parser->output)); 106 list_initialize(&(parser->feature)); 107 107 108 108 list_initialize(&(parser->stack)); … … 246 246 // push current state to stack 247 247 new_report_item = usb_hid_report_item_clone(report_item); 248 list_prepend (&parser->stack, &new_report_item->link); 249 248 usb_hid_report_path_t *tmp_path = usb_hid_report_path_clone(usage_path); 249 new_report_item->usage_path = tmp_path; 250 251 list_prepend (&new_report_item->link, &parser->stack); 250 252 break; 251 253 case USB_HID_REPORT_TAG_POP: … … 254 256 return EINVAL; 255 257 } 258 free(report_item); 259 260 report_item = list_get_instance(parser->stack.next, usb_hid_report_item_t, link); 256 261 257 report_item = list_get_instance(&parser->stack, usb_hid_report_item_t, link); 262 usb_hid_report_usage_path_t *tmp_usage_path; 263 tmp_usage_path = list_get_instance(report_item->usage_path->link.prev, usb_hid_report_usage_path_t, link); 264 265 usb_hid_report_set_last_item(usage_path, tmp_usage_path->usage_page, tmp_usage_path->usage); 266 267 usb_hid_report_path_free(report_item->usage_path); 268 list_initialize(&report_item->usage_path->link); 258 269 list_remove (parser->stack.next); 259 270 … … 469 480 case USB_HID_REPORT_TAG_PUSH: 470 481 case USB_HID_REPORT_TAG_POP: 482 usb_log_debug("PUSH/POP processed\n"); 471 483 return tag; 472 484 break; … … 678 690 usb_hid_free_report_list(&parser->output); 679 691 usb_hid_free_report_list(&parser->feature); 680 692 usb_hid_free_report_list(&parser->stack); 681 693 return; 682 694 } … … 709 721 return EINVAL; 710 722 } 711 712 /* get the size of result array */713 key_count = usb_hid_report_input_length(parser, path, flags);714 715 if(!(keys = malloc(sizeof(uint8_t) * key_count))){716 return ENOMEM;717 }718 723 719 724 if(parser->use_report_id != 0) { 720 725 report_id = data[0]; 721 726 usb_hid_report_path_set_report_id(path, report_id); 727 } 728 729 730 /* get the size of result array */ 731 key_count = usb_hid_report_input_length(parser, path, flags); 732 733 if(!(keys = malloc(sizeof(uint8_t) * key_count))){ 734 return ENOMEM; 722 735 } 723 736 … … 734 747 ((item->usage_minimum == 0) && (item->usage_maximum == 0))) { 735 748 // variable item 736 keys[i++] = usb_hid_translate_data( item, data,j);749 keys[i++] = usb_hid_translate_data(parser, item, data,j); 737 750 } 738 751 else { 739 752 // bitmapa 740 if((item_value = usb_hid_translate_data( item, data, j)) != 0) {753 if((item_value = usb_hid_translate_data(parser, item, data, j)) != 0) { 741 754 keys[i++] = (item->count - 1 - j) + item->usage_minimum; 742 755 } … … 758 771 759 772 /** 760 * Translate data from the report as specified in report descriptor 773 * Translate data from the report as specified in report descriptor item 761 774 * 762 775 * @param item Report descriptor item with definition of translation … … 765 778 * @return Translated data 766 779 */ 767 int usb_hid_translate_data( usb_hid_report_item_t *item, const uint8_t *data, size_t j)780 int usb_hid_translate_data(const usb_hid_report_parser_t *parser, usb_hid_report_item_t *item, const uint8_t *data, size_t j) 768 781 { 769 782 int resolution; … … 775 788 const uint8_t *foo; 776 789 777 // now only common numbersllowed790 // now only shot tags are allowed 778 791 if(item->size > 32) { 779 792 return 0; … … 795 808 796 809 offset = item->offset + (j * item->size); 797 if( item->id != 0) {810 if(parser->use_report_id != 0) { 798 811 offset += 8; 799 usb_log_debug("MOVED OFFSET BY 1Byte, REPORT_ID(%d)\n", item->id);800 812 } 801 813 … … 1157 1169 *size = (last->offset + (last->size * last->count)) / 8; 1158 1170 1171 if(parser->use_report_id != 0) { 1172 *size += 1; 1173 } 1174 1159 1175 uint8_t *buffer = malloc(sizeof(uint8_t) * (*size)); 1160 1176 memset(buffer, 0, sizeof(uint8_t) * (*size)); … … 1210 1226 1211 1227 item = item->next; 1212 } 1228 } 1213 1229 1214 1230 return ret;
Note:
See TracChangeset
for help on using the changeset viewer.