Changeset 57d9c05e in mainline
- Timestamp:
- 2011-03-25T17:15:26Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 841e6e5
- Parents:
- 9c0f158
- Location:
- uspace/lib/usb
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usb/include/usb/classes/hidparser.h
r9c0f158 r57d9c05e 31 31 */ 32 32 /** @file 33 * @brief USB HID parser.33 * USB HID report descriptor and report data parser 34 34 */ 35 35 #ifndef LIBUSB_HIDPARSER_H_ … … 74 74 #define USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY 4 75 75 76 /** */ 76 77 typedef struct { 78 /** */ 77 79 int32_t usage_page; 80 /** */ 78 81 int32_t usage; 79 82 /** */ 80 83 link_t link; 81 84 } usb_hid_report_usage_path_t; 82 85 86 /** */ 83 87 typedef struct { 88 /** */ 84 89 int depth; 90 91 /** */ 85 92 link_t link; 86 93 } usb_hid_report_path_t; … … 90 97 */ 91 98 typedef struct { 99 /** */ 92 100 int32_t id; 101 /** */ 93 102 int32_t usage_minimum; 103 /** */ 94 104 int32_t usage_maximum; 105 /** */ 95 106 int32_t logical_minimum; 107 /** */ 96 108 int32_t logical_maximum; 109 /** */ 97 110 int32_t size; 111 /** */ 98 112 int32_t count; 113 /** */ 99 114 size_t offset; 115 /** */ 100 116 int32_t delimiter; 101 117 /** */ 102 118 int32_t unit_exponent; 119 /** */ 103 120 int32_t unit; 104 121 105 /* 106 * some not yet used fields 107 */ 122 /** */ 108 123 int32_t string_index; 124 /** */ 109 125 int32_t string_minimum; 126 /** */ 110 127 int32_t string_maximum; 128 /** */ 111 129 int32_t designator_index; 130 /** */ 112 131 int32_t designator_minimum; 132 /** */ 113 133 int32_t designator_maximum; 134 /** */ 114 135 int32_t physical_minimum; 136 /** */ 115 137 int32_t physical_maximum; 116 138 139 /** */ 117 140 uint8_t item_flags; 118 141 142 /** */ 119 143 usb_hid_report_path_t *usage_path; 144 /** */ 120 145 link_t link; 121 146 } usb_hid_report_item_t; … … 124 149 /** HID report parser structure. */ 125 150 typedef struct { 151 /** */ 126 152 link_t input; 153 /** */ 127 154 link_t output; 155 /** */ 128 156 link_t feature; 129 157 } usb_hid_report_parser_t; … … 190 218 191 219 /* 192 * modifiers definitions 193 */ 194 220 * Descriptor parser functions 221 */ 222 /** */ 223 int usb_hid_parser_init(usb_hid_report_parser_t *parser); 224 225 /** */ 226 int usb_hid_parse_report_descriptor(usb_hid_report_parser_t *parser, 227 const uint8_t *data, size_t size); 228 229 /** */ 230 void usb_hid_free_report_parser(usb_hid_report_parser_t *parser); 231 232 /** */ 233 void usb_hid_descriptor_print(usb_hid_report_parser_t *parser); 234 235 /* 236 * Boot protocol functions 237 */ 238 /** */ 195 239 int usb_hid_boot_keyboard_input_report(const uint8_t *data, size_t size, 196 240 const usb_hid_report_in_callbacks_t *callbacks, void *arg); 197 241 242 /** */ 198 243 int usb_hid_boot_keyboard_output_report(uint8_t leds, uint8_t *data, size_t size); 199 244 200 int usb_hid_parser_init(usb_hid_report_parser_t *parser); 201 int usb_hid_parse_report_descriptor(usb_hid_report_parser_t *parser, 202 const uint8_t *data, size_t size); 203 245 246 /* 247 * Input report parser functions 248 */ 249 /** */ 204 250 int usb_hid_parse_report(const usb_hid_report_parser_t *parser, 205 251 const uint8_t *data, size_t size, … … 207 253 const usb_hid_report_in_callbacks_t *callbacks, void *arg); 208 254 255 /** */ 209 256 size_t usb_hid_report_input_length(const usb_hid_report_parser_t *parser, 210 257 usb_hid_report_path_t *path, int flags); 211 258 212 259 213 void usb_hid_free_report_parser(usb_hid_report_parser_t *parser); 214 215 void usb_hid_descriptor_print(usb_hid_report_parser_t *parser); 216 217 /* usage path functions*/260 261 /* 262 * usage path functions 263 */ 264 /** */ 218 265 usb_hid_report_path_t *usb_hid_report_path(void); 266 267 /** */ 219 268 void usb_hid_report_path_free(usb_hid_report_path_t *path); 269 270 /** */ 220 271 int usb_hid_report_path_append_item(usb_hid_report_path_t *usage_path, int32_t usage_page, int32_t usage); 272 273 /** */ 221 274 void usb_hid_report_remove_last_item(usb_hid_report_path_t *usage_path); 275 276 /** */ 222 277 void usb_hid_report_null_last_item(usb_hid_report_path_t *usage_path); 278 279 /** */ 223 280 void usb_hid_report_set_last_item(usb_hid_report_path_t *usage_path, int32_t tag, int32_t data); 281 282 /** */ 224 283 int usb_hid_report_compare_usage_path(usb_hid_report_path_t *report_path, usb_hid_report_path_t *path, int flags); 284 285 /** */ 225 286 usb_hid_report_path_t *usb_hid_report_path_clone(usb_hid_report_path_t *usage_path); 226 287 227 288 228 // output API 289 /* 290 * Output report parser functions 291 */ 229 292 /** Allocates output report buffer*/ 230 293 uint8_t *usb_hid_report_output(usb_hid_report_parser_t *parser); 294 231 295 /** Frees output report buffer*/ 232 296 void usb_hid_report_output_free(uint8_t *output); … … 235 299 size_t usb_hid_report_output_size(usb_hid_report_parser_t *parser, 236 300 usb_hid_report_path_t *path, int flags); 301 237 302 /** Updates the output report buffer by translated given data */ 238 303 int usb_hid_report_output_translate(usb_hid_report_parser_t *parser, -
uspace/lib/usb/src/hidparser.c
r9c0f158 r57d9c05e 31 31 */ 32 32 /** @file 33 * @brief HIDparser implementation.33 * HID report descriptor and report data parser implementation. 34 34 */ 35 35 #include <usb/classes/hidparser.h> … … 40 40 #include <usb/debug.h> 41 41 42 /** */ 42 43 #define USB_HID_NEW_REPORT_ITEM 1 44 45 /** */ 43 46 #define USB_HID_NO_ACTION 2 47 48 /** */ 44 49 #define USB_HID_UNKNOWN_TAG -99 45 50 46 #define BAD_HACK_USAGE_PAGE 0x07 47 51 /* 52 * Private descriptor parser functions 53 */ 48 54 int usb_hid_report_parse_tag(uint8_t tag, uint8_t class, const uint8_t *data, size_t item_size, 49 55 usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path); … … 58 64 int usb_hid_report_reset_local_items(); 59 65 void usb_hid_free_report_list(link_t *head); 66 67 /* 68 * Data translation private functions 69 */ 60 70 int32_t usb_hid_report_tag_data_int32(const uint8_t *data, size_t size); 61 71 inline size_t usb_hid_count_item_offset(usb_hid_report_item_t * report_item, size_t offset); … … 63 73 int usb_pow(int a, int b); 64 74 65 75 // TODO: tohle ma bejt asi jinde 66 76 int usb_pow(int a, int b) 67 77 { … … 80 90 81 91 /** 82 * 92 * Initialize the report descriptor parser structure 93 * 94 * @param parser Report descriptor parser structure 95 * @return Error code 83 96 */ 84 97 int usb_hid_parser_init(usb_hid_report_parser_t *parser) 85 98 { 86 87 return EINVAL;88 89 90 99 if(parser == NULL) { 100 return EINVAL; 101 } 102 103 list_initialize(&(parser->input)); 91 104 list_initialize(&(parser->output)); 92 105 list_initialize(&(parser->feature)); … … 301 314 302 315 /** 316 * Parse one tag of the report descriptor 303 317 * 304 318 * @param Tag to parse … … 517 531 * Prints content of given list of report items. 518 532 * 519 * @param List of report items 533 * @param List of report items (usb_hid_report_item_t) 520 534 * @return void 521 535 */ … … 549 563 path = path->next; 550 564 } 551 552 553 // usb_log_debug("\tUSAGE: %X\n", report_item->usage); 554 // usb_log_debug("\tUSAGE PAGE: %X\n", report_item->usage_page); 565 555 566 usb_log_debug("\tLOGMIN: %X\n", report_item->logical_minimum); 556 567 usb_log_debug("\tLOGMAX: %X\n", report_item->logical_maximum); … … 567 578 } 568 579 /** 569 * Prints content of given descriptor in human readable format.570 * 571 * @param Parsed descriptor to print580 * Prints content of given report descriptor in human readable format. 581 * 582 * @param parser Parsed descriptor to print 572 583 * @return void 573 584 */ … … 592 603 * Releases whole linked list of report items 593 604 * 594 * 605 * @param head Head of list of report descriptor items (usb_hid_report_item_t) 606 * @return void 595 607 */ 596 608 void usb_hid_free_report_list(link_t *head) … … 624 636 } 625 637 626 /** Free the HID reportparser structure638 /** Frees the HID report descriptor parser structure 627 639 * 628 640 * @param parser Opaque HID report parser structure 629 * @return Error code641 * @return void 630 642 */ 631 643 void usb_hid_free_report_parser(usb_hid_report_parser_t *parser) … … 657 669 const usb_hid_report_in_callbacks_t *callbacks, void *arg) 658 670 { 659 /*660 *661 * only key codes (usage page 0x07) will be processed662 * other usages will be ignored663 */664 671 link_t *list_item; 665 672 usb_hid_report_item_t *item; … … 673 680 return EINVAL; 674 681 } 675 676 677 // get the size of result keycodes array 682 683 /* get the size of result array */ 678 684 key_count = usb_hid_report_input_length(parser, path, flags); 679 685 … … 682 688 } 683 689 684 / / read data690 /* read data */ 685 691 list_item = parser->input.next; 686 692 while(list_item != &(parser->input)) { … … 716 722 } 717 723 718 724 /** 725 * Translate data from the report as specified in report descriptor 726 * 727 * @param item Report descriptor item with definition of translation 728 * @param data Data to translate 729 * @param j Index of processed field in report descriptor item 730 * @return Translated data 731 */ 719 732 int usb_hid_translate_data(usb_hid_report_item_t *item, const uint8_t *data, size_t j) 720 733 { … … 793 806 } 794 807 808 /** 809 * 810 * 811 * @param parser 812 * @param path 813 * @param flags 814 * @return 815 */ 795 816 size_t usb_hid_report_input_length(const usb_hid_report_parser_t *parser, 796 817 usb_hid_report_path_t *path, int flags) 797 818 { 798 int ret = 0;819 size_t ret = 0; 799 820 link_t *item; 800 821 usb_hid_report_item_t *report_item; 801 822 802 823 if(parser == NULL) { 803 return EINVAL;804 } 805 806 item = (&parser->input)->next;824 return 0; 825 } 826 827 item = parser->input.next; 807 828 while(&parser->input != item) { 808 829 report_item = list_get_instance(item, usb_hid_report_item_t, link); … … 821 842 /** 822 843 * 844 * @param usage_path 845 * @param usage_page 846 * @param usage 847 * @return 823 848 */ 824 849 int usb_hid_report_path_append_item(usb_hid_report_path_t *usage_path, … … 842 867 /** 843 868 * 869 * @param usage_path 870 * @return 844 871 */ 845 872 void usb_hid_report_remove_last_item(usb_hid_report_path_t *usage_path) … … 857 884 /** 858 885 * 886 * @param usage_path 887 * @return 859 888 */ 860 889 void usb_hid_report_null_last_item(usb_hid_report_path_t *usage_path) … … 870 899 /** 871 900 * 901 * @param usage_path 902 * @param tag 903 * @param data 904 * @return 872 905 */ 873 906 void usb_hid_report_set_last_item(usb_hid_report_path_t *usage_path, int32_t tag, int32_t data) … … 891 924 892 925 /** 893 * 926 * 927 * 928 * @param report_path 929 * @param path 930 * @param flags 931 * @return 894 932 */ 895 933 int usb_hid_report_compare_usage_path(usb_hid_report_path_t *report_path, … … 989 1027 /** 990 1028 * 1029 * @return 991 1030 */ 992 1031 usb_hid_report_path_t *usb_hid_report_path(void) … … 1006 1045 /** 1007 1046 * 1047 * @param path 1048 * @return void 1008 1049 */ 1009 1050 void usb_hid_report_path_free(usb_hid_report_path_t *path) … … 1018 1059 * Clone content of given usage path to the new one 1019 1060 * 1061 * @param usage_path 1062 * @return 1020 1063 */ 1021 1064 usb_hid_report_path_t *usb_hid_report_path_clone(usb_hid_report_path_t *usage_path) … … 1045 1088 1046 1089 1090 /*** OUTPUT API **/ 1091 1092 /** Allocates output report buffer 1093 * 1094 * @param parser 1095 * @param size 1096 * @return 1097 */ 1098 uint8_t *usb_hid_report_output(usb_hid_report_parser_t *parser, size_t *size) 1099 { 1100 if(parser == NULL) { 1101 *size = 0; 1102 return NULL; 1103 } 1104 1105 // read the last outpu report item 1106 usb_hid_report_item_t *last; 1107 link_t *link; 1108 1109 link = parser->output.prev; 1110 if(link != &parser->output) { 1111 last = list_get_instance(link, usb_hid_report_item_t, link); 1112 *size = (last->offset + (last->size * last->count)) / 8; 1113 1114 uint8_t *buffer = malloc(sizeof(uint8_t) * (*size)); 1115 return buffer; 1116 } 1117 else { 1118 *size = 0; 1119 return NULL; 1120 } 1121 } 1122 1123 1124 /** Frees output report buffer 1125 * 1126 * @param output Output report buffer 1127 * @return 1128 */ 1129 void usb_hid_report_output_free(uint8_t *output) 1130 { 1131 if(output != NULL) { 1132 free (output); 1133 } 1134 } 1135 1136 /** Returns size of output for given usage path 1137 * 1138 * @param parser 1139 * @param path 1140 * @param flags 1141 * @return 1142 */ 1143 size_t usb_hid_report_output_size(usb_hid_report_parser_t *parser, 1144 usb_hid_report_path_t *path, int flags) 1145 { 1146 size_t ret = 0; 1147 link_t *item; 1148 usb_hid_report_item_t *report_item; 1149 1150 if(parser == NULL) { 1151 return 0; 1152 } 1153 1154 item = parser->output.next; 1155 while(&parser->input != item) { 1156 report_item = list_get_instance(item, usb_hid_report_item_t, link); 1157 if(!USB_HID_ITEM_FLAG_CONSTANT(report_item->item_flags) && 1158 (usb_hid_report_compare_usage_path(report_item->usage_path, path, flags) == EOK)) { 1159 ret += report_item->count; 1160 } 1161 1162 item = item->next; 1163 } 1164 1165 return ret; 1166 1167 } 1168 1169 /** Updates the output report buffer by translated given data 1170 * 1171 * @param parser 1172 * @param path 1173 * @param flags 1174 * @param buffer 1175 * @param size 1176 * @param data 1177 * @param data_size 1178 * @return 1179 */ 1180 int usb_hid_report_output_translate(usb_hid_report_parser_t *parser, 1181 usb_hid_report_path_t *path, int flags, 1182 uint8_t *buffer, size_t size, 1183 int32_t *data, size_t data_size) 1184 { 1185 //TODO 1186 // 1187 //go throught output descriptor and 1188 // if path match then take data from the begin, translate them and 1189 // or to the buffer 1190 // 1191 // it should be the reverse process to input translation 1192 1193 usb_hid_report_item_t *report_item; 1194 link_t *item; 1195 size_t idx=0; 1196 int i=0; 1197 int32_t field_value=0; 1198 int32_t value=0; 1199 int8_t mask; 1200 int8_t offset; 1201 1202 if(parser == NULL) { 1203 return EINVAL; 1204 } 1205 1206 item = parser->output.next; 1207 while(item != &parser->output) { 1208 report_item = list_get_instance(item, usb_hid_report_item_t ,link); 1209 1210 if(idx > size) { 1211 return EINVAL; 1212 } 1213 1214 for(i=0; i<report_item->count; i++, idx++) { 1215 // translate data 1216 value = usb_hid_translate_data_output(report_item, data[idx]); 1217 1218 // pres kazdy byte v bufferu kteryho se to tyka 1219 for(){ 1220 // vybrat ktera cast value patri do tohodle bytu 1221 // shiftnout podle pozice 1222 1223 //samotny vlozeni do bufferu 1224 buffer[x+j] |= value[j]; 1225 } 1226 } 1227 } 1228 1229 return EOK; 1230 } 1231 1232 1047 1233 /** 1048 1234 * @}
Note:
See TracChangeset
for help on using the changeset viewer.