Changes in uspace/drv/usbhid/kbddev.c [48d2765:d477734] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbhid/kbddev.c
r48d2765 rd477734 196 196 unsigned mod_mask; 197 197 198 /* 199 * These parts are copy-pasted from the AT keyboard driver. 200 * 201 * They definitely require some refactoring, but will keep it for later 202 * when the console and keyboard system is changed in HelenOS. 203 */ 198 // TODO: replace by our own parsing?? or are the key codes identical?? 204 199 switch (key) { 205 200 case KC_LCTRL: mod_mask = KM_LCTRL; break; … … 333 328 i = 0; 334 329 // all fields should report Error Rollover 335 while (i < kbd_dev->key _count &&330 while (i < kbd_dev->keycode_count && 336 331 key_codes[i] == BOOTP_ERROR_ROLLOVER) { 337 332 ++i; 338 333 } 339 if (i == kbd_dev->key _count) {334 if (i == kbd_dev->keycode_count) { 340 335 usb_log_debug("Phantom state occured.\n"); 341 336 // phantom state, do nothing … … 348 343 * 1) Key releases 349 344 */ 350 for (j = 0; j < kbd_dev->key _count; ++j) {345 for (j = 0; j < kbd_dev->keycode_count; ++j) { 351 346 // try to find the old key in the new key list 352 347 i = 0; 353 while (i < kbd_dev->key _count354 && key_codes[i] != kbd_dev->key s[j]) {348 while (i < kbd_dev->keycode_count 349 && key_codes[i] != kbd_dev->keycodes[j]) { 355 350 ++i; 356 351 } 357 352 358 if (i == kbd_dev->key _count) {353 if (i == kbd_dev->keycode_count) { 359 354 // not found, i.e. the key was released 360 key = usbhid_parse_scancode(kbd_dev->key s[j]);355 key = usbhid_parse_scancode(kbd_dev->keycodes[j]); 361 356 usbhid_kbd_push_ev(kbd_dev, KEY_RELEASE, key); 362 357 usb_log_debug2("Key released: %d\n", key); … … 369 364 * 1) Key presses 370 365 */ 371 for (i = 0; i < kbd_dev->key _count; ++i) {366 for (i = 0; i < kbd_dev->keycode_count; ++i) { 372 367 // try to find the new key in the old key list 373 368 j = 0; 374 while (j < kbd_dev->key _count375 && kbd_dev->key s[j] != key_codes[i]) {369 while (j < kbd_dev->keycode_count 370 && kbd_dev->keycodes[j] != key_codes[i]) { 376 371 ++j; 377 372 } 378 373 379 if (j == kbd_dev->key _count) {374 if (j == kbd_dev->keycode_count) { 380 375 // not found, i.e. new key pressed 381 376 key = usbhid_parse_scancode(key_codes[i]); … … 397 392 // } 398 393 399 memcpy(kbd_dev->key s, key_codes, kbd_dev->key_count);394 memcpy(kbd_dev->keycodes, key_codes, kbd_dev->keycode_count); 400 395 401 396 usb_log_debug("New stored keycodes: %s\n", 402 usb_debug_str_buffer(kbd_dev->key s, kbd_dev->key_count, 0));397 usb_debug_str_buffer(kbd_dev->keycodes, kbd_dev->keycode_count, 0)); 403 398 } 404 399 … … 420 415 421 416 usb_log_debug("Got keys from parser: %s\n", 422 usb_debug_str_buffer(key_codes, kbd_dev->key _count, 0));423 424 if (count != kbd_dev->key _count) {417 usb_debug_str_buffer(key_codes, kbd_dev->keycode_count, 0)); 418 419 if (count != kbd_dev->keycode_count) { 425 420 usb_log_warning("Number of received keycodes (%d) differs from" 426 " expected number (%d).\n", count, kbd_dev->key _count);421 " expected number (%d).\n", count, kbd_dev->keycode_count); 427 422 return; 428 423 } … … 435 430 /* General kbd functions */ 436 431 /*----------------------------------------------------------------------------*/ 437 /** 438 * Processes data received from the device in form of report. 439 * 440 * This function uses the HID report parser to translate the data received from 441 * the device into generic USB HID key codes and into generic modifiers bitmap. 442 * The parser then calls the given callback (usbhid_kbd_process_keycodes()). 443 * 444 * @note Currently, only the boot protocol is supported. 445 * 446 * @param kbd_dev Keyboard device structure (must be initialized). 447 * @param buffer Data from the keyboard (i.e. the report). 448 * @param actual_size Size of the data from keyboard (report size) in bytes. 449 * 450 * @sa usbhid_kbd_process_keycodes(), usb_hid_boot_keyboard_input_report(). 451 */ 432 452 433 static void usbhid_kbd_process_data(usbhid_kbd_t *kbd_dev, 453 434 uint8_t *buffer, size_t actual_size) … … 474 455 /* HID/KBD structure manipulation */ 475 456 /*----------------------------------------------------------------------------*/ 476 /** 477 * Creates a new USB/HID keyboard structure. 478 * 479 * The structure returned by this function is not initialized. Use 480 * usbhid_kbd_init() to initialize it prior to polling. 481 * 482 * @return New uninitialized structure for representing a USB/HID keyboard or 483 * NULL if not successful (memory error). 484 */ 457 485 458 static usbhid_kbd_t *usbhid_kbd_new(void) 486 459 { … … 508 481 509 482 /*----------------------------------------------------------------------------*/ 510 /** 511 * Properly destroys the USB/HID keyboard structure. 512 * 513 * @param kbd_dev Pointer to the structure to be destroyed. 514 */ 483 515 484 static void usbhid_kbd_free(usbhid_kbd_t **kbd_dev) 516 485 { … … 532 501 533 502 /*----------------------------------------------------------------------------*/ 534 /** 535 * Initialization of the USB/HID keyboard structure. 536 * 537 * This functions initializes required structures from the device's descriptors. 538 * 539 * During initialization, the keyboard is switched into boot protocol, the idle 540 * rate is set to 0 (infinity), resulting in the keyboard only reporting event 541 * when a key is pressed or released. Finally, the LED lights are turned on 542 * according to the default setup of lock keys. 543 * 544 * @note By default, the keyboards is initialized with Num Lock turned on and 545 * other locks turned off. 546 * 547 * @param kbd_dev Keyboard device structure to be initialized. 548 * @param dev DDF device structure of the keyboard. 549 * 550 * @retval EOK if successful. 551 * @retval EINVAL if some parameter is not given. 552 * @return Other value inherited from function usbhid_dev_init(). 553 */ 503 554 504 static int usbhid_kbd_init(usbhid_kbd_t *kbd_dev, ddf_dev_t *dev) 555 505 { … … 586 536 587 537 // save the size of the report (boot protocol report by default) 588 kbd_dev->key _count = BOOTP_REPORT_SIZE;589 kbd_dev->key s = (uint8_t *)calloc(590 kbd_dev->key _count, sizeof(uint8_t));591 592 if (kbd_dev->key s == NULL) {538 kbd_dev->keycode_count = BOOTP_REPORT_SIZE; 539 kbd_dev->keycodes = (uint8_t *)calloc( 540 kbd_dev->keycode_count, sizeof(uint8_t)); 541 542 if (kbd_dev->keycodes == NULL) { 593 543 usb_log_fatal("No memory!\n"); 594 return ENOMEM;544 return rc; 595 545 } 596 546 … … 621 571 /* HID/KBD polling */ 622 572 /*----------------------------------------------------------------------------*/ 623 /** 624 * Main keyboard polling function. 625 * 626 * This function uses the Interrupt In pipe of the keyboard to poll for events. 627 * The keyboard is initialized in a way that it reports only when a key is 628 * pressed or released, so there is no actual need for any sleeping between 629 * polls (see usbhid_kbd_try_add_device() or usbhid_kbd_init()). 630 * 631 * @param kbd_dev Initialized keyboard structure representing the device to 632 * poll. 633 * 634 * @sa usbhid_kbd_process_data() 635 */ 573 636 574 static void usbhid_kbd_poll(usbhid_kbd_t *kbd_dev) 637 575 { … … 701 639 702 640 /*----------------------------------------------------------------------------*/ 703 /** 704 * Function executed by the main driver fibril. 705 * 706 * Just starts polling the keyboard for events. 707 * 708 * @param arg Initialized keyboard device structure (of type usbhid_kbd_t) 709 * representing the device. 710 * 711 * @retval EOK if the fibril finished polling the device. 712 * @retval EINVAL if no device was given in the argument. 713 * 714 * @sa usbhid_kbd_poll() 715 * 716 * @todo Change return value - only case when the fibril finishes is in case 717 * of some error, so the error should probably be propagated from function 718 * usbhid_kbd_poll() to here and up. 719 */ 641 720 642 static int usbhid_kbd_fibril(void *arg) 721 643 { … … 739 661 /* API functions */ 740 662 /*----------------------------------------------------------------------------*/ 741 /** 742 * Function for adding a new device of type USB/HID/keyboard. 743 * 744 * This functions initializes required structures from the device's descriptors 745 * and starts a new fibril for polling the keyboard for events. 746 * 747 * During initialization, the keyboard is switched into boot protocol, the idle 748 * rate is set to 0 (infinity), resulting in the keyboard only reporting event 749 * when a key is pressed or released. Finally, the LED lights are turned on 750 * according to the default setup of lock keys. 751 * 752 * @note By default, the keyboards is initialized with Num Lock turned on and 753 * other locks turned off. 754 * @note Currently supports only boot-protocol keyboards. 755 * 756 * @param dev Device to add. 757 * 758 * @retval EOK if successful. 759 * @retval ENOMEM if there 760 * @return Other error code inherited from one of functions usbhid_kbd_init(), 761 * ddf_fun_bind() and ddf_fun_add_to_class(). 762 * 763 * @sa usbhid_kbd_fibril() 764 */ 663 765 664 int usbhid_kbd_try_add_device(ddf_dev_t *dev) 766 665 { … … 784 683 "structure.\n"); 785 684 ddf_fun_destroy(kbd_fun); 786 return E NOMEM; // TODO: some other code??685 return EINVAL; // TODO: some other code?? 787 686 } 788 687
Note:
See TracChangeset
for help on using the changeset viewer.