Changeset e60436b in mainline
- Timestamp:
- 2011-04-21T19:58:20Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 36f737a
- Parents:
- 3bcac68
- Location:
- uspace/drv/usbhid
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbhid/kbd/kbddev.c
r3bcac68 re60436b 177 177 /*----------------------------------------------------------------------------*/ 178 178 179 static void usb_kbd_process_keycodes(const uint8_t *key_codes, size_t count,180 uint8_t report_id, void *arg);181 182 static const usb_hid_report_in_callbacks_t usb_kbd_parser_callbacks = {183 .keyboard = usb_kbd_process_keycodes184 };179 //static void usb_kbd_process_keycodes(const uint8_t *key_codes, size_t count, 180 // uint8_t report_id, void *arg); 181 182 //static const usb_hid_report_in_callbacks_t usb_kbd_parser_callbacks = { 183 // .keyboard = usb_kbd_process_keycodes 184 //}; 185 185 186 186 /*----------------------------------------------------------------------------*/ … … 320 320 // TODO: COMPOSE and KANA 321 321 322 usb_log_debug("Creating output report: %s\n", usb_debug_str_buffer ((uint8_t *)kbd_dev->led_data, kbd_dev->led_output_size * 4, 0)); 323 324 usb_hid_report_output_set_data(hid_dev->parser, kbd_dev->led_path, 325 USB_HID_PATH_COMPARE_END , kbd_dev->led_data, 326 kbd_dev->led_output_size); 327 int rc = usb_hid_report_output_translate(hid_dev->parser, 0, 322 usb_log_debug("Creating output report: "); 323 for (i = 0; i < kbd_dev->led_output_size; ++i) { 324 usb_log_debug("%d ", kbd_dev->led_data[i]); 325 } 326 usb_log_debug("\n"); 327 328 usb_hid_report_output_set_data(hid_dev->report, kbd_dev->led_path, 329 USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 330 kbd_dev->led_data, kbd_dev->led_output_size); 331 int rc = usb_hid_report_output_translate(hid_dev->report, 0, 328 332 kbd_dev->output_buffer, kbd_dev->output_size); 329 333 … … 333 337 return; 334 338 } 339 340 // TODO: output translating does not work!! 335 341 336 342 usb_log_debug("Output report buffer: %s\n", … … 485 491 */ 486 492 static void usb_kbd_check_key_changes(usb_hid_dev_t *hid_dev, 487 usb_kbd_t *kbd_dev , const uint8_t *key_codes, size_t count)493 usb_kbd_t *kbd_dev/*, const uint8_t *key_codes, size_t count*/) 488 494 { 489 495 unsigned int key; … … 499 505 */ 500 506 i = 0; 501 while (i < count && key_codes[i] != ERROR_ROLLOVER) {507 while (i < kbd_dev->key_count && kbd_dev->keys[i] != ERROR_ROLLOVER) { 502 508 ++i; 503 509 } 504 if (i != count) {510 if (i != kbd_dev->key_count) { 505 511 usb_log_debug("Phantom state occured.\n"); 506 512 // phantom state, do nothing 507 513 return; 508 514 } 509 510 /* TODO: quite dummy right now, think of better implementation */511 assert(count == kbd_dev->key_count);512 515 513 516 /* 514 517 * 1) Key releases 515 518 */ 516 for (j = 0; j < count; ++j) {519 for (j = 0; j < kbd_dev->key_count; ++j) { 517 520 // try to find the old key in the new key list 518 521 i = 0; 519 522 while (i < kbd_dev->key_count 520 && k ey_codes[i] != kbd_dev->keys[j]) {523 && kbd_dev->keys[i] != kbd_dev->keys_old[j]) { 521 524 ++i; 522 525 } 523 526 524 if (i == count) {527 if (i == kbd_dev->key_count) { 525 528 // not found, i.e. the key was released 526 key = usbhid_parse_scancode(kbd_dev->keys [j]);529 key = usbhid_parse_scancode(kbd_dev->keys_old[j]); 527 530 if (!usb_kbd_is_lock(key)) { 528 531 usb_kbd_repeat_stop(kbd_dev, key); … … 541 544 // try to find the new key in the old key list 542 545 j = 0; 543 while (j < count && kbd_dev->keys[j] != key_codes[i]) { 546 while (j < kbd_dev->key_count 547 && kbd_dev->keys_old[j] != kbd_dev->keys[i]) { 544 548 ++j; 545 549 } 546 550 547 if (j == count) {551 if (j == kbd_dev->key_count) { 548 552 // not found, i.e. new key pressed 549 key = usbhid_parse_scancode(k ey_codes[i]);553 key = usbhid_parse_scancode(kbd_dev->keys[i]); 550 554 usb_log_debug2("Key pressed: %d (keycode: %d)\n", key, 551 key_codes[i]); 552 usb_kbd_push_ev(hid_dev, kbd_dev, KEY_PRESS, 553 key); 555 kbd_dev->keys[i]); 556 usb_kbd_push_ev(hid_dev, kbd_dev, KEY_PRESS, key); 554 557 if (!usb_kbd_is_lock(key)) { 555 558 usb_kbd_repeat_start(kbd_dev, key); … … 560 563 } 561 564 562 memcpy(kbd_dev->keys, key_codes, count); 563 564 usb_log_debug("New stored keycodes: %s\n", 565 usb_debug_str_buffer(kbd_dev->keys, kbd_dev->key_count, 0)); 565 // usb_log_debug("Old keys: "); 566 // for (i = 0; i < kbd_dev->key_count; ++i) { 567 // usb_log_debug("%d ", kbd_dev->keys_old[i]); 568 // } 569 // usb_log_debug("\n"); 570 571 572 // usb_log_debug("New keys: "); 573 // for (i = 0; i < kbd_dev->key_count; ++i) { 574 // usb_log_debug("%d ", kbd_dev->keys[i]); 575 // } 576 // usb_log_debug("\n"); 577 578 memcpy(kbd_dev->keys_old, kbd_dev->keys, kbd_dev->key_count * 4); 579 580 usb_log_debug2("New stored keys: "); 581 for (i = 0; i < kbd_dev->key_count; ++i) { 582 usb_log_debug2("%d ", kbd_dev->keys_old[i]); 583 } 584 usb_log_debug2("\n"); 566 585 } 567 586 … … 585 604 * @sa usb_kbd_check_key_changes(), usb_kbd_check_modifier_changes() 586 605 */ 587 static void usb_kbd_process_keycodes(const uint8_t *key_codes, size_t count,588 uint8_t report_id, void *arg)589 {590 if (arg == NULL) {591 usb_log_warning("Missing argument in callback "592 "usbhid_process_keycodes().\n");593 return;594 }595 596 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)arg;597 598 if (hid_dev->data == NULL) {599 usb_log_warning("Missing KBD device structure in callback.\n");600 return;601 }602 603 usb_kbd_t *kbd_dev = (usb_kbd_t *)hid_dev->data;604 605 usb_log_debug("Got keys from parser (report id: %u): %s\n",606 report_id, usb_debug_str_buffer(key_codes, count, 0));607 608 if (count != kbd_dev->key_count) {609 usb_log_warning("Number of received keycodes (%zu) differs from"610 " expected (%zu).\n", count, kbd_dev->key_count);611 return;612 }613 614 ///usb_kbd_check_modifier_changes(kbd_dev, key_codes, count);615 usb_kbd_check_key_changes(hid_dev, kbd_dev, key_codes, count);616 }606 //static void usb_kbd_process_keycodes(const uint8_t *key_codes, size_t count, 607 // uint8_t report_id, void *arg) 608 //{ 609 // if (arg == NULL) { 610 // usb_log_warning("Missing argument in callback " 611 // "usbhid_process_keycodes().\n"); 612 // return; 613 // } 614 615 // usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)arg; 616 617 // if (hid_dev->data == NULL) { 618 // usb_log_warning("Missing KBD device structure in callback.\n"); 619 // return; 620 // } 621 622 // usb_kbd_t *kbd_dev = (usb_kbd_t *)hid_dev->data; 623 624 // usb_log_debug("Got keys from parser (report id: %u): %s\n", 625 // report_id, usb_debug_str_buffer(key_codes, count, 0)); 626 627 // if (count != kbd_dev->key_count) { 628 // usb_log_warning("Number of received keycodes (%zu) differs from" 629 // " expected (%zu).\n", count, kbd_dev->key_count); 630 // return; 631 // } 632 633 // ///usb_kbd_check_modifier_changes(kbd_dev, key_codes, count); 634 // usb_kbd_check_key_changes(hid_dev, kbd_dev, key_codes, count); 635 //} 617 636 618 637 /*----------------------------------------------------------------------------*/ … … 638 657 uint8_t *buffer, size_t actual_size) 639 658 { 640 assert(hid_dev->parser != NULL); 659 assert(hid_dev->report != NULL); 660 assert(hid_dev != NULL); 661 assert(hid_dev->data != NULL); 662 663 usb_kbd_t *kbd_dev = (usb_kbd_t *)hid_dev->data; 641 664 642 665 usb_log_debug("Calling usb_hid_parse_report() with " … … 649 672 //usb_hid_report_path_set_report_id(path, 0); 650 673 651 int rc = usb_hid_parse_report(hid_dev->parser, buffer, actual_size); 652 usb_hid_report_field_t *field = usb_hid_report_get_sibling(hid_dev->parser, 653 NULL, path, USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 654 USB_HID_REPORT_TYPE_INPUT); 655 656 while(field != NULL) { 657 usb_log_debug("FIELD (%p) - VALUE(%d) USAGE(%u)\n", field, field->value, field->usage); 658 field = usb_hid_report_get_sibling(hid_dev->parser, field, path, 659 USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 660 USB_HID_REPORT_TYPE_INPUT); 661 } 674 int rc = usb_hid_parse_report(hid_dev->report, buffer, actual_size); 675 676 if (rc != EOK) { 677 usb_log_warning("Error in usb_hid_parse_report():" 678 "%s\n", str_error(rc)); 679 } 680 681 // fill in the currently pressed keys 682 683 usb_hid_report_field_t *field = usb_hid_report_get_sibling( 684 hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END 685 | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, USB_HID_REPORT_TYPE_INPUT); 686 unsigned i = 0; 687 688 // TODO: remove this hack - skipping first field 689 field = usb_hid_report_get_sibling(hid_dev->report, field, path, 690 USB_HID_PATH_COMPARE_END 691 | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 692 USB_HID_REPORT_TYPE_INPUT); 693 694 while (field != NULL) { 695 usb_log_debug2("FIELD (%p) - VALUE(%d) USAGE(%u)\n", 696 field, field->value, field->usage); 662 697 698 assert(i < kbd_dev->key_count); 699 // if (i == kbd_dev->key_count) { 700 // break; 701 // } 702 703 // save the key usage 704 kbd_dev->keys[i] = field->usage; 705 usb_log_debug2("Saved %u. key usage %d\n", i, kbd_dev->keys[i]); 706 707 ++i; 708 field = usb_hid_report_get_sibling(hid_dev->report, field, path, 709 USB_HID_PATH_COMPARE_END 710 | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 711 USB_HID_REPORT_TYPE_INPUT); 712 } 663 713 664 714 usb_hid_report_path_free(path); 665 715 666 if (rc != EOK) { 667 usb_log_warning("Error in usb_hid_boot_keyboard_input_report():" 668 "%s\n", str_error(rc)); 669 } 716 usb_kbd_check_key_changes(hid_dev, kbd_dev); 670 717 } 671 718 … … 755 802 756 803 kbd_dev->key_count = usb_hid_report_input_length( 757 hid_dev-> parser, path,804 hid_dev->report, path, 758 805 USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY); 759 806 usb_hid_report_path_free(path); … … 761 808 usb_log_debug("Size of the input report: %zu\n", kbd_dev->key_count); 762 809 763 kbd_dev->keys = ( uint8_t *)calloc(kbd_dev->key_count, sizeof(uint8_t));810 kbd_dev->keys = (int32_t *)calloc(kbd_dev->key_count, sizeof(int32_t)); 764 811 765 812 if (kbd_dev->keys == NULL) { … … 769 816 } 770 817 818 kbd_dev->keys_old = 819 (int32_t *)calloc(kbd_dev->key_count, sizeof(int32_t)); 820 821 if (kbd_dev->keys_old == NULL) { 822 usb_log_fatal("No memory!\n"); 823 free(kbd_dev->keys); 824 free(kbd_dev); 825 return ENOMEM; 826 } 827 771 828 /* 772 829 * Output report 773 830 */ 774 831 kbd_dev->output_size = 0; 775 kbd_dev->output_buffer = usb_hid_report_output(hid_dev-> parser,776 &kbd_dev->output_size, 0 x00);832 kbd_dev->output_buffer = usb_hid_report_output(hid_dev->report, 833 &kbd_dev->output_size, 0); 777 834 if (kbd_dev->output_buffer == NULL) { 778 835 usb_log_warning("Error creating output report buffer.\n"); … … 787 844 kbd_dev->led_path, USB_HIDUT_PAGE_LED, 0); 788 845 789 kbd_dev->led_output_size = usb_hid_report_output_size(hid_dev-> parser,846 kbd_dev->led_output_size = usb_hid_report_output_size(hid_dev->report, 790 847 kbd_dev->led_path, 791 848 USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY); … … 944 1001 int usb_kbd_set_boot_protocol(usb_hid_dev_t *hid_dev) 945 1002 { 946 int rc = usb_hid_parse_report_descriptor(hid_dev-> parser,1003 int rc = usb_hid_parse_report_descriptor(hid_dev->report, 947 1004 USB_KBD_BOOT_REPORT_DESCRIPTOR, 948 1005 USB_KBD_BOOT_REPORT_DESCRIPTOR_SIZE); -
uspace/drv/usbhid/kbd/kbddev.h
r3bcac68 re60436b 65 65 */ 66 66 typedef struct usb_kbd_t { 67 /** Previously pressed keys (not translated to key codes). */ 68 int32_t *keys_old; 67 69 /** Currently pressed keys (not translated to key codes). */ 68 uint8_t *keys;70 int32_t *keys; 69 71 /** Count of stored keys (i.e. number of keys in the report). */ 70 72 size_t key_count; -
uspace/drv/usbhid/lgtch-ultrax/lgtch-ultrax.c
r3bcac68 re60436b 83 83 usb_hid_report_path_set_report_id(path, 0); 84 84 85 int rc = usb_hid_parse_report(hid_dev-> parser, buffer, buffer_size);85 int rc = usb_hid_parse_report(hid_dev->report, buffer, buffer_size); 86 86 87 usb_hid_report_field_t *field = usb_hid_report_get_sibling(hid_dev-> parser, NULL, path, USB_HID_PATH_COMPARE_END , USB_HID_REPORT_TYPE_INPUT);87 usb_hid_report_field_t *field = usb_hid_report_get_sibling(hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END , USB_HID_REPORT_TYPE_INPUT); 88 88 while(field != NULL) { 89 89 usb_log_debug("KEY VALUE(%X) USAGE(%X)\n", field->value, field->usage); -
uspace/drv/usbhid/mouse/mousedev.c
r3bcac68 re60436b 296 296 int usb_mouse_set_boot_protocol(usb_hid_dev_t *hid_dev) 297 297 { 298 int rc = usb_hid_parse_report_descriptor(hid_dev-> parser,298 int rc = usb_hid_parse_report_descriptor(hid_dev->report, 299 299 USB_MOUSE_BOOT_REPORT_DESCRIPTOR, 300 300 USB_MOUSE_BOOT_REPORT_DESCRIPTOR_SIZE); -
uspace/drv/usbhid/usbhid.c
r3bcac68 re60436b 192 192 } 193 193 194 assert(hid_dev-> parser!= NULL);194 assert(hid_dev->report != NULL); 195 195 196 196 usb_log_debug("Compare flags: %d\n", mapping->compare); 197 size_t size = usb_hid_report_input_length(hid_dev-> parser, usage_path,197 size_t size = usb_hid_report_input_length(hid_dev->report, usage_path, 198 198 mapping->compare); 199 199 usb_log_debug("Size of the input report: %zuB\n", size); … … 341 341 } 342 342 343 hid_dev-> parser= (usb_hid_report_t *)(malloc(sizeof(343 hid_dev->report = (usb_hid_report_t *)(malloc(sizeof( 344 344 usb_hid_report_t))); 345 if (hid_dev-> parser== NULL) {345 if (hid_dev->report == NULL) { 346 346 usb_log_fatal("No memory!\n"); 347 347 free(hid_dev); … … 385 385 /* Get the report descriptor and parse it. */ 386 386 rc = usb_hid_process_report_descriptor(hid_dev->usb_dev, 387 hid_dev-> parser);387 hid_dev->report); 388 388 389 389 bool fallback = false; … … 583 583 584 584 // destroy the parser 585 if ((*hid_dev)-> parser!= NULL) {586 usb_hid_free_report((*hid_dev)-> parser);585 if ((*hid_dev)->report != NULL) { 586 usb_hid_free_report((*hid_dev)->report); 587 587 } 588 588 -
uspace/drv/usbhid/usbhid.h
r3bcac68 re60436b 91 91 92 92 /** HID Report parser. */ 93 usb_hid_report_t * parser;93 usb_hid_report_t *report; 94 94 95 95 /** Arbitrary data (e.g. a special structure for handling keyboard). */
Note:
See TracChangeset
for help on using the changeset viewer.