Changes in / [aaa3d82b:3e95cd7] in mainline
- Location:
- uspace/lib/usbhid
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbhid/include/usb/hid/hid_report_items.h
raaa3d82b r3e95cd7 96 96 #define USB_HID_ITEM_FLAG_RELATIVE(flags) ((flags & 0x4) == 0x4) 97 97 98 /** Indicates whether the data “rolls over” when reaching either the extreme 98 /** 99 * Indicates whether the data “rolls over” when reaching either the extreme 99 100 * high or low value. For example, a dial that can spin freely 360 degrees 100 101 * might output values from 0 to 10. If Wrap is indicated, the next value -
uspace/lib/usbhid/include/usb/hid/hiddescriptor.h
raaa3d82b r3e95cd7 43 43 44 44 int usb_hid_parse_report_descriptor(usb_hid_report_t *report, 45 45 const uint8_t *data, size_t size); 46 46 47 47 void usb_hid_free_report(usb_hid_report_t *report); … … 51 51 int usb_hid_report_init(usb_hid_report_t *report); 52 52 53 int usb_hid_report_append_fields(usb_hid_report_t *report, 54 53 int usb_hid_report_append_fields(usb_hid_report_t *report, 54 usb_hid_report_item_t *report_item); 55 55 56 usb_hid_report_description_t * usb_hid_report_find_description( 57 const usb_hid_report_t *report, uint8_t report_id, 58 usb_hid_report_type_t type); 56 usb_hid_report_description_t * usb_hid_report_find_description(const usb_hid_report_t *report, uint8_t report_id, usb_hid_report_type_t type); 59 57 60 int usb_hid_report_parse_tag(uint8_t tag, uint8_t class, const uint8_t *data, 61 size_t item_size, usb_hid_report_item_t *report_item, 62 usb_hid_report_path_t *usage_path); 58 int usb_hid_report_parse_tag(uint8_t tag, uint8_t class, const uint8_t *data, size_t item_size, 59 usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path); 63 60 64 int usb_hid_report_parse_main_tag(uint8_t tag, const uint8_t *data, 65 size_t item_size, usb_hid_report_item_t *report_item, 66 usb_hid_report_path_t *usage_path); 61 int usb_hid_report_parse_main_tag(uint8_t tag, const uint8_t *data, size_t item_size, 62 usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path); 67 63 68 int usb_hid_report_parse_global_tag(uint8_t tag, const uint8_t *data, 69 size_t item_size, usb_hid_report_item_t *report_item, 70 usb_hid_report_path_t *usage_path); 64 int usb_hid_report_parse_global_tag(uint8_t tag, const uint8_t *data, size_t item_size, 65 usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path); 71 66 72 int usb_hid_report_parse_local_tag(uint8_t tag, const uint8_t *data, 73 size_t item_size, usb_hid_report_item_t *report_item, 74 usb_hid_report_path_t *usage_path); 67 int usb_hid_report_parse_local_tag(uint8_t tag, const uint8_t *data, size_t item_size, 68 usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path); 75 69 76 70 void usb_hid_descriptor_print_list(link_t *head); … … 80 74 void usb_hid_free_report_list(link_t *head); 81 75 82 usb_hid_report_item_t *usb_hid_report_item_clone( 83 const usb_hid_report_item_t *item); 76 usb_hid_report_item_t *usb_hid_report_item_clone(const usb_hid_report_item_t *item); 84 77 85 78 uint32_t usb_hid_report_tag_data_uint32(const uint8_t *data, size_t size); 86 79 87 usb_hid_report_path_t *usb_hid_report_path_try_insert(usb_hid_report_t*report, 88 usb_hid_report_path_t *cmp_path); 80 usb_hid_report_path_t *usb_hid_report_path_try_insert(usb_hid_report_t *report, usb_hid_report_path_t *cmp_path); 89 81 90 82 -
uspace/lib/usbhid/include/usb/hid/hidparser.h
raaa3d82b r3e95cd7 47 47 * Input report parser functions 48 48 */ 49 int usb_hid_parse_report(const usb_hid_report_t *report, const uint8_t *data, 50 size_t size, uint8_t *report_id); 49 /** */ 50 int usb_hid_parse_report(const usb_hid_report_t *report, const uint8_t *data, 51 size_t size, uint8_t *report_id); 51 52 52 53 /* 53 54 * Output report parser functions 54 55 */ 56 /** Allocates output report buffer*/ 55 57 uint8_t *usb_hid_report_output(usb_hid_report_t *report, size_t *size, 56 58 uint8_t report_id); 57 59 60 /** Frees output report buffer*/ 58 61 void usb_hid_report_output_free(uint8_t *output); 59 62 60 size_t usb_hid_report_size(usb_hid_report_t *report, uint8_t report_id, 61 usb_hid_report_type_t type); 63 /** Returns size of report in items */ 64 size_t usb_hid_report_size(usb_hid_report_t *report, uint8_t report_id, 65 usb_hid_report_type_t type); 62 66 63 size_t usb_hid_report_byte_size(usb_hid_report_t *report, uint8_t report_id, 64 67 size_t usb_hid_report_byte_size(usb_hid_report_t *report, uint8_t report_id, 68 usb_hid_report_type_t type); 65 69 66 70 67 int usb_hid_report_output_translate(usb_hid_report_t *report, 68 uint8_t report_id, uint8_t *buffer, size_t size); 71 /** Makes the output report buffer by translated given data */ 72 int usb_hid_report_output_translate(usb_hid_report_t *report, uint8_t report_id, 73 uint8_t *buffer, size_t size); 69 74 70 75 71 /* 72 * Report descriptor structure observing functions 73 */74 usb_hid_report_field_t *usb_hid_report_get_sibling(usb_hid_report_t *report, 75 usb_hid_report_field_t *field, usb_hid_report_path_t *path, 76 int flags,usb_hid_report_type_t type);76 /** */ 77 usb_hid_report_field_t *usb_hid_report_get_sibling(usb_hid_report_t *report, 78 usb_hid_report_field_t *field, 79 usb_hid_report_path_t *path, 80 int flags, 81 usb_hid_report_type_t type); 77 82 83 /** */ 78 84 uint8_t usb_hid_get_next_report_id(usb_hid_report_t *report, 79 uint8_t report_id, usb_hid_report_type_t type); 85 uint8_t report_id, 86 usb_hid_report_type_t type); 80 87 81 88 #endif -
uspace/lib/usbhid/include/usb/hid/hidpath.h
raaa3d82b r3e95cd7 42 42 43 43 /*---------------------------------------------------------------------------*/ 44 /* 44 /** 45 45 * Flags of usage paths comparison modes. 46 46 * 47 47 */ 48 /** Wanted usage path must be exactly the same as the searched one. This49 * option cannot be combined with the others.48 /** Wanted usage path must be exactly the same as the searched one. 49 * This option cannot be combined with the others. 50 50 */ 51 51 #define USB_HID_PATH_COMPARE_STRICT 0 … … 57 57 58 58 /** 59 * Only usage page are compared along the usage path. This option can be60 * combined with others.59 * Only usage page are compared along the usage path. 60 * This option can be combined with others. 61 61 */ 62 62 #define USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY 2 … … 101 101 int depth; 102 102 103 /** Report id. Zero is reserved and means that report id is not used. 104 * */ 103 /** Report id. Zero is reserved and means that report id is not used. */ 105 104 uint8_t report_id; 106 105 … … 118 117 void usb_hid_report_path_free(usb_hid_report_path_t *path); 119 118 120 int usb_hid_report_path_set_report_id(usb_hid_report_path_t *usage_path, 121 119 int usb_hid_report_path_set_report_id(usb_hid_report_path_t *usage_path, 120 uint8_t report_id); 122 121 123 122 int usb_hid_report_path_append_item(usb_hid_report_path_t *usage_path, 124 123 int32_t usage_page, int32_t usage); 125 124 126 125 void usb_hid_report_remove_last_item(usb_hid_report_path_t *usage_path); … … 129 128 130 129 void usb_hid_report_set_last_item(usb_hid_report_path_t *usage_path, 131 130 int32_t tag, int32_t data); 132 131 133 int usb_hid_report_compare_usage_path(usb_hid_report_path_t *report_path, 134 132 int usb_hid_report_compare_usage_path(usb_hid_report_path_t *report_path, 133 usb_hid_report_path_t *path, int flags); 135 134 136 usb_hid_report_path_t *usb_hid_report_path_clone( 137 usb_hid_report_path_t *usage_path); 135 usb_hid_report_path_t *usb_hid_report_path_clone(usb_hid_report_path_t *usage_path); 138 136 139 137 void usb_hid_print_usage_path(usb_hid_report_path_t *path); -
uspace/lib/usbhid/include/usb/hid/hidtypes.h
raaa3d82b r3e95cd7 72 72 73 73 /** 74 * Enum of report types74 * Report type 75 75 */ 76 76 typedef enum { 77 /** Input report. Data are sent from device to system */78 77 USB_HID_REPORT_TYPE_INPUT = 1, 79 80 /** Output report. Data are sent from system to device */81 78 USB_HID_REPORT_TYPE_OUTPUT = 2, 82 83 /** Feature report. Describes device configuration information that84 * can be sent to the device */85 79 USB_HID_REPORT_TYPE_FEATURE = 3 86 80 } usb_hid_report_type_t; -
uspace/lib/usbhid/src/hiddescriptor.c
raaa3d82b r3e95cd7 41 41 #include <assert.h> 42 42 43 /*---------------------------------------------------------------------------*/ 44 /* 45 * Constants defining current parsing mode for correct parsing of the set of 46 * local tags (usage) enclosed in delimter tags. 47 */ 48 /** 49 * Second delimiter tag was read. The set of local items (usage) ended. 50 */ 43 51 44 #define OUTSIDE_DELIMITER_SET 0 52 53 /**54 * First delimiter tag was read. The set of local items (usage) started.55 */56 45 #define START_DELIMITER_SET 1 57 58 /**59 * Parser is in the set of local items.60 */61 46 #define INSIDE_DELIMITER_SET 2 62 63 /*---------------------------------------------------------------------------*/64 47 65 48 /** The new report item flag. Used to determine when the item is completly … … 78 61 #define USB_HID_UNKNOWN_TAG -99 79 62 80 /*---------------------------------------------------------------------------*/ 81 /** 82 * Checks if given collection path is already present in report structure and 83 * inserts it if not. 84 * 85 * @param report Report structure 86 * @param cmp_path The collection path 87 * @return Pointer to the result collection path in report structure. 88 * @retval NULL If some error occurs 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 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 { 65 /* find or append current collection path to the list */ 66 //link_t *path_it = report->collection_paths.next; 93 67 link_t *path_it = report->collection_paths.prev->next; 94 68 usb_hid_report_path_t *path = NULL; 95 69 96 if((report == NULL) || (cmp_path == NULL)) {97 return NULL;98 }99 70 100 71 while(path_it != &report->collection_paths) { 101 path = list_get_instance(path_it, usb_hid_report_path_t, 102 link); 103 104 if(usb_hid_report_compare_usage_path(path, cmp_path, 105 USB_HID_PATH_COMPARE_STRICT) == EOK){ 72 path = list_get_instance(path_it, usb_hid_report_path_t, link); 73 74 if(usb_hid_report_compare_usage_path(path, cmp_path, USB_HID_PATH_COMPARE_STRICT) == EOK){ 106 75 break; 107 76 } … … 109 78 } 110 79 if(path_it == &report->collection_paths) { 111 path = usb_hid_report_path_clone(cmp_path); 112 if(path == NULL) { 113 return NULL; 114 } 80 path = usb_hid_report_path_clone(cmp_path); 115 81 list_append(&path->link, &report->collection_paths); 116 82 report->collection_paths_count++; … … 119 85 } 120 86 else { 121 return list_get_instance(path_it, usb_hid_report_path_t, 122 link); 123 } 124 } 125 126 /*---------------------------------------------------------------------------*/ 87 return list_get_instance(path_it, usb_hid_report_path_t, link); 88 } 89 } 90 127 91 /** 128 92 * Initialize the report descriptor parser structure … … 130 94 * @param parser Report descriptor parser structure 131 95 * @return Error code 132 * @retval EINVAL If no report structure was given133 * @retval EOK If report structure was successfully initialized134 96 */ 135 97 int usb_hid_report_init(usb_hid_report_t *report) … … 147 109 } 148 110 149 /*---------------------------------------------------------------------------*/ 150 151 /** 152 * 153 * 154 * @param report Report structure in which the new report items should be 155 * stored 156 * @param report_item Current report descriptor's parsing state table 157 * @return Error code 158 * @retval EOK If all fields were successfully append to report 159 * @retval EINVAL If invalid parameters (NULL) was given 160 * @retval ENOMEM If there is no memmory to store new report description 161 * 162 */ 163 int usb_hid_report_append_fields(usb_hid_report_t *report, 164 usb_hid_report_item_t *report_item) { 165 111 112 /* 113 * 114 * 115 */ 116 int usb_hid_report_append_fields(usb_hid_report_t *report, usb_hid_report_item_t *report_item) 117 { 166 118 usb_hid_report_field_t *field; 167 119 int i; … … 169 121 uint32_t *usages; 170 122 int usages_used=0; 171 172 if((report == NULL) || (report_item == NULL)) {173 return EINVAL;174 }175 176 123 if(report_item->usages_count > 0){ 177 124 usages = malloc(sizeof(int32_t) * report_item->usages_count); 178 memcpy(usages, report_item->usages, sizeof(int32_t) * 179 report_item->usages_count); 125 memcpy(usages, report_item->usages, sizeof(int32_t) * report_item->usages_count); 180 126 } 181 127 else { … … 198 144 if(USB_HID_ITEM_FLAG_VARIABLE(report_item->item_flags) == 0){ 199 145 /* 200 Store usage array. The Correct Usage Page and Usage is201 dependingon data in report and will be filled later146 Store usage array. The Correct Usage Page and Usage is depending 147 on data in report and will be filled later 202 148 */ 203 149 field->usage = 0; … … 216 162 } 217 163 else { 218 usage = report_item->usages[ 219 report_item->usages_count- 1]; 164 usage = report_item->usages[report_item->usages_count - 1]; 220 165 } 221 166 222 167 if(USB_HID_IS_EXTENDED_USAGE(usage)){ 223 168 field->usage = USB_HID_EXTENDED_USAGE(usage); 224 field->usage_page = 225 USB_HID_EXTENDED_USAGE_PAGE(usage); 169 field->usage_page = USB_HID_EXTENDED_USAGE_PAGE(usage); 226 170 } 227 171 else { … … 232 176 } 233 177 234 usb_hid_report_set_last_item(path, USB_HID_TAG_CLASS_GLOBAL, 235 field->usage_page); 236 usb_hid_report_set_last_item(path, USB_HID_TAG_CLASS_LOCAL, 237 field->usage); 238 239 field->collection_path = 240 usb_hid_report_path_try_insert(report, path); 178 usb_hid_report_set_last_item(path, USB_HID_TAG_CLASS_GLOBAL, field->usage_page); 179 usb_hid_report_set_last_item(path, USB_HID_TAG_CLASS_LOCAL, field->usage); 180 181 field->collection_path = usb_hid_report_path_try_insert(report, path); 241 182 242 183 field->size = report_item->size; 243 184 244 size_t offset_byte = (report_item->offset + (i * 245 report_item->size)) / 8; 246 247 size_t offset_bit = 8 - ((report_item->offset + (i * 248 report_item->size)) % 8) - report_item->size; 185 size_t offset_byte = (report_item->offset + (i * report_item->size)) / 8; 186 size_t offset_bit = 8 - ((report_item->offset + (i * report_item->size)) % 8) - report_item->size; 249 187 250 188 field->offset = 8 * offset_byte + offset_bit; … … 257 195 /* find the right report list*/ 258 196 usb_hid_report_description_t *report_des; 259 report_des = usb_hid_report_find_description(report, 260 report_item->id, report_item->type); 261 197 report_des = usb_hid_report_find_description(report, report_item->id, report_item->type); 262 198 if(report_des == NULL){ 263 report_des = malloc( 264 sizeof(usb_hid_report_description_t)); 265 if(report_des == NULL) { 266 return ENOMEM; 267 } 268 269 memset(report_des, 0, 270 sizeof(usb_hid_report_description_t)); 199 report_des = malloc(sizeof(usb_hid_report_description_t)); 200 memset(report_des, 0, sizeof(usb_hid_report_description_t)); 271 201 272 202 report_des->type = report_item->type; … … 295 225 return EOK; 296 226 } 297 /*---------------------------------------------------------------------------*/ 298 /** 299 * Finds description of report with given report_id and of given type in 300 * opaque report structure. 301 * 302 * @param report Opaque structure containing the parsed report descriptor 303 * @param report_id ReportId of report we are searching 304 * @param type Type of report we are searching 305 * @return Pointer to the particular report description 306 * @retval NULL If no description is founded 307 */ 308 usb_hid_report_description_t * usb_hid_report_find_description( 309 const usb_hid_report_t *report, uint8_t report_id, 310 usb_hid_report_type_t type) { 311 227 228 usb_hid_report_description_t * usb_hid_report_find_description(const usb_hid_report_t *report, uint8_t report_id, usb_hid_report_type_t type) 229 { 312 230 link_t *report_it = report->reports.next; 313 231 usb_hid_report_description_t *report_des = NULL; 314 232 315 233 while(report_it != &report->reports) { 316 report_des = list_get_instance(report_it, 317 usb_hid_report_description_t, link); 318 319 if((report_des->report_id == report_id) && 320 (report_des->type == type)) { 234 report_des = list_get_instance(report_it, usb_hid_report_description_t, link); 235 236 if((report_des->report_id == report_id) && (report_des->type == type)){ 321 237 return report_des; 322 238 } … … 327 243 return NULL; 328 244 } 329 /*---------------------------------------------------------------------------*/330 245 331 246 /** Parse HID report descriptor. … … 334 249 * @param data Data describing the report. 335 250 * @return Error code. 336 * @retval ENOMEM If no more memmory is available337 * @retval EINVAL If invalid data are founded338 * @retval EOK If report descriptor is successfully parsed339 251 */ 340 252 int usb_hid_parse_report_descriptor(usb_hid_report_t *report, … … 387 299 388 300 ret = usb_hid_report_parse_tag(tag,class,data+i+1, 389 item_size,report_item, usage_path); 390 301 item_size,report_item, usage_path); 391 302 switch(ret){ 392 case USB_HID_NEW_REPORT_ITEM: 393 /* store report item to report and create the 394 * new one store current collection path 395 */ 396 report_item->usage_path = usage_path; 303 case USB_HID_NEW_REPORT_ITEM: 304 // store report item to report and create the new one 305 // store current collection path 306 report_item->usage_path = usage_path; 397 307 398 usb_hid_report_path_set_report_id( 399 report_item->usage_path, report_item->id); 400 401 if(report_item->id != 0){ 402 report->use_report_ids = 1; 403 } 308 usb_hid_report_path_set_report_id(report_item->usage_path, report_item->id); 309 if(report_item->id != 0){ 310 report->use_report_ids = 1; 311 } 404 312 405 switch(tag) { 406 case USB_HID_REPORT_TAG_INPUT: 407 report_item->type = 408 USB_HID_REPORT_TYPE_INPUT; 409 410 report_item->offset = offset_input; 411 offset_input += report_item->count * 412 report_item->size; 313 switch(tag) { 314 case USB_HID_REPORT_TAG_INPUT: 315 report_item->type = USB_HID_REPORT_TYPE_INPUT; 316 report_item->offset = offset_input; 317 offset_input += report_item->count * report_item->size; 318 break; 319 case USB_HID_REPORT_TAG_OUTPUT: 320 report_item->type = USB_HID_REPORT_TYPE_OUTPUT; 321 report_item->offset = offset_output; 322 offset_output += report_item->count * report_item->size; 323 324 break; 325 case USB_HID_REPORT_TAG_FEATURE: 326 report_item->type = USB_HID_REPORT_TYPE_FEATURE; 327 report_item->offset = offset_feature; 328 offset_feature += report_item->count * report_item->size; 329 break; 330 default: 331 usb_log_debug("\tjump over - tag %X\n", tag); 332 break; 333 } 334 335 /* 336 * append new fields to the report 337 * structure 338 */ 339 usb_hid_report_append_fields(report, report_item); 340 341 /* reset local items */ 342 usb_hid_report_reset_local_items (report_item); 343 413 344 break; 414 415 case USB_HID_REPORT_TAG_OUTPUT: 416 report_item->type = 417 USB_HID_REPORT_TYPE_OUTPUT; 345 346 case USB_HID_RESET_OFFSET: 347 offset_input = 0; 348 offset_output = 0; 349 offset_feature = 0; 350 usb_hid_report_path_set_report_id (usage_path, report_item->id); 351 break; 352 353 case USB_HID_REPORT_TAG_PUSH: 354 // push current state to stack 355 new_report_item = usb_hid_report_item_clone(report_item); 356 usb_hid_report_path_t *tmp_path = usb_hid_report_path_clone(usage_path); 357 new_report_item->usage_path = tmp_path; 358 359 list_prepend (&new_report_item->link, &stack); 360 break; 361 case USB_HID_REPORT_TAG_POP: 362 // restore current state from stack 363 if(list_empty (&stack)) { 364 return EINVAL; 365 } 366 free(report_item); 367 368 report_item = list_get_instance(stack.next, usb_hid_report_item_t, link); 418 369 419 report_item->offset = offset_output; 420 offset_output += report_item->count * 421 report_item->size; 370 usb_hid_report_usage_path_t *tmp_usage_path; 371 tmp_usage_path = list_get_instance(report_item->usage_path->link.prev, usb_hid_report_usage_path_t, link); 372 373 usb_hid_report_set_last_item(usage_path, USB_HID_TAG_CLASS_GLOBAL, tmp_usage_path->usage_page); 374 usb_hid_report_set_last_item(usage_path, USB_HID_TAG_CLASS_LOCAL, tmp_usage_path->usage); 375 376 usb_hid_report_path_free(report_item->usage_path); 377 list_initialize(&report_item->usage_path->link); 378 list_remove (stack.next); 379 422 380 break; 423 424 case USB_HID_REPORT_TAG_FEATURE: 425 report_item->type = 426 USB_HID_REPORT_TYPE_FEATURE; 427 428 report_item->offset = offset_feature; 429 offset_feature += report_item->count * 430 report_item->size; 381 382 default: 383 // nothing special to do 431 384 break; 432 433 default:434 usb_log_debug2(435 "\tjump over - tag %X\n", tag);436 break;437 }438 439 /*440 * append new fields to the report structure441 */442 usb_hid_report_append_fields(report,443 report_item);444 445 /* reset local items */446 usb_hid_report_reset_local_items (report_item);447 break;448 449 case USB_HID_RESET_OFFSET:450 offset_input = 0;451 offset_output = 0;452 offset_feature = 0;453 usb_hid_report_path_set_report_id (usage_path,454 report_item->id);455 break;456 457 case USB_HID_REPORT_TAG_PUSH:458 // push current state to stack459 new_report_item = usb_hid_report_item_clone(460 report_item);461 462 usb_hid_report_path_t *tmp_path =463 usb_hid_report_path_clone(usage_path);464 465 new_report_item->usage_path = tmp_path;466 467 list_prepend (&new_report_item->link, &stack);468 break;469 case USB_HID_REPORT_TAG_POP:470 // restore current state from stack471 if(list_empty (&stack)) {472 return EINVAL;473 }474 free(report_item);475 476 report_item = list_get_instance(stack.next,477 usb_hid_report_item_t, link);478 479 usb_hid_report_usage_path_t *tmp_usage_path;480 tmp_usage_path = list_get_instance(481 report_item->usage_path->link.prev,482 usb_hid_report_usage_path_t, link);483 484 usb_hid_report_set_last_item(usage_path,485 USB_HID_TAG_CLASS_GLOBAL, tmp_usage_path->usage_page);486 487 usb_hid_report_set_last_item(usage_path,488 USB_HID_TAG_CLASS_LOCAL, tmp_usage_path->usage);489 490 usb_hid_report_path_free(report_item->usage_path);491 list_initialize(&report_item->usage_path->link);492 list_remove (stack.next);493 494 break;495 496 default:497 // nothing special to do498 break;499 385 } 500 386 … … 513 399 } 514 400 515 /*---------------------------------------------------------------------------*/516 401 517 402 /** … … 524 409 * @return Code of action to be done next 525 410 */ 526 int usb_hid_report_parse_tag(uint8_t tag, uint8_t class, const uint8_t *data, 527 size_t item_size, usb_hid_report_item_t *report_item, 528 usb_hid_report_path_t *usage_path) { 529 411 int usb_hid_report_parse_tag(uint8_t tag, uint8_t class, const uint8_t *data, size_t item_size, 412 usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path) 413 { 530 414 int ret; 531 415 532 416 switch(class){ 533 case USB_HID_TAG_CLASS_MAIN: 534 535 if((ret=usb_hid_report_parse_main_tag(tag, data, item_size, 536 report_item, usage_path)) == EOK) { 537 538 return USB_HID_NEW_REPORT_ITEM; 539 } 540 else { 541 return ret; 542 } 543 break; 544 545 case USB_HID_TAG_CLASS_GLOBAL: 546 return usb_hid_report_parse_global_tag(tag, data, item_size, 547 report_item, usage_path); 548 break; 549 550 case USB_HID_TAG_CLASS_LOCAL: 551 return usb_hid_report_parse_local_tag(tag, data, item_size, 552 report_item, usage_path); 553 break; 554 555 default: 556 return USB_HID_NO_ACTION; 417 case USB_HID_TAG_CLASS_MAIN: 418 419 if((ret=usb_hid_report_parse_main_tag(tag,data,item_size,report_item, usage_path)) == EOK) { 420 return USB_HID_NEW_REPORT_ITEM; 421 } 422 else { 423 /*TODO process the error */ 424 return ret; 425 } 426 break; 427 428 case USB_HID_TAG_CLASS_GLOBAL: 429 return usb_hid_report_parse_global_tag(tag,data,item_size,report_item, usage_path); 430 break; 431 432 case USB_HID_TAG_CLASS_LOCAL: 433 return usb_hid_report_parse_local_tag(tag,data,item_size,report_item, usage_path); 434 break; 435 default: 436 return USB_HID_NO_ACTION; 557 437 } 558 438 } … … 568 448 */ 569 449 570 int usb_hid_report_parse_main_tag(uint8_t tag, const uint8_t *data, 571 size_t item_size, usb_hid_report_item_t *report_item, 572 usb_hid_report_path_t *usage_path) 450 int usb_hid_report_parse_main_tag(uint8_t tag, const uint8_t *data, size_t item_size, 451 usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path) 573 452 { 574 453 usb_hid_report_usage_path_t *path_item; … … 576 455 switch(tag) 577 456 { 578 case USB_HID_REPORT_TAG_INPUT:579 case USB_HID_REPORT_TAG_OUTPUT:580 case USB_HID_REPORT_TAG_FEATURE:581 report_item->item_flags = *data;582 return EOK;583 break;457 case USB_HID_REPORT_TAG_INPUT: 458 case USB_HID_REPORT_TAG_OUTPUT: 459 case USB_HID_REPORT_TAG_FEATURE: 460 report_item->item_flags = *data; 461 return EOK; 462 break; 584 463 585 case USB_HID_REPORT_TAG_COLLECTION: 586 587 /* store collection atributes */ 588 path_item = list_get_instance(usage_path->head.prev, 589 usb_hid_report_usage_path_t, link); 590 path_item->flags = *data; 464 case USB_HID_REPORT_TAG_COLLECTION: 465 466 // store collection atributes 467 path_item = list_get_instance(usage_path->head.prev, usb_hid_report_usage_path_t, link); 468 path_item->flags = *data; 591 469 592 /* set last item */ 593 usb_hid_report_set_last_item(usage_path, 594 USB_HID_TAG_CLASS_GLOBAL, 595 USB_HID_EXTENDED_USAGE_PAGE(report_item->usages[ 596 report_item->usages_count-1])); 597 598 usb_hid_report_set_last_item(usage_path, 599 USB_HID_TAG_CLASS_LOCAL, 600 USB_HID_EXTENDED_USAGE(report_item->usages[ 601 report_item->usages_count-1])); 470 // set last item 471 usb_hid_report_set_last_item(usage_path, 472 USB_HID_TAG_CLASS_GLOBAL, 473 USB_HID_EXTENDED_USAGE_PAGE(report_item->usages[report_item->usages_count-1])); 474 usb_hid_report_set_last_item(usage_path, 475 USB_HID_TAG_CLASS_LOCAL, 476 USB_HID_EXTENDED_USAGE(report_item->usages[report_item->usages_count-1])); 602 477 603 /* append the new one which will be set by common usage/usage 604 * page */ 605 usb_hid_report_path_append_item(usage_path, 606 report_item->usage_page, 607 report_item->usages[report_item->usages_count-1]); 608 609 usb_hid_report_reset_local_items (report_item); 610 return USB_HID_NO_ACTION; 611 break; 478 // append the new one which will be set by common 479 // usage/usage page 480 usb_hid_report_path_append_item(usage_path, report_item->usage_page, report_item->usages[report_item->usages_count-1]); 481 usb_hid_report_reset_local_items (report_item); 482 return USB_HID_NO_ACTION; 483 break; 612 484 613 case USB_HID_REPORT_TAG_END_COLLECTION: 614 usb_hid_report_remove_last_item(usage_path); 615 return USB_HID_NO_ACTION; 616 break; 617 618 default: 619 return USB_HID_NO_ACTION; 485 case USB_HID_REPORT_TAG_END_COLLECTION: 486 usb_hid_report_remove_last_item(usage_path); 487 return USB_HID_NO_ACTION; 488 break; 489 default: 490 return USB_HID_NO_ACTION; 620 491 } 621 492 … … 632 503 * @return Error code 633 504 */ 634 int usb_hid_report_parse_global_tag(uint8_t tag, const uint8_t *data, 635 size_t item_size, usb_hid_report_item_t *report_item, 636 usb_hid_report_path_t *usage_path) { 637 505 int usb_hid_report_parse_global_tag(uint8_t tag, const uint8_t *data, size_t item_size, 506 usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path) 507 { 508 // TODO take care about the bit length of data 638 509 switch(tag) 639 510 { 640 case USB_HID_REPORT_TAG_USAGE_PAGE: 641 report_item->usage_page = 642 usb_hid_report_tag_data_uint32(data, item_size); 643 break; 644 645 case USB_HID_REPORT_TAG_LOGICAL_MINIMUM: 646 report_item->logical_minimum = USB_HID_UINT32_TO_INT32( 647 usb_hid_report_tag_data_uint32(data,item_size), 648 item_size * 8); 649 break; 650 651 case USB_HID_REPORT_TAG_LOGICAL_MAXIMUM: 652 report_item->logical_maximum = USB_HID_UINT32_TO_INT32( 653 usb_hid_report_tag_data_uint32(data,item_size), 654 item_size * 8); 655 break; 656 657 case USB_HID_REPORT_TAG_PHYSICAL_MINIMUM: 658 report_item->physical_minimum = USB_HID_UINT32_TO_INT32( 659 usb_hid_report_tag_data_uint32(data,item_size), 660 item_size * 8); 661 break; 662 663 case USB_HID_REPORT_TAG_PHYSICAL_MAXIMUM: 664 report_item->physical_maximum = USB_HID_UINT32_TO_INT32( 665 usb_hid_report_tag_data_uint32(data,item_size), 666 item_size * 8); 667 break; 668 669 case USB_HID_REPORT_TAG_UNIT_EXPONENT: 670 report_item->unit_exponent = usb_hid_report_tag_data_uint32( 671 data,item_size); 672 break; 673 674 case USB_HID_REPORT_TAG_UNIT: 675 report_item->unit = usb_hid_report_tag_data_uint32( 676 data,item_size); 677 break; 678 679 case USB_HID_REPORT_TAG_REPORT_SIZE: 680 report_item->size = usb_hid_report_tag_data_uint32( 681 data,item_size); 682 break; 683 684 case USB_HID_REPORT_TAG_REPORT_COUNT: 685 report_item->count = usb_hid_report_tag_data_uint32( 686 data,item_size); 687 break; 688 689 case USB_HID_REPORT_TAG_REPORT_ID: 690 report_item->id = usb_hid_report_tag_data_uint32(data, 691 item_size); 692 return USB_HID_RESET_OFFSET; 693 break; 694 695 case USB_HID_REPORT_TAG_PUSH: 696 case USB_HID_REPORT_TAG_POP: 697 /* 698 * stack operations are done in top level parsing 699 * function 700 */ 701 return tag; 702 break; 511 case USB_HID_REPORT_TAG_USAGE_PAGE: 512 report_item->usage_page = usb_hid_report_tag_data_uint32(data, item_size); 513 break; 514 case USB_HID_REPORT_TAG_LOGICAL_MINIMUM: 515 report_item->logical_minimum = USB_HID_UINT32_TO_INT32(usb_hid_report_tag_data_uint32(data,item_size), item_size * 8); 516 break; 517 case USB_HID_REPORT_TAG_LOGICAL_MAXIMUM: 518 report_item->logical_maximum = USB_HID_UINT32_TO_INT32(usb_hid_report_tag_data_uint32(data,item_size), item_size * 8); 519 break; 520 case USB_HID_REPORT_TAG_PHYSICAL_MINIMUM: 521 report_item->physical_minimum = USB_HID_UINT32_TO_INT32(usb_hid_report_tag_data_uint32(data,item_size), item_size * 8); 522 break; 523 case USB_HID_REPORT_TAG_PHYSICAL_MAXIMUM: 524 report_item->physical_maximum = USB_HID_UINT32_TO_INT32(usb_hid_report_tag_data_uint32(data,item_size), item_size * 8); 525 526 break; 527 case USB_HID_REPORT_TAG_UNIT_EXPONENT: 528 report_item->unit_exponent = usb_hid_report_tag_data_uint32(data,item_size); 529 break; 530 case USB_HID_REPORT_TAG_UNIT: 531 report_item->unit = usb_hid_report_tag_data_uint32(data,item_size); 532 break; 533 case USB_HID_REPORT_TAG_REPORT_SIZE: 534 report_item->size = usb_hid_report_tag_data_uint32(data,item_size); 535 break; 536 case USB_HID_REPORT_TAG_REPORT_COUNT: 537 report_item->count = usb_hid_report_tag_data_uint32(data,item_size); 538 break; 539 case USB_HID_REPORT_TAG_REPORT_ID: 540 report_item->id = usb_hid_report_tag_data_uint32(data,item_size); 541 return USB_HID_RESET_OFFSET; 542 break; 543 case USB_HID_REPORT_TAG_PUSH: 544 case USB_HID_REPORT_TAG_POP: 545 /* 546 * stack operations are done in top level parsing 547 * function 548 */ 549 return tag; 550 break; 703 551 704 default:705 return USB_HID_NO_ACTION;552 default: 553 return USB_HID_NO_ACTION; 706 554 } 707 555 … … 718 566 * @return Error code 719 567 */ 720 int usb_hid_report_parse_local_tag(uint8_t tag, const uint8_t *data, 721 size_t item_size, usb_hid_report_item_t *report_item, 722 usb_hid_report_path_t *usage_path) 568 int usb_hid_report_parse_local_tag(uint8_t tag, const uint8_t *data, size_t item_size, 569 usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path) 723 570 { 724 571 int32_t extended_usage; 725 572 726 573 switch(tag) { 727 case USB_HID_REPORT_TAG_USAGE: 728 switch(report_item->in_delimiter) { 729 case INSIDE_DELIMITER_SET: 730 /* nothing to do 731 * we catch only the first one 732 */ 733 break; 734 735 case START_DELIMITER_SET: 736 report_item->in_delimiter = INSIDE_DELIMITER_SET; 737 case OUTSIDE_DELIMITER_SET: 738 extended_usage = ((report_item->usage_page) << 16); 739 extended_usage += usb_hid_report_tag_data_uint32( 740 data,item_size); 741 742 report_item->usages[report_item->usages_count] = 743 extended_usage; 744 745 report_item->usages_count++; 746 break; 747 } 748 break; 749 750 case USB_HID_REPORT_TAG_USAGE_MINIMUM: 751 if (item_size == 3) { 752 // usage extended usages 753 report_item->extended_usage_page = 754 USB_HID_EXTENDED_USAGE_PAGE( 755 usb_hid_report_tag_data_uint32(data,item_size)); 756 757 758 report_item->usage_minimum = 759 USB_HID_EXTENDED_USAGE( 760 usb_hid_report_tag_data_uint32(data,item_size)); 761 } 762 else { 763 report_item->usage_minimum = 764 usb_hid_report_tag_data_uint32(data,item_size); 765 } 766 break; 767 768 case USB_HID_REPORT_TAG_USAGE_MAXIMUM: 769 if (item_size == 3) { 770 if(report_item->extended_usage_page != 771 USB_HID_EXTENDED_USAGE_PAGE( 772 usb_hid_report_tag_data_uint32(data,item_size))) { 574 case USB_HID_REPORT_TAG_USAGE: 575 switch(report_item->in_delimiter) { 576 case INSIDE_DELIMITER_SET: 577 // nothing to do 578 break; 579 case START_DELIMITER_SET: 580 report_item->in_delimiter = INSIDE_DELIMITER_SET; 581 case OUTSIDE_DELIMITER_SET: 582 extended_usage = ((report_item->usage_page) << 16); 583 extended_usage += usb_hid_report_tag_data_uint32(data,item_size); 584 report_item->usages[report_item->usages_count] = extended_usage; 585 report_item->usages_count++; 586 break; 587 } 588 break; 589 case USB_HID_REPORT_TAG_USAGE_MINIMUM: 590 if (item_size == 3) { 591 // usage extended usages 592 report_item->extended_usage_page = (usb_hid_report_tag_data_uint32(data,item_size) & 0xFF00) >> 16; 593 report_item->usage_minimum = usb_hid_report_tag_data_uint32(data,item_size) & 0xFF; 594 } 595 else { 596 report_item->usage_minimum = usb_hid_report_tag_data_uint32(data,item_size); 597 } 598 break; 599 case USB_HID_REPORT_TAG_USAGE_MAXIMUM: 600 if (item_size == 3) { 601 602 if(report_item->extended_usage_page != ((usb_hid_report_tag_data_uint32(data,item_size) & 0xFF00) >> 16)) { 603 return EINVAL; 604 } 773 605 774 return EINVAL; 775 } 776 777 // usage extended usages 778 report_item->extended_usage_page = 779 USB_HID_EXTENDED_USAGE_PAGE( 780 usb_hid_report_tag_data_uint32(data,item_size)); 781 782 report_item->usage_maximum = 783 USB_HID_EXTENDED_USAGE( 784 usb_hid_report_tag_data_uint32(data,item_size)); 785 } 786 else { 787 report_item->usage_maximum = 788 usb_hid_report_tag_data_uint32(data,item_size); 789 } 790 791 // vlozit zaznamy do pole usages 792 int32_t i; 793 for(i = report_item->usage_minimum; 794 i <= report_item->usage_maximum; i++) { 795 796 if(report_item->extended_usage_page) { 797 report_item->usages[report_item->usages_count++] = 798 (report_item->extended_usage_page << 16) + i; 799 } 800 else { 801 report_item->usages[report_item->usages_count++] = 802 (report_item->usage_page << 16) + i; 803 } 804 } 805 report_item->extended_usage_page = 0; 606 // usage extended usages 607 report_item->extended_usage_page = (usb_hid_report_tag_data_uint32(data,item_size) & 0xFF00) >> 16; 608 report_item->usage_maximum = usb_hid_report_tag_data_uint32(data,item_size) & 0xFF; 609 } 610 else { 611 report_item->usage_maximum = usb_hid_report_tag_data_uint32(data,item_size); 612 } 613 614 // vlozit zaznamy do pole usages 615 int32_t i; 616 for(i=report_item->usage_minimum; i<=report_item->usage_maximum; i++) { 617 if(report_item->extended_usage_page) { 618 report_item->usages[report_item->usages_count++] = (report_item->extended_usage_page << 16) + i; 619 } 620 else { 621 622 report_item->usages[report_item->usages_count++] = (report_item->usage_page << 16) + i; 623 } 624 } 625 report_item->extended_usage_page = 0; 806 626 807 break; 808 809 case USB_HID_REPORT_TAG_DESIGNATOR_INDEX: 810 report_item->designator_index = 811 usb_hid_report_tag_data_uint32(data,item_size); 812 break; 813 814 case USB_HID_REPORT_TAG_DESIGNATOR_MINIMUM: 815 report_item->designator_minimum = 816 usb_hid_report_tag_data_uint32(data,item_size); 817 break; 818 819 case USB_HID_REPORT_TAG_DESIGNATOR_MAXIMUM: 820 report_item->designator_maximum = 821 usb_hid_report_tag_data_uint32(data,item_size); 822 break; 823 824 case USB_HID_REPORT_TAG_STRING_INDEX: 825 report_item->string_index = 826 usb_hid_report_tag_data_uint32(data,item_size); 827 break; 828 829 case USB_HID_REPORT_TAG_STRING_MINIMUM: 830 report_item->string_minimum = 831 usb_hid_report_tag_data_uint32(data,item_size); 832 break; 833 834 case USB_HID_REPORT_TAG_STRING_MAXIMUM: 835 report_item->string_maximum = 836 usb_hid_report_tag_data_uint32(data,item_size); 837 break; 838 839 case USB_HID_REPORT_TAG_DELIMITER: 840 report_item->in_delimiter = 841 usb_hid_report_tag_data_uint32(data,item_size); 842 break; 843 844 default: 845 return USB_HID_NO_ACTION; 627 break; 628 case USB_HID_REPORT_TAG_DESIGNATOR_INDEX: 629 report_item->designator_index = usb_hid_report_tag_data_uint32(data,item_size); 630 break; 631 case USB_HID_REPORT_TAG_DESIGNATOR_MINIMUM: 632 report_item->designator_minimum = usb_hid_report_tag_data_uint32(data,item_size); 633 break; 634 case USB_HID_REPORT_TAG_DESIGNATOR_MAXIMUM: 635 report_item->designator_maximum = usb_hid_report_tag_data_uint32(data,item_size); 636 break; 637 case USB_HID_REPORT_TAG_STRING_INDEX: 638 report_item->string_index = usb_hid_report_tag_data_uint32(data,item_size); 639 break; 640 case USB_HID_REPORT_TAG_STRING_MINIMUM: 641 report_item->string_minimum = usb_hid_report_tag_data_uint32(data,item_size); 642 break; 643 case USB_HID_REPORT_TAG_STRING_MAXIMUM: 644 report_item->string_maximum = usb_hid_report_tag_data_uint32(data,item_size); 645 break; 646 case USB_HID_REPORT_TAG_DELIMITER: 647 report_item->in_delimiter = usb_hid_report_tag_data_uint32(data,item_size); 648 break; 649 650 default: 651 return USB_HID_NO_ACTION; 846 652 } 847 653 848 654 return EOK; 849 655 } 850 /*---------------------------------------------------------------------------*/851 656 852 657 /** … … 869 674 return result; 870 675 } 871 /*---------------------------------------------------------------------------*/872 676 873 677 /** … … 890 694 for(item = head->next; item != head; item = item->next) { 891 695 892 report_item = list_get_instance(item, usb_hid_report_field_t, 893 link); 696 report_item = list_get_instance(item, usb_hid_report_field_t, link); 894 697 895 698 usb_log_debug("\t\tOFFSET: %X\n", report_item->offset); 896 usb_log_debug("\t\tSIZE: %zu\n", report_item->size); 897 usb_log_debug("\t\tLOGMIN: %d\n", 898 report_item->logical_minimum); 899 usb_log_debug("\t\tLOGMAX: %d\n", 900 report_item->logical_maximum); 901 usb_log_debug("\t\tPHYMIN: %d\n", 902 report_item->physical_minimum); 903 usb_log_debug("\t\tPHYMAX: %d\n", 904 report_item->physical_maximum); 905 usb_log_debug("\t\ttUSAGEMIN: %X\n", 906 report_item->usage_minimum); 907 usb_log_debug("\t\tUSAGEMAX: %X\n", 908 report_item->usage_maximum); 909 usb_log_debug("\t\tUSAGES COUNT: %zu\n", 910 report_item->usages_count); 699 usb_log_debug("\t\tSIZE: %zu\n", report_item->size); 700 usb_log_debug("\t\tLOGMIN: %d\n", report_item->logical_minimum); 701 usb_log_debug("\t\tLOGMAX: %d\n", report_item->logical_maximum); 702 usb_log_debug("\t\tPHYMIN: %d\n", report_item->physical_minimum); 703 usb_log_debug("\t\tPHYMAX: %d\n", report_item->physical_maximum); 704 usb_log_debug("\t\ttUSAGEMIN: %X\n", report_item->usage_minimum); 705 usb_log_debug("\t\tUSAGEMAX: %X\n", report_item->usage_maximum); 706 usb_log_debug("\t\tUSAGES COUNT: %zu\n", report_item->usages_count); 911 707 912 708 usb_log_debug("\t\tVALUE: %X\n", report_item->value); … … 920 716 } 921 717 922 } 923 /*---------------------------------------------------------------------------*/ 924 718 719 } 925 720 /** 926 721 * Prints content of given report descriptor in human readable format. … … 939 734 940 735 while(report_it != &report->reports) { 941 report_des = list_get_instance(report_it, 942 usb_hid_report_description_t, link); 736 report_des = list_get_instance(report_it, usb_hid_report_description_t, link); 943 737 usb_log_debug("Report ID: %d\n", report_des->report_id); 944 738 usb_log_debug("\tType: %d\n", report_des->type); 945 739 usb_log_debug("\tLength: %zu\n", report_des->bit_length); 946 usb_log_debug("\tB Size: %zu\n",947 usb_hid_report_byte_size(report,948 report_des->report_id,949 report_des->type));950 740 usb_log_debug("\tItems: %zu\n", report_des->item_length); 951 741 952 742 usb_hid_descriptor_print_list(&report_des->report_items); 953 743 744 /* 745 link_t *path_it = report->collection_paths.next; 746 while(path_it != &report->collection_paths) { 747 usb_hid_print_usage_path (list_get_instance(path_it, usb_hid_report_path_t, link)); 748 path_it = path_it->next; 749 } 750 */ 954 751 report_it = report_it->next; 955 752 } 956 753 } 957 /*---------------------------------------------------------------------------*/958 754 959 755 /** … … 980 776 981 777 while(!list_empty(&report_item->usage_path->link)) { 982 778 usb_hid_report_remove_last_item(report_item->usage_path); 983 779 } 984 780 … … 992 788 993 789 } 994 /*---------------------------------------------------------------------------*/995 790 996 791 /** Frees the HID report descriptor parser structure … … 1008 803 usb_hid_report_path_t *path; 1009 804 while(!list_empty(&report->collection_paths)) { 1010 path = list_get_instance(report->collection_paths.next, 1011 usb_hid_report_path_t, link); 1012 805 path = list_get_instance(report->collection_paths.next, usb_hid_report_path_t, link); 1013 806 usb_hid_report_path_free(path); 1014 807 } … … 1018 811 usb_hid_report_field_t *field; 1019 812 while(!list_empty(&report->reports)) { 1020 report_des = list_get_instance(report->reports.next, 1021 usb_hid_report_description_t, link); 1022 813 report_des = list_get_instance(report->reports.next, usb_hid_report_description_t, link); 1023 814 list_remove(&report_des->link); 1024 815 1025 816 while(!list_empty(&report_des->report_items)) { 1026 field = list_get_instance( 1027 report_des->report_items.next, 1028 usb_hid_report_field_t, link); 1029 817 field = list_get_instance(report_des->report_items.next, usb_hid_report_field_t, link); 1030 818 list_remove(&field->link); 1031 819 … … 1038 826 return; 1039 827 } 1040 /*---------------------------------------------------------------------------*/1041 828 1042 829 /** -
uspace/lib/usbhid/src/hidparser.c
raaa3d82b r3e95cd7 119 119 } 120 120 else { 121 return ((report_des->bit_length + 7) / 8) ; 121 if(report_id == 0) { 122 return ((report_des->bit_length + 7) / 8) ; 123 } 124 else { 125 return 1 + ((report_des->bit_length + 7) / 8); 126 } 122 127 } 123 128 } … … 162 167 while(list_item != &(report_des->report_items)) { 163 168 164 item = list_get_instance(list_item, usb_hid_report_field_t, 165 link); 169 item = list_get_instance(list_item, usb_hid_report_field_t, link); 166 170 167 171 if(USB_HID_ITEM_FLAG_CONSTANT(item->item_flags) == 0) { … … 170 174 171 175 // array 172 item->value = 173 usb_hid_translate_data(item, data); 176 item->value = usb_hid_translate_data(item, data); 174 177 175 178 item->usage = USB_HID_EXTENDED_USAGE( 176 item->usages[item->value - item->physical_minimum]); 177 179 item->usages[item->value - item->physical_minimum]); 178 180 item->usage_page = USB_HID_EXTENDED_USAGE_PAGE( 179 item->usages[item->value - item->physical_minimum]);181 item->usages[item->value - item->physical_minimum]); 180 182 181 183 usb_hid_report_set_last_item (item->collection_path, 182 USB_HID_TAG_CLASS_GLOBAL, item->usage_page); 183 184 USB_HID_TAG_CLASS_GLOBAL, item->usage_page); 184 185 usb_hid_report_set_last_item (item->collection_path, 185 186 USB_HID_TAG_CLASS_LOCAL, item->usage); … … 272 273 } 273 274 274 return (int)(((value - item->logical_minimum) / resolution) + 275 item->physical_minimum); 275 return (int)(((value - item->logical_minimum) / resolution) + item->physical_minimum); 276 276 277 277 } … … 415 415 if(i == (offset/8)) { 416 416 tmp_value = value; 417 tmp_value = tmp_value & 418 ((1 << (8-(offset%8)))-1); 419 417 tmp_value = tmp_value & ((1 << (8-(offset%8)))-1); 420 418 tmp_value = tmp_value << (offset%8); 421 419 422 mask = ~(((1 << (8-(offset%8)))-1) << 423 (offset%8)); 424 425 buffer[i] = (buffer[i] & mask) | 426 tmp_value; 420 mask = ~(((1 << (8-(offset%8)))-1) << (offset%8)); 421 buffer[i] = (buffer[i] & mask) | tmp_value; 427 422 } 428 423 else if (i == ((offset + length -1)/8)) { 429 424 430 value = value >> (length - 431 ((offset + length) % 8)); 432 433 value = value & ((1 << (length - 434 ((offset + length) % 8))) - 1); 425 value = value >> (length - ((offset + length) % 8)); 426 value = value & 427 ((1 << (length - ((offset + length) % 8))) - 1); 435 428 436 mask = (1 << (length - 437 ((offset + length) % 8))) - 1; 438 429 mask = (1 << (length - ((offset + length) % 8))) - 1; 439 430 buffer[i] = (buffer[i] & mask) | value; 440 431 } … … 538 529 usb_hid_report_type_t type) 539 530 { 540 usb_hid_report_description_t *report_des = 541 usb_hid_report_find_description(report, path->report_id, type);531 usb_hid_report_description_t *report_des = usb_hid_report_find_description( 532 report, path->report_id, type); 542 533 543 534 link_t *field_it; … … 555 546 556 547 while(field_it != &report_des->report_items) { 557 field = list_get_instance(field_it, usb_hid_report_field_t, 558 link); 548 field = list_get_instance(field_it, usb_hid_report_field_t, link); 559 549 560 550 if(USB_HID_ITEM_FLAG_CONSTANT(field->item_flags) == 0) { 561 usb_hid_report_path_append_item ( 562 field->collection_path, field->usage_page, 563 field->usage); 564 565 if(usb_hid_report_compare_usage_path( 566 field->collection_path, path, flags) == EOK){ 567 568 usb_hid_report_remove_last_item( 569 field->collection_path); 570 551 usb_hid_report_path_append_item (field->collection_path, 552 field->usage_page, field->usage); 553 554 if(usb_hid_report_compare_usage_path(field->collection_path, path, 555 flags) == EOK){ 556 557 usb_hid_report_remove_last_item(field->collection_path); 571 558 return field; 572 559 } 573 usb_hid_report_remove_last_item ( 574 field->collection_path); 560 usb_hid_report_remove_last_item (field->collection_path); 575 561 } 576 562 field_it = field_it->next; -
uspace/lib/usbhid/src/hidpath.c
raaa3d82b r3e95cd7 225 225 226 226 switch(flags){ 227 /* path is somewhere in report_path */ 228 case USB_HID_PATH_COMPARE_ANYWHERE: 229 if(path->depth != 1){ 230 return 1; 231 } 232 233 report_link = report_path->head.next; 234 path_link = path->head.next; 235 path_item = list_get_instance(path_link, 236 usb_hid_report_usage_path_t, link); 237 238 while(report_link != &report_path->head) { 239 report_item = list_get_instance(report_link, 227 /* path is somewhere in report_path */ 228 case USB_HID_PATH_COMPARE_ANYWHERE: 229 if(path->depth != 1){ 230 return 1; 231 } 232 233 report_link = report_path->head.next; 234 path_link = path->head.next; 235 path_item = list_get_instance(path_link, 240 236 usb_hid_report_usage_path_t, link); 237 238 while(report_link != &report_path->head) { 239 report_item = list_get_instance(report_link, 240 usb_hid_report_usage_path_t, link); 241 241 242 if(USB_HID_SAME_USAGE_PAGE(report_item->usage_page,243 path_item->usage_page)){242 if(USB_HID_SAME_USAGE_PAGE(report_item->usage_page, 243 path_item->usage_page)){ 244 244 245 if(only_page == 0){ 246 if(USB_HID_SAME_USAGE( 247 report_item->usage, 248 path_item->usage)) { 245 if(only_page == 0){ 246 if(USB_HID_SAME_USAGE(report_item->usage, 247 path_item->usage)) { 249 248 249 return EOK; 250 } 251 } 252 else { 250 253 return EOK; 251 254 } 252 255 } 256 257 report_link = report_link->next; 258 } 259 260 return 1; 261 break; 262 /* the paths must be identical */ 263 case USB_HID_PATH_COMPARE_STRICT: 264 if(report_path->depth != path->depth){ 265 return 1; 266 } 267 268 /* path is prefix of the report_path */ 269 case USB_HID_PATH_COMPARE_BEGIN: 270 271 report_link = report_path->head.next; 272 path_link = path->head.next; 273 274 while((report_link != &report_path->head) && 275 (path_link != &path->head)) { 276 277 report_item = list_get_instance(report_link, 278 usb_hid_report_usage_path_t, link); 279 280 path_item = list_get_instance(path_link, 281 usb_hid_report_usage_path_t, link); 282 283 if(!USB_HID_SAME_USAGE_PAGE(report_item->usage_page, 284 path_item->usage_page) || ((only_page == 0) && 285 !USB_HID_SAME_USAGE(report_item->usage, 286 path_item->usage))) { 287 288 return 1; 289 } else { 290 report_link = report_link->next; 291 path_link = path_link->next; 292 } 293 294 } 295 296 if((((flags & USB_HID_PATH_COMPARE_BEGIN) != 0) && 297 (path_link == &path->head)) || 298 ((report_link == &report_path->head) && 299 (path_link == &path->head))) { 300 301 return EOK; 302 } 253 303 else { 304 return 1; 305 } 306 break; 307 308 /* path is suffix of report_path */ 309 case USB_HID_PATH_COMPARE_END: 310 311 report_link = report_path->head.prev; 312 path_link = path->head.prev; 313 314 if(list_empty(&path->head)){ 254 315 return EOK; 255 316 } 256 }257 258 report_link = report_link->next;259 }260 261 return 1;262 break;263 264 /* the paths must be identical */265 case USB_HID_PATH_COMPARE_STRICT:266 if(report_path->depth != path->depth){267 return 1;268 }269 270 /* path is prefix of the report_path */271 case USB_HID_PATH_COMPARE_BEGIN:272 273 report_link = report_path->head.next;274 path_link = path->head.next;275 317 276 while((report_link != &report_path->head) && 277 (path_link != &path->head)) { 278 279 report_item = list_get_instance(report_link, 280 usb_hid_report_usage_path_t, link); 281 282 path_item = list_get_instance(path_link, 283 usb_hid_report_usage_path_t, link); 284 285 if(!USB_HID_SAME_USAGE_PAGE(report_item->usage_page, 286 path_item->usage_page) || ((only_page == 0) && 287 !USB_HID_SAME_USAGE(report_item->usage, 288 path_item->usage))) { 318 while((report_link != &report_path->head) && 319 (path_link != &path->head)) { 320 321 report_item = list_get_instance(report_link, 322 usb_hid_report_usage_path_t, link); 323 324 path_item = list_get_instance(path_link, 325 usb_hid_report_usage_path_t, link); 326 327 if(!USB_HID_SAME_USAGE_PAGE(report_item->usage_page, 328 path_item->usage_page) || ((only_page == 0) && 329 !USB_HID_SAME_USAGE(report_item->usage, 330 path_item->usage))) { 331 332 return 1; 333 } else { 334 report_link = report_link->prev; 335 path_link = path_link->prev; 336 } 289 337 290 return 1; 291 } 292 else { 293 report_link = report_link->next; 294 path_link = path_link->next; 295 } 338 } 339 340 if(path_link == &path->head) { 341 return EOK; 342 } 343 else { 344 return 1; 345 } 296 346 297 } 298 299 if((((flags & USB_HID_PATH_COMPARE_BEGIN) != 0) && 300 (path_link == &path->head)) || 301 ((report_link == &report_path->head) && 302 (path_link == &path->head))) { 303 304 return EOK; 305 } 306 else { 307 return 1; 308 } 309 break; 310 311 /* path is suffix of report_path */ 312 case USB_HID_PATH_COMPARE_END: 313 314 report_link = report_path->head.prev; 315 path_link = path->head.prev; 316 317 if(list_empty(&path->head)){ 318 return EOK; 319 } 320 321 while((report_link != &report_path->head) && 322 (path_link != &path->head)) { 323 324 report_item = list_get_instance(report_link, 325 usb_hid_report_usage_path_t, link); 326 327 path_item = list_get_instance(path_link, 328 usb_hid_report_usage_path_t, link); 329 330 if(!USB_HID_SAME_USAGE_PAGE(report_item->usage_page, 331 path_item->usage_page) || ((only_page == 0) && 332 !USB_HID_SAME_USAGE(report_item->usage, 333 path_item->usage))) { 334 335 return 1; 336 } else { 337 report_link = report_link->prev; 338 path_link = path_link->prev; 339 } 340 341 } 342 343 if(path_link == &path->head) { 344 return EOK; 345 } 346 else { 347 return 1; 348 } 349 350 break; 351 352 default: 353 return EINVAL; 347 break; 348 349 default: 350 return EINVAL; 354 351 } 355 352 } … … 421 418 path_link = usage_path->head.next; 422 419 while(path_link != &usage_path->head) { 423 path_item = list_get_instance(path_link, 424 usb_hid_report_usage_path_t, link); 425 420 path_item = list_get_instance(path_link, usb_hid_report_usage_path_t, 421 link); 426 422 new_path_item = malloc(sizeof(usb_hid_report_usage_path_t)); 427 423 if(new_path_item == NULL) {
Note:
See TracChangeset
for help on using the changeset viewer.