Changes in uspace/drv/usbhid/kbddev.c [a8def7d:ac8285d] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbhid/kbddev.c
ra8def7d rac8285d 37 37 #include <errno.h> 38 38 #include <str_error.h> 39 #include < stdio.h>39 #include <fibril.h> 40 40 41 41 #include <io/keycode.h> 42 42 #include <ipc/kbd.h> 43 43 #include <async.h> 44 #include <fibril.h>45 #include <fibril_synch.h>46 44 47 45 #include <usb/usb.h> … … 57 55 #include "layout.h" 58 56 #include "conv.h" 59 #include "kbdrepeat.h" 60 61 /*----------------------------------------------------------------------------*/ 62 /** Default modifiers when the keyboard is initialized. */ 57 58 /*----------------------------------------------------------------------------*/ 59 63 60 static const unsigned DEFAULT_ACTIVE_MODS = KM_NUM_LOCK; 64 65 /** Boot protocol report size (key part). */66 61 static const size_t BOOTP_REPORT_SIZE = 6; 67 68 /** Boot protocol total report size. */69 62 static const size_t BOOTP_BUFFER_SIZE = 8; 70 71 /** Boot protocol output report size. */72 63 static const size_t BOOTP_BUFFER_OUT_SIZE = 1; 73 74 /** Boot protocol error key code. */75 static const uint8_t BOOTP_ERROR_ROLLOVER = 1;76 77 /** Default idle rate for keyboards. */78 static const uint8_t IDLE_RATE = 0;79 80 /** Delay before a pressed key starts auto-repeating. */81 static const unsigned int DEFAULT_DELAY_BEFORE_FIRST_REPEAT = 500 * 1000;82 83 /** Delay between two repeats of a pressed key when auto-repeating. */84 static const unsigned int DEFAULT_REPEAT_DELAY = 50 * 1000;85 64 86 65 /** Keyboard polling endpoint description for boot protocol class. */ … … 100 79 #define NUM_LAYOUTS 3 101 80 102 /** Keyboard layout map. */103 81 static layout_op_t *layout[NUM_LAYOUTS] = { 104 82 &us_qwerty_op, … … 112 90 /* Modifier constants */ 113 91 /*----------------------------------------------------------------------------*/ 114 /** Mapping of USB modifier key codes to generic modifier key codes. */ 92 115 93 static const keycode_t usbhid_modifiers_keycodes[USB_HID_MOD_COUNT] = { 116 94 KC_LCTRL, /* USB_HID_MOD_LCTRL */ … … 133 111 }; 134 112 135 /** 136 * Default handler for IPC methods not handled by DDF. 113 /** Default handler for IPC methods not handled by DDF. 137 114 * 138 * Currently recognizes only one method (IPC_M_CONNECT_TO_ME), in which case it 139 * assumes the caller is the console and thus it stores IPC phone to it for 140 * later use by the driver to notify about key events. 141 * 142 * @param fun Device function handling the call. 115 * @param dev Device handling the call. 143 116 * @param icallid Call id. 144 117 * @param icall Call data. … … 171 144 /* Key processing functions */ 172 145 /*----------------------------------------------------------------------------*/ 173 /** 174 * Handles turning of LED lights on and off. 175 * 176 * In case of USB keyboards, the LEDs are handled in the driver, not in the 177 * device. When there should be a change (lock key was pressed), the driver 178 * uses a Set_Report request sent to the device to set the state of the LEDs. 179 * 180 * This functions sets the LED lights according to current settings of modifiers 181 * kept in the keyboard device structure. 182 * 183 * @param kbd_dev Keyboard device structure. 184 */ 146 185 147 static void usbhid_kbd_set_led(usbhid_kbd_t *kbd_dev) 186 148 { 187 149 uint8_t buffer[BOOTP_BUFFER_OUT_SIZE]; 188 150 int rc= 0; 151 unsigned i; 189 152 190 153 memset(buffer, 0, BOOTP_BUFFER_OUT_SIZE); … … 214 177 } 215 178 216 usb_log_debug("Output report buffer: %s\n", 217 usb_debug_str_buffer(buffer, BOOTP_BUFFER_OUT_SIZE, 0)); 218 179 // TODO: REFACTOR!!! 180 181 usb_log_debug("Output report buffer: "); 182 for (i = 0; i < BOOTP_BUFFER_OUT_SIZE; ++i) { 183 usb_log_debug("0x%x ", buffer[i]); 184 } 185 usb_log_debug("\n"); 186 187 uint16_t value = 0; 188 value |= (USB_HID_REPORT_TYPE_OUTPUT << 8); 189 219 190 assert(kbd_dev->hid_dev != NULL); 220 191 assert(kbd_dev->hid_dev->initialized); 221 usbhid_req_set_report(kbd_dev->hid_dev, USB_HID_REPORT_TYPE_OUTPUT, 222 buffer, BOOTP_BUFFER_OUT_SIZE); 223 } 224 225 /*----------------------------------------------------------------------------*/ 226 /** 227 * Processes key events. 228 * 229 * @note This function was copied from AT keyboard driver and modified to suit 230 * USB keyboard. 231 * 232 * @note Lock keys are not sent to the console, as they are completely handled 233 * in the driver. It may, however, be required later that the driver 234 * sends also these keys to application (otherwise it cannot use those 235 * keys at all). 236 * 237 * @param kbd_dev Keyboard device structure. 238 * @param type Type of the event (press / release). Recognized values: 239 * KEY_PRESS, KEY_RELEASE 240 * @param key Key code of the key according to HID Usage Tables. 241 */ 242 void usbhid_kbd_push_ev(usbhid_kbd_t *kbd_dev, int type, unsigned int key) 192 usbhid_req_set_report(kbd_dev->hid_dev, value, buffer, 193 BOOTP_BUFFER_OUT_SIZE); 194 } 195 196 /*----------------------------------------------------------------------------*/ 197 198 static void usbhid_kbd_push_ev(usbhid_kbd_t *kbd_dev, int type, 199 unsigned int key) 243 200 { 244 201 console_event_t ev; 245 202 unsigned mod_mask; 246 203 247 /* 248 * These parts are copy-pasted from the AT keyboard driver. 249 * 250 * They definitely require some refactoring, but will keep it for later 251 * when the console and keyboard system is changed in HelenOS. 252 */ 204 // TODO: replace by our own parsing?? or are the key codes identical?? 253 205 switch (key) { 254 206 case KC_LCTRL: mod_mask = KM_LCTRL; break; … … 276 228 277 229 if (mod_mask != 0) { 230 usb_log_debug2("\n\nChanging mods and lock keys\n"); 231 usb_log_debug2("\nmods before: 0x%x\n", kbd_dev->mods); 232 usb_log_debug2("\nLock keys before:0x%x\n\n", 233 kbd_dev->lock_keys); 234 278 235 if (type == KEY_PRESS) { 236 usb_log_debug2("\nKey pressed.\n"); 279 237 /* 280 238 * Only change lock state on transition from released … … 282 240 * up the lock state. 283 241 */ 284 unsigned int locks_old = kbd_dev->lock_keys;285 286 242 kbd_dev->mods = 287 243 kbd_dev->mods ^ (mod_mask & ~kbd_dev->lock_keys); … … 289 245 290 246 /* Update keyboard lock indicator lights. */ 291 if (kbd_dev->lock_keys != locks_old) { 292 usbhid_kbd_set_led(kbd_dev); 293 } 247 usbhid_kbd_set_led(kbd_dev); 294 248 } else { 249 usb_log_debug2("\nKey released.\n"); 295 250 kbd_dev->lock_keys = kbd_dev->lock_keys & ~mod_mask; 296 251 } 297 252 } 298 253 254 usb_log_debug2("\n\nmods after: 0x%x\n", kbd_dev->mods); 255 usb_log_debug2("\nLock keys after: 0x%x\n\n", kbd_dev->lock_keys); 256 299 257 if (key == KC_CAPS_LOCK || key == KC_NUM_LOCK || key == KC_SCROLL_LOCK) { 300 258 // do not send anything to the console, this is our business … … 323 281 ev.key = key; 324 282 ev.mods = kbd_dev->mods; 283 284 if (ev.mods & KM_NUM_LOCK) { 285 usb_log_debug("\n\nNum Lock turned on.\n\n"); 286 } 325 287 326 288 ev.c = layout[active_layout]->parse_ev(&ev); 327 289 328 290 usb_log_debug2("Sending key %d to the console\n", ev.key); 329 if (kbd_dev->console_phone < 0) { 330 usb_log_warning( 331 "Connection to console not ready, key discarded.\n"); 332 return; 333 } 291 assert(kbd_dev->console_phone != -1); 334 292 335 293 async_msg_4(kbd_dev->console_phone, KBD_EVENT, ev.type, ev.key, … … 338 296 339 297 /*----------------------------------------------------------------------------*/ 340 /** 341 * Checks if modifiers were pressed or released and generates key events. 342 * 343 * @param kbd_dev Keyboard device structure. 344 * @param modifiers Bitmap of modifiers. 345 * 346 * @sa usbhid_kbd_push_ev() 347 */ 298 348 299 static void usbhid_kbd_check_modifier_changes(usbhid_kbd_t *kbd_dev, 349 300 uint8_t modifiers) … … 381 332 382 333 /*----------------------------------------------------------------------------*/ 383 /** 384 * Checks if some keys were pressed or released and generates key events. 385 * 386 * An event is created only when key is pressed or released. Besides handling 387 * the events (usbhid_kbd_push_ev()), the auto-repeat fibril is notified about 388 * key presses and releases (see usbhid_kbd_repeat_start() and 389 * usbhid_kbd_repeat_stop()). 390 * 391 * @param kbd_dev Keyboard device structure. 392 * @param key_codes Parsed keyboard report - codes of currently pressed keys 393 * according to HID Usage Tables. 394 * @param count Number of key codes in report (size of the report). 395 * 396 * @sa usbhid_kbd_push_ev(), usbhid_kbd_repeat_start(), usbhid_kbd_repeat_stop() 397 */ 334 398 335 static void usbhid_kbd_check_key_changes(usbhid_kbd_t *kbd_dev, 399 const uint8_t *key_codes, size_t count) 400 { 336 const uint8_t *key_codes) 337 { 338 // TODO: phantom state!! 339 401 340 unsigned int key; 402 341 unsigned int i, j; 403 342 404 /* 405 * First of all, check if the kbd have reported phantom state. 406 */ 407 i = 0; 408 // all fields should report Error Rollover 409 while (i < count && 410 key_codes[i] == BOOTP_ERROR_ROLLOVER) { 411 ++i; 412 } 413 if (i == count) { 414 usb_log_debug("Phantom state occured.\n"); 415 // phantom state, do nothing 416 return; 417 } 418 419 /* TODO: quite dummy right now, think of better implementation */ 420 assert(count == kbd_dev->key_count); 343 // TODO: quite dummy right now, think of better implementation 421 344 422 345 /* 423 346 * 1) Key releases 424 347 */ 425 for (j = 0; j < count; ++j) {348 for (j = 0; j < kbd_dev->keycode_count; ++j) { 426 349 // try to find the old key in the new key list 427 350 i = 0; 428 while (i < kbd_dev->key _count429 && key_codes[i] != kbd_dev->key s[j]) {351 while (i < kbd_dev->keycode_count 352 && key_codes[i] != kbd_dev->keycodes[j]) { 430 353 ++i; 431 354 } 432 355 433 if (i == count) {356 if (i == kbd_dev->keycode_count) { 434 357 // not found, i.e. the key was released 435 key = usbhid_parse_scancode(kbd_dev->keys[j]); 436 usbhid_kbd_repeat_stop(kbd_dev, key); 358 key = usbhid_parse_scancode(kbd_dev->keycodes[j]); 437 359 usbhid_kbd_push_ev(kbd_dev, KEY_RELEASE, key); 438 usb_log_debug2(" Key released: %d\n", key);360 usb_log_debug2("\nKey released: %d\n", key); 439 361 } else { 440 362 // found, nothing happens … … 445 367 * 1) Key presses 446 368 */ 447 for (i = 0; i < kbd_dev->key _count; ++i) {369 for (i = 0; i < kbd_dev->keycode_count; ++i) { 448 370 // try to find the new key in the old key list 449 371 j = 0; 450 while (j < count && kbd_dev->keys[j] != key_codes[i]) { 372 while (j < kbd_dev->keycode_count 373 && kbd_dev->keycodes[j] != key_codes[i]) { 451 374 ++j; 452 375 } 453 376 454 if (j == count) {377 if (j == kbd_dev->keycode_count) { 455 378 // not found, i.e. new key pressed 456 379 key = usbhid_parse_scancode(key_codes[i]); 457 usb_log_debug2(" Key pressed: %d (keycode: %d)\n", key,380 usb_log_debug2("\nKey pressed: %d (keycode: %d)\n", key, 458 381 key_codes[i]); 459 382 usbhid_kbd_push_ev(kbd_dev, KEY_PRESS, key); 460 usbhid_kbd_repeat_start(kbd_dev, key);461 383 } else { 462 384 // found, nothing happens … … 464 386 } 465 387 466 memcpy(kbd_dev->keys, key_codes, count); 467 468 usb_log_debug("New stored keycodes: %s\n", 469 usb_debug_str_buffer(kbd_dev->keys, kbd_dev->key_count, 0)); 388 memcpy(kbd_dev->keycodes, key_codes, kbd_dev->keycode_count); 389 390 usb_log_debug2("\nNew stored keycodes: "); 391 for (i = 0; i < kbd_dev->keycode_count; ++i) { 392 usb_log_debug2("%d ", kbd_dev->keycodes[i]); 393 } 470 394 } 471 395 … … 473 397 /* Callbacks for parser */ 474 398 /*----------------------------------------------------------------------------*/ 475 /** 476 * Callback function for the HID report parser. 477 * 478 * This function is called by the HID report parser with the parsed report. 479 * The parsed report is used to check if any events occured (key was pressed or 480 * released, modifier was pressed or released). 481 * 482 * @param key_codes Parsed keyboard report - codes of currently pressed keys 483 * according to HID Usage Tables. 484 * @param count Number of key codes in report (size of the report). 485 * @param modifiers Bitmap of modifiers (Ctrl, Alt, Shift, GUI). 486 * @param arg User-specified argument. Expects pointer to the keyboard device 487 * structure representing the keyboard. 488 * 489 * @sa usbhid_kbd_check_key_changes(), usbhid_kbd_check_modifier_changes() 490 */ 399 491 400 static void usbhid_kbd_process_keycodes(const uint8_t *key_codes, size_t count, 492 401 uint8_t modifiers, void *arg) … … 497 406 return; 498 407 } 408 409 usb_log_debug2("Got keys from parser: "); 410 unsigned i; 411 for (i = 0; i < count; ++i) { 412 usb_log_debug2("%d ", key_codes[i]); 413 } 414 usb_log_debug2("\n"); 499 415 500 416 usbhid_kbd_t *kbd_dev = (usbhid_kbd_t *)arg; 501 417 assert(kbd_dev != NULL); 502 503 usb_log_debug("Got keys from parser: %s\n", 504 usb_debug_str_buffer(key_codes, count, 0)); 505 506 if (count != kbd_dev->key_count) { 418 419 if (count != kbd_dev->keycode_count) { 507 420 usb_log_warning("Number of received keycodes (%d) differs from" 508 " expected number (%d).\n", count, kbd_dev->key _count);421 " expected number (%d).\n", count, kbd_dev->keycode_count); 509 422 return; 510 423 } 511 424 512 425 usbhid_kbd_check_modifier_changes(kbd_dev, modifiers); 513 usbhid_kbd_check_key_changes(kbd_dev, key_codes , count);426 usbhid_kbd_check_key_changes(kbd_dev, key_codes); 514 427 } 515 428 … … 517 430 /* General kbd functions */ 518 431 /*----------------------------------------------------------------------------*/ 519 /** 520 * Processes data received from the device in form of report. 521 * 522 * This function uses the HID report parser to translate the data received from 523 * the device into generic USB HID key codes and into generic modifiers bitmap. 524 * The parser then calls the given callback (usbhid_kbd_process_keycodes()). 525 * 526 * @note Currently, only the boot protocol is supported. 527 * 528 * @param kbd_dev Keyboard device structure (must be initialized). 529 * @param buffer Data from the keyboard (i.e. the report). 530 * @param actual_size Size of the data from keyboard (report size) in bytes. 531 * 532 * @sa usbhid_kbd_process_keycodes(), usb_hid_boot_keyboard_input_report(). 533 */ 432 534 433 static void usbhid_kbd_process_data(usbhid_kbd_t *kbd_dev, 535 434 uint8_t *buffer, size_t actual_size) 536 435 { 537 assert(kbd_dev->initialized);538 assert(kbd_dev->hid_dev->parser != NULL);539 540 436 usb_hid_report_in_callbacks_t *callbacks = 541 437 (usb_hid_report_in_callbacks_t *)malloc( … … 544 440 callbacks->keyboard = usbhid_kbd_process_keycodes; 545 441 546 usb_log_debug("Calling usb_hid_parse_report() with " 547 "buffer %s\n", usb_debug_str_buffer(buffer, actual_size, 0)); 548 549 // int rc = usb_hid_boot_keyboard_input_report(buffer, actual_size, 550 // callbacks, kbd_dev); 551 int rc = usb_hid_parse_report(kbd_dev->hid_dev->parser, buffer, 552 actual_size, callbacks, kbd_dev); 442 //usb_hid_parse_report(kbd_dev->parser, buffer, actual_size, callbacks, 443 // NULL); 444 /*usb_log_debug2("Calling usb_hid_boot_keyboard_input_report() with size" 445 " %zu\n", actual_size);*/ 446 //dump_buffer("bufffer: ", buffer, actual_size); 447 448 int rc = usb_hid_boot_keyboard_input_report(buffer, actual_size, 449 callbacks, kbd_dev); 553 450 554 451 if (rc != EOK) { … … 561 458 /* HID/KBD structure manipulation */ 562 459 /*----------------------------------------------------------------------------*/ 563 /** 564 * Creates a new USB/HID keyboard structure. 565 * 566 * The structure returned by this function is not initialized. Use 567 * usbhid_kbd_init() to initialize it prior to polling. 568 * 569 * @return New uninitialized structure for representing a USB/HID keyboard or 570 * NULL if not successful (memory error). 571 */ 460 572 461 static usbhid_kbd_t *usbhid_kbd_new(void) 573 462 { … … 595 484 596 485 /*----------------------------------------------------------------------------*/ 597 /** 598 * Properly destroys the USB/HID keyboard structure. 599 * 600 * @param kbd_dev Pointer to the structure to be destroyed. 601 */ 486 602 487 static void usbhid_kbd_free(usbhid_kbd_t **kbd_dev) 603 488 { … … 614 499 } 615 500 616 if ((*kbd_dev)->repeat_mtx != NULL) {617 /* TODO: replace by some check and wait */618 assert(!fibril_mutex_is_locked((*kbd_dev)->repeat_mtx));619 free((*kbd_dev)->repeat_mtx);620 }621 622 501 free(*kbd_dev); 623 502 *kbd_dev = NULL; … … 625 504 626 505 /*----------------------------------------------------------------------------*/ 627 /** 628 * Initialization of the USB/HID keyboard structure. 629 * 630 * This functions initializes required structures from the device's descriptors. 631 * 632 * During initialization, the keyboard is switched into boot protocol, the idle 633 * rate is set to 0 (infinity), resulting in the keyboard only reporting event 634 * when a key is pressed or released. Finally, the LED lights are turned on 635 * according to the default setup of lock keys. 636 * 637 * @note By default, the keyboards is initialized with Num Lock turned on and 638 * other locks turned off. 639 * 640 * @param kbd_dev Keyboard device structure to be initialized. 641 * @param dev DDF device structure of the keyboard. 642 * 643 * @retval EOK if successful. 644 * @retval EINVAL if some parameter is not given. 645 * @return Other value inherited from function usbhid_dev_init(). 646 */ 506 647 507 static int usbhid_kbd_init(usbhid_kbd_t *kbd_dev, ddf_dev_t *dev) 648 508 { … … 679 539 680 540 // save the size of the report (boot protocol report by default) 681 kbd_dev->key _count = BOOTP_REPORT_SIZE;682 kbd_dev->key s = (uint8_t *)calloc(683 kbd_dev->key _count, sizeof(uint8_t));684 685 if (kbd_dev->key s == NULL) {541 kbd_dev->keycode_count = BOOTP_REPORT_SIZE; 542 kbd_dev->keycodes = (uint8_t *)calloc( 543 kbd_dev->keycode_count, sizeof(uint8_t)); 544 545 if (kbd_dev->keycodes == NULL) { 686 546 usb_log_fatal("No memory!\n"); 687 return ENOMEM;547 return rc; 688 548 } 689 549 … … 692 552 kbd_dev->lock_keys = 0; 693 553 694 kbd_dev->repeat.key_new = 0;695 kbd_dev->repeat.key_repeated = 0;696 kbd_dev->repeat.delay_before = DEFAULT_DELAY_BEFORE_FIRST_REPEAT;697 kbd_dev->repeat.delay_between = DEFAULT_REPEAT_DELAY;698 699 kbd_dev->repeat_mtx = (fibril_mutex_t *)(700 malloc(sizeof(fibril_mutex_t)));701 if (kbd_dev->repeat_mtx == NULL) {702 usb_log_fatal("No memory!\n");703 free(kbd_dev->keys);704 return ENOMEM;705 }706 707 fibril_mutex_initialize(kbd_dev->repeat_mtx);708 709 554 /* 710 555 * Set boot protocol. 711 556 * Set LEDs according to initial setup. 712 * Set Idle rate713 557 */ 714 558 assert(kbd_dev->hid_dev != NULL); 715 559 assert(kbd_dev->hid_dev->initialized); 716 //usbhid_req_set_protocol(kbd_dev->hid_dev, USB_HID_PROTOCOL_BOOT);560 usbhid_req_set_protocol(kbd_dev->hid_dev, USB_HID_PROTOCOL_BOOT); 717 561 718 562 usbhid_kbd_set_led(kbd_dev); 719 720 usbhid_req_set_idle(kbd_dev->hid_dev, IDLE_RATE);721 563 722 564 kbd_dev->initialized = 1; … … 729 571 /* HID/KBD polling */ 730 572 /*----------------------------------------------------------------------------*/ 731 /** 732 * Main keyboard polling function. 733 * 734 * This function uses the Interrupt In pipe of the keyboard to poll for events. 735 * The keyboard is initialized in a way that it reports only when a key is 736 * pressed or released, so there is no actual need for any sleeping between 737 * polls (see usbhid_kbd_try_add_device() or usbhid_kbd_init()). 738 * 739 * @param kbd_dev Initialized keyboard structure representing the device to 740 * poll. 741 * 742 * @sa usbhid_kbd_process_data() 743 */ 573 744 574 static void usbhid_kbd_poll(usbhid_kbd_t *kbd_dev) 745 575 { … … 759 589 760 590 while (true) { 591 async_usleep(1000 * 10); 592 761 593 sess_rc = usb_endpoint_pipe_start_session( 762 594 &kbd_dev->hid_dev->poll_pipe); … … 764 596 usb_log_warning("Failed to start a session: %s.\n", 765 597 str_error(sess_rc)); 766 break;598 continue; 767 599 } 768 600 … … 776 608 usb_log_warning("Error polling the keyboard: %s.\n", 777 609 str_error(rc)); 778 break;610 continue; 779 611 } 780 612 … … 782 614 usb_log_warning("Error closing session: %s.\n", 783 615 str_error(sess_rc)); 784 break;616 continue; 785 617 } 786 618 … … 799 631 usb_log_debug("Calling usbhid_kbd_process_data()\n"); 800 632 usbhid_kbd_process_data(kbd_dev, buffer, actual_size); 801 802 // disabled for now, no reason to sleep 803 //async_usleep(kbd_dev->hid_dev->poll_interval); 804 } 805 } 806 807 /*----------------------------------------------------------------------------*/ 808 /** 809 * Function executed by the main driver fibril. 810 * 811 * Just starts polling the keyboard for events. 812 * 813 * @param arg Initialized keyboard device structure (of type usbhid_kbd_t) 814 * representing the device. 815 * 816 * @retval EOK if the fibril finished polling the device. 817 * @retval EINVAL if no device was given in the argument. 818 * 819 * @sa usbhid_kbd_poll() 820 * 821 * @todo Change return value - only case when the fibril finishes is in case 822 * of some error, so the error should probably be propagated from function 823 * usbhid_kbd_poll() to here and up. 824 */ 633 } 634 635 // not reached 636 assert(0); 637 } 638 639 /*----------------------------------------------------------------------------*/ 640 825 641 static int usbhid_kbd_fibril(void *arg) 826 642 { … … 844 660 /* API functions */ 845 661 /*----------------------------------------------------------------------------*/ 846 /** 847 * Function for adding a new device of type USB/HID/keyboard. 848 * 849 * This functions initializes required structures from the device's descriptors 850 * and starts new fibril for polling the keyboard for events and another one for 851 * handling auto-repeat of keys. 852 * 853 * During initialization, the keyboard is switched into boot protocol, the idle 854 * rate is set to 0 (infinity), resulting in the keyboard only reporting event 855 * when a key is pressed or released. Finally, the LED lights are turned on 856 * according to the default setup of lock keys. 857 * 858 * @note By default, the keyboards is initialized with Num Lock turned on and 859 * other locks turned off. 860 * @note Currently supports only boot-protocol keyboards. 861 * 862 * @param dev Device to add. 863 * 864 * @retval EOK if successful. 865 * @retval ENOMEM if there 866 * @return Other error code inherited from one of functions usbhid_kbd_init(), 867 * ddf_fun_bind() and ddf_fun_add_to_class(). 868 * 869 * @sa usbhid_kbd_fibril(), usbhid_kbd_repeat_fibril() 870 */ 662 871 663 int usbhid_kbd_try_add_device(ddf_dev_t *dev) 872 664 { … … 890 682 "structure.\n"); 891 683 ddf_fun_destroy(kbd_fun); 892 return E NOMEM; // TODO: some other code??684 return EINVAL; // TODO: some other code?? 893 685 } 894 686 … … 939 731 } 940 732 fibril_add_ready(fid); 941 942 /*943 * Create new fibril for auto-repeat944 */945 fid = fibril_create(usbhid_kbd_repeat_fibril, kbd_dev);946 if (fid == 0) {947 usb_log_error("Failed to start fibril for KBD auto-repeat");948 return ENOMEM;949 }950 fibril_add_ready(fid);951 733 952 734 (void)keyboard_ops;
Note:
See TracChangeset
for help on using the changeset viewer.