Changeset 5499a8b in mainline
- Timestamp:
- 2011-05-20T13:43:09Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 14e7959
- Parents:
- 74b1e40
- Location:
- uspace/lib/usbhid/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbhid/src/hidparser.c
r74b1e40 r5499a8b 31 31 */ 32 32 /** @file 33 * HID report descriptor andreport data parser implementation.33 * USB HID report data parser implementation. 34 34 */ 35 35 #include <usb/hid/hidparser.h> … … 41 41 #include <assert.h> 42 42 43 43 /*---------------------------------------------------------------------------*/ 44 44 /* 45 45 * Data translation private functions 46 46 */ 47 47 uint32_t usb_hid_report_tag_data_uint32(const uint8_t *data, size_t size); 48 //inline size_t usb_hid_count_item_offset(usb_hid_report_item_t * report_item, size_t offset); 48 49 49 int usb_hid_translate_data(usb_hid_report_field_t *item, const uint8_t *data); 50 uint32_t usb_hid_translate_data_reverse(usb_hid_report_field_t *item, int32_t value); 50 51 uint32_t usb_hid_translate_data_reverse(usb_hid_report_field_t *item, 52 int32_t value); 53 51 54 int usb_pow(int a, int b); 52 55 56 /*---------------------------------------------------------------------------*/ 53 57 54 58 // TODO: tohle ma bejt asi jinde … … 56 60 { 57 61 switch(b) { 58 59 60 61 62 63 64 65 66 67 } 68 } 69 62 case 0: 63 return 1; 64 break; 65 case 1: 66 return a; 67 break; 68 default: 69 return a * usb_pow(a, b-1); 70 break; 71 } 72 } 73 /*---------------------------------------------------------------------------*/ 70 74 71 75 /** Returns size of report of specified report id and type in items … … 93 97 } 94 98 } 95 99 /*---------------------------------------------------------------------------*/ 96 100 97 101 /** Parse and act upon a HID report. … … 103 107 * @return Error code. 104 108 */ 105 int usb_hid_parse_report(const usb_hid_report_t *report, 106 const uint8_t *data,size_t size, uint8_t *report_id)109 int usb_hid_parse_report(const usb_hid_report_t *report, const uint8_t *data, 110 size_t size, uint8_t *report_id) 107 111 { 108 112 link_t *list_item; … … 139 143 item->value = usb_hid_translate_data(item, data); 140 144 141 item->usage = USB_HID_EXTENDED_USAGE(item->usages[item->value - item->physical_minimum]); 142 item->usage_page = USB_HID_EXTENDED_USAGE_PAGE(item->usages[item->value - item->physical_minimum]); 145 item->usage = USB_HID_EXTENDED_USAGE( 146 item->usages[item->value - item->physical_minimum]); 147 item->usage_page = USB_HID_EXTENDED_USAGE_PAGE( 148 item->usages[item->value - item->physical_minimum]); 143 149 144 150 usb_hid_report_set_last_item (item->collection_path, 145 USB_HID_TAG_CLASS_GLOBAL, 146 item->usage_page); 151 USB_HID_TAG_CLASS_GLOBAL, item->usage_page); 147 152 usb_hid_report_set_last_item (item->collection_path, 148 USB_HID_TAG_CLASS_LOCAL, 149 item->usage); 153 USB_HID_TAG_CLASS_LOCAL, item->usage); 150 154 151 155 } … … 162 166 } 163 167 168 /*---------------------------------------------------------------------------*/ 164 169 /** 165 170 * Translate data from the report as specified in report descriptor item … … 167 172 * @param item Report descriptor item with definition of translation 168 173 * @param data Data to translate 169 * @param j Index of processed field in report descriptor item170 174 * @return Translated data 171 175 */ … … 240 244 } 241 245 242 /*** OUTPUT API **/ 246 /*---------------------------------------------------------------------------*/ 247 /* OUTPUT API */ 243 248 244 249 /** … … 250 255 * @return Returns allocated output buffer for specified output 251 256 */ 252 uint8_t *usb_hid_report_output(usb_hid_report_t *report, size_t *size, uint8_t report_id) 257 uint8_t *usb_hid_report_output(usb_hid_report_t *report, size_t *size, 258 uint8_t report_id) 253 259 { 254 260 if(report == NULL) { … … 260 266 usb_hid_report_description_t *report_des = NULL; 261 267 while(report_it != &report->reports) { 262 report_des = list_get_instance(report_it, usb_hid_report_description_t, link); 263 if((report_des->report_id == report_id) && (report_des->type == USB_HID_REPORT_TYPE_OUTPUT)){ 268 report_des = list_get_instance(report_it, 269 usb_hid_report_description_t, link); 270 271 if((report_des->report_id == report_id) && 272 (report_des->type == USB_HID_REPORT_TYPE_OUTPUT)){ 264 273 break; 265 274 } … … 303 312 * @return Error code 304 313 */ 305 int usb_hid_report_output_translate(usb_hid_report_t *report, uint8_t report_id,306 314 int usb_hid_report_output_translate(usb_hid_report_t *report, 315 uint8_t report_id, uint8_t *buffer, size_t size) 307 316 { 308 317 link_t *item; … … 320 329 } 321 330 322 usb_log_debug("OUTPUT BUFFER: %s\n", usb_debug_str_buffer(buffer,size, 0));323 324 331 usb_hid_report_description_t *report_des; 325 report_des = usb_hid_report_find_description (report, report_id, USB_HID_REPORT_TYPE_OUTPUT); 332 report_des = usb_hid_report_find_description (report, report_id, 333 USB_HID_REPORT_TYPE_OUTPUT); 334 326 335 if(report_des == NULL){ 327 336 return EINVAL; … … 333 342 report_item = list_get_instance(item, usb_hid_report_field_t, link); 334 343 335 usb_log_debug("OUTPUT ITEM usage(%x), value(%x)\n", report_item->usage, report_item->value);336 337 344 if(USB_HID_ITEM_FLAG_VARIABLE(report_item->item_flags) == 0) { 338 345 339 346 // array 340 value = usb_hid_translate_data_reverse(report_item, report_item->value); 347 value = usb_hid_translate_data_reverse(report_item, 348 report_item->value); 349 341 350 offset = report_item->offset; 342 351 length = report_item->size; … … 344 353 else { 345 354 // variable item 346 value = usb_hid_translate_data_reverse(report_item, report_item->value); 355 value = usb_hid_translate_data_reverse(report_item, 356 report_item->value); 357 347 358 offset = report_item->offset; 348 359 length = report_item->size; … … 353 364 if((offset/8) == ((offset+length-1)/8)) { 354 365 // je to v jednom bytu 355 if(((size_t)(offset/8) >= size) || ((size_t)(offset+length-1)/8) >= size) { 366 if(((size_t)(offset/8) >= size) || 367 ((size_t)(offset+length-1)/8) >= size) { 356 368 break; // TODO ErrorCode 357 369 } … … 379 391 380 392 value = value >> (length - ((offset + length) % 8)); 381 value = value & ((1 << (length - ((offset + length) % 8))) - 1); 393 value = value & 394 ((1 << (length - ((offset + length) % 8))) - 1); 382 395 383 396 mask = (1 << (length - ((offset + length) % 8))) - 1; … … 396 409 } 397 410 398 usb_log_debug("OUTPUT BUFFER: %s\n", usb_debug_str_buffer(buffer,size, 0));399 400 411 return EOK; 401 412 } 402 413 414 /*---------------------------------------------------------------------------*/ 403 415 /** 404 416 * Translate given data for putting them into the outoput report … … 407 419 * @return ranslated value 408 420 */ 409 uint32_t usb_hid_translate_data_reverse(usb_hid_report_field_t *item, int value) 421 uint32_t usb_hid_translate_data_reverse(usb_hid_report_field_t *item, 422 int value) 410 423 { 411 424 int ret=0; … … 431 444 } 432 445 433 ret = ((value - item->physical_minimum) * resolution) + item->logical_minimum; 434 usb_log_debug("\tvalue(%x), resolution(%x), phymin(%x) logmin(%x), ret(%x)\n", value, resolution, item->physical_minimum, item->logical_minimum, ret); 446 ret = ((value - item->physical_minimum) * resolution) + 447 item->logical_minimum; 448 449 usb_log_debug("\tvalue(%x), resolution(%x), phymin(%x) logmin(%x), \ 450 ret(%x)\n", value, resolution, item->physical_minimum, 451 item->logical_minimum, ret); 435 452 436 453 if((item->logical_minimum < 0) || (item->logical_maximum < 0)){ … … 440 457 } 441 458 442 usb_hid_report_item_t *usb_hid_report_item_clone(const usb_hid_report_item_t *item) 459 /*---------------------------------------------------------------------------*/ 460 /** 461 * Clones given state table 462 * 463 * @param item State table to clone 464 * @return Pointer to the cloned item 465 */ 466 usb_hid_report_item_t *usb_hid_report_item_clone( 467 const usb_hid_report_item_t *item) 443 468 { 444 469 usb_hid_report_item_t *new_report_item; … … 453 478 } 454 479 455 480 /*---------------------------------------------------------------------------*/ 481 /** 482 * Function for sequence walking through the report. Returns next field in the 483 * report or the first one when no field is given. 484 * 485 * @param report Searched report structure 486 * @param field Current field. If NULL is given, the first one in the report 487 * is returned. Otherwise the next one i nthe list is returned. 488 * @param path Usage path specifying which fields wa are interested in. 489 * @param flags Flags defining mode of usage paths comparison 490 * @param type Type of report we search. 491 * @retval NULL if no field is founded 492 * @retval Pointer to the founded report structure when founded 493 */ 456 494 usb_hid_report_field_t *usb_hid_report_get_sibling(usb_hid_report_t *report, 457 usb_hid_report_field_t *field, 458 usb_hid_report_path_t *path, int flags, 459 usb_hid_report_type_t type) 460 { 461 usb_hid_report_description_t *report_des = usb_hid_report_find_description (report, path->report_id, type); 495 usb_hid_report_field_t *field, usb_hid_report_path_t *path, int flags, 496 usb_hid_report_type_t type) 497 { 498 usb_hid_report_description_t *report_des = usb_hid_report_find_description( 499 report, path->report_id, type); 500 462 501 link_t *field_it; 463 502 … … 467 506 468 507 if(field == NULL){ 469 // vezmu prvni co mathuje podle path!!470 508 field_it = report_des->report_items.next; 471 509 } … … 478 516 479 517 if(USB_HID_ITEM_FLAG_CONSTANT(field->item_flags) == 0) { 480 usb_hid_report_path_append_item (field->collection_path, field->usage_page, field->usage); 481 if(usb_hid_report_compare_usage_path (field->collection_path, path, flags) == EOK){ 482 usb_hid_report_remove_last_item (field->collection_path); 518 usb_hid_report_path_append_item (field->collection_path, 519 field->usage_page, field->usage); 520 521 if(usb_hid_report_compare_usage_path(field->collection_path, path, 522 flags) == EOK){ 523 524 usb_hid_report_remove_last_item(field->collection_path); 483 525 return field; 484 526 } … … 491 533 } 492 534 493 uint8_t usb_hid_report_get_report_id(usb_hid_report_t *report, uint8_t report_id, usb_hid_report_type_t type) 535 /*---------------------------------------------------------------------------*/ 536 /** 537 * Returns nonzero (report_id) number if there is report of given type and 538 * have the specified report_id in report structure 539 * 540 * @param report_id Searched report id 541 * @param type Type of searched report 542 * @param report Report structure inwhich we search 543 * @retval 0 if report structure is null or there is no specified report 544 * @retval report_id otherwise 545 */ 546 uint8_t usb_hid_report_get_report_id(usb_hid_report_t *report, 547 uint8_t report_id, usb_hid_report_type_t type) 494 548 { 495 549 if(report == NULL){ … … 501 555 502 556 if(report_id == 0) { 503 report_it = usb_hid_report_find_description (report, report_id, type)->link.next; 557 report_it = usb_hid_report_find_description(report, report_id, 558 type)->link.next; 504 559 } 505 560 else { … … 508 563 509 564 while(report_it != &report->reports) { 510 report_des = list_get_instance(report_it, usb_hid_report_description_t, link); 565 report_des = list_get_instance(report_it, usb_hid_report_description_t, 566 link); 567 511 568 if(report_des->type == type){ 512 569 return report_des->report_id; … … 517 574 } 518 575 576 /*---------------------------------------------------------------------------*/ 577 /** 578 * Reset all local items in given state table 579 * 580 * @param report_item State table containing current state of report 581 * descriptor parsing 582 * 583 * @return void 584 */ 519 585 void usb_hid_report_reset_local_items(usb_hid_report_item_t *report_item) 520 586 { -
uspace/lib/usbhid/src/hidpath.c
r74b1e40 r5499a8b 41 41 #include <assert.h> 42 42 43 44 #define USB_HID_SAME_USAGE(usage1, usage2) ((usage1 == usage2) || (usage1 == 0) || (usage2 == 0)) 45 #define USB_HID_SAME_USAGE_PAGE(page1, page2) ((page1 == page2) || (page1 == 0) || (page2 == 0)) 46 43 /*---------------------------------------------------------------------------*/ 44 /** 45 * Compares two usages if they are same or not or one of the usages is not 46 * set. 47 * 48 * @param usage1 49 * @param usage2 50 * @return boolean 51 */ 52 #define USB_HID_SAME_USAGE(usage1, usage2) \ 53 ((usage1 == usage2) || (usage1 == 0) || (usage2 == 0)) 54 55 /** 56 * Compares two usage pages if they are same or not or one of them is not set. 57 * 58 * @param page1 59 * @param page2 60 * @return boolean 61 */ 62 #define USB_HID_SAME_USAGE_PAGE(page1, page2) \ 63 ((page1 == page2) || (page1 == 0) || (page2 == 0)) 64 65 /*---------------------------------------------------------------------------*/ 47 66 /** 48 67 * Appends one item (couple of usage_path and usage) into the usage path … … 73 92 } 74 93 94 /*---------------------------------------------------------------------------*/ 75 95 /** 76 96 * Removes last item from the usage path structure … … 91 111 } 92 112 113 /*---------------------------------------------------------------------------*/ 93 114 /** 94 115 * Nulls last item of the usage path structure. … … 102 123 103 124 if(!list_empty(&usage_path->head)){ 104 item = list_get_instance(usage_path->head.prev, usb_hid_report_usage_path_t, link); 125 item = list_get_instance(usage_path->head.prev, 126 usb_hid_report_usage_path_t, link); 127 105 128 memset(item, 0, sizeof(usb_hid_report_usage_path_t)); 106 129 } 107 130 } 108 131 132 /*---------------------------------------------------------------------------*/ 109 133 /** 110 134 * Modifies last item of usage path structure by given usage page or usage … … 137 161 } 138 162 139 163 /*---------------------------------------------------------------------------*/ 164 /** 165 * 166 * 167 * 168 * 169 */ 140 170 void usb_hid_print_usage_path(usb_hid_report_path_t *path) 141 171 { … … 147 177 while(item != &path->head) { 148 178 149 path_item = list_get_instance(item, usb_hid_report_usage_path_t, link); 179 path_item = list_get_instance(item, usb_hid_report_usage_path_t, 180 link); 181 150 182 usb_log_debug("\tUSAGE_PAGE: %X\n", path_item->usage_page); 151 183 usb_log_debug("\tUSAGE: %X\n", path_item->usage); 152 184 usb_log_debug("\tFLAGS: %d\n", path_item->flags); 153 185 154 item = item->next; 155 } 156 } 157 186 item = item->next; 187 } 188 } 189 190 /*---------------------------------------------------------------------------*/ 158 191 /** 159 192 * Compares two usage paths structures … … 198 231 } 199 232 200 // projit skrz cestu a kdyz nekde sedi tak vratim EOK201 // dojduli az za konec tak nnesedi202 233 report_link = report_path->head.next; 203 234 path_link = path->head.next; 204 path_item = list_get_instance(path_link, usb_hid_report_usage_path_t, link); 235 path_item = list_get_instance(path_link, 236 usb_hid_report_usage_path_t, link); 205 237 206 238 while(report_link != &report_path->head) { 207 report_item = list_get_instance(report_link, usb_hid_report_usage_path_t, link); 208 if(USB_HID_SAME_USAGE_PAGE(report_item->usage_page, path_item->usage_page)){ 239 report_item = list_get_instance(report_link, 240 usb_hid_report_usage_path_t, link); 241 242 if(USB_HID_SAME_USAGE_PAGE(report_item->usage_page, 243 path_item->usage_page)){ 244 209 245 if(only_page == 0){ 210 if(USB_HID_SAME_USAGE(report_item->usage, path_item->usage)) { 246 if(USB_HID_SAME_USAGE(report_item->usage, 247 path_item->usage)) { 248 211 249 return EOK; 212 250 } … … 238 276 239 277 report_item = list_get_instance(report_link, 240 usb_hid_report_usage_path_t, 241 link); 278 usb_hid_report_usage_path_t, link); 242 279 243 280 path_item = list_get_instance(path_link, 244 usb_hid_report_usage_path_t, 245 link); 246 247 if(!USB_HID_SAME_USAGE_PAGE(report_item->usage_page, path_item->usage_page) ||248 ((only_page == 0) &&249 !USB_HID_SAME_USAGE(report_item->usage,path_item->usage))) {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))) { 250 287 251 288 return 1; … … 257 294 } 258 295 259 if((((flags & USB_HID_PATH_COMPARE_BEGIN) != 0) && (path_link == &path->head)) || 260 ((report_link == &report_path->head) && (path_link == &path->head))) { 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 261 301 return EOK; 262 302 } … … 280 320 281 321 report_item = list_get_instance(report_link, 282 usb_hid_report_usage_path_t,283 link); 322 usb_hid_report_usage_path_t, link); 323 284 324 path_item = list_get_instance(path_link, 285 usb_hid_report_usage_path_t, 286 link); 325 usb_hid_report_usage_path_t, link); 287 326 288 if(!USB_HID_SAME_USAGE_PAGE(report_item->usage_page, path_item->usage_page) || 289 ((only_page == 0) && 290 !USB_HID_SAME_USAGE(report_item->usage, path_item->usage))) { 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 291 332 return 1; 292 333 } else { … … 311 352 } 312 353 354 /*---------------------------------------------------------------------------*/ 313 355 /** 314 356 * Allocates and initializes new usage path structure. … … 332 374 } 333 375 376 /*---------------------------------------------------------------------------*/ 334 377 /** 335 378 * Releases given usage path structure. … … 348 391 } 349 392 350 393 /*---------------------------------------------------------------------------*/ 351 394 /** 352 395 * Clone content of given usage path to the new one … … 355 398 * @return New copy of given usage path structure 356 399 */ 357 usb_hid_report_path_t *usb_hid_report_path_clone(usb_hid_report_path_t *usage_path) 400 usb_hid_report_path_t *usb_hid_report_path_clone( 401 usb_hid_report_path_t *usage_path) 358 402 { 359 403 link_t *path_link; … … 374 418 path_link = usage_path->head.next; 375 419 while(path_link != &usage_path->head) { 376 path_item = list_get_instance(path_link, usb_hid_report_usage_path_t, 420 path_item = list_get_instance(path_link, usb_hid_report_usage_path_t, 377 421 link); 378 422 new_path_item = malloc(sizeof(usb_hid_report_usage_path_t)); … … 395 439 } 396 440 397 441 /*---------------------------------------------------------------------------*/ 398 442 /** 399 443 * Sets report id in usage path structure … … 403 447 * @return Error code 404 448 */ 405 int usb_hid_report_path_set_report_id(usb_hid_report_path_t *path, uint8_t report_id) 449 int usb_hid_report_path_set_report_id(usb_hid_report_path_t *path, 450 uint8_t report_id) 406 451 { 407 452 if(path == NULL){
Note:
See TracChangeset
for help on using the changeset viewer.