Changes in uspace/drv/usbhid/kbddev.c [dfe53af:e8c1fb0] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbhid/kbddev.c
rdfe53af re8c1fb0 60 60 61 61 /*----------------------------------------------------------------------------*/ 62 62 /** Default modifiers when the keyboard is initialized. */ 63 63 static const unsigned DEFAULT_ACTIVE_MODS = KM_NUM_LOCK; 64 65 /** Boot protocol report size (key part). */ 64 66 static const size_t BOOTP_REPORT_SIZE = 6; 67 68 /** Boot protocol total report size. */ 65 69 static const size_t BOOTP_BUFFER_SIZE = 8; 70 71 /** Boot protocol output report size. */ 66 72 static const size_t BOOTP_BUFFER_OUT_SIZE = 1; 73 74 /** Boot protocol error key code. */ 67 75 static const uint8_t BOOTP_ERROR_ROLLOVER = 1; 76 77 /** Default idle rate for keyboards. */ 68 78 static const uint8_t IDLE_RATE = 0; 79 80 /** Delay before a pressed key starts auto-repeating. */ 69 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. */ 70 84 static const unsigned int DEFAULT_REPEAT_DELAY = 50 * 1000; 71 85 … … 86 100 #define NUM_LAYOUTS 3 87 101 102 /** Keyboard layout map. */ 88 103 static layout_op_t *layout[NUM_LAYOUTS] = { 89 104 &us_qwerty_op, … … 97 112 /* Modifier constants */ 98 113 /*----------------------------------------------------------------------------*/ 99 114 /** Mapping of USB modifier key codes to generic modifier key codes. */ 100 115 static const keycode_t usbhid_modifiers_keycodes[USB_HID_MOD_COUNT] = { 101 116 KC_LCTRL, /* USB_HID_MOD_LCTRL */ … … 118 133 }; 119 134 120 /** Default handler for IPC methods not handled by DDF. 121 * 122 * @param dev Device handling the call. 135 /** 136 * Default handler for IPC methods not handled by DDF. 137 * 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. 123 143 * @param icallid Call id. 124 144 * @param icall Call data. … … 151 171 /* Key processing functions */ 152 172 /*----------------------------------------------------------------------------*/ 153 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 */ 154 185 static void usbhid_kbd_set_led(usbhid_kbd_t *kbd_dev) 155 186 { … … 193 224 194 225 /*----------------------------------------------------------------------------*/ 195 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 */ 196 242 void usbhid_kbd_push_ev(usbhid_kbd_t *kbd_dev, int type, unsigned int key) 197 243 { … … 292 338 293 339 /*----------------------------------------------------------------------------*/ 294 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 */ 295 348 static void usbhid_kbd_check_modifier_changes(usbhid_kbd_t *kbd_dev, 296 349 uint8_t modifiers) … … 328 381 329 382 /*----------------------------------------------------------------------------*/ 330 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 */ 331 398 static void usbhid_kbd_check_key_changes(usbhid_kbd_t *kbd_dev, 332 const uint8_t *key_codes )399 const uint8_t *key_codes, size_t count) 333 400 { 334 401 unsigned int key; … … 340 407 i = 0; 341 408 // all fields should report Error Rollover 342 while (i < kbd_dev->key_count &&409 while (i < count && 343 410 key_codes[i] == BOOTP_ERROR_ROLLOVER) { 344 411 ++i; 345 412 } 346 if (i == kbd_dev->key_count) {413 if (i == count) { 347 414 usb_log_debug("Phantom state occured.\n"); 348 415 // phantom state, do nothing … … 350 417 } 351 418 352 // TODO: quite dummy right now, think of better implementation 419 /* TODO: quite dummy right now, think of better implementation */ 420 assert(count == kbd_dev->key_count); 353 421 354 422 /* 355 423 * 1) Key releases 356 424 */ 357 for (j = 0; j < kbd_dev->key_count; ++j) {425 for (j = 0; j < count; ++j) { 358 426 // try to find the old key in the new key list 359 427 i = 0; … … 363 431 } 364 432 365 if (i == kbd_dev->key_count) {433 if (i == count) { 366 434 // not found, i.e. the key was released 367 435 key = usbhid_parse_scancode(kbd_dev->keys[j]); … … 380 448 // try to find the new key in the old key list 381 449 j = 0; 382 while (j < kbd_dev->key_count 383 && kbd_dev->keys[j] != key_codes[i]) { 450 while (j < count && kbd_dev->keys[j] != key_codes[i]) { 384 451 ++j; 385 452 } 386 453 387 if (j == kbd_dev->key_count) {454 if (j == count) { 388 455 // not found, i.e. new key pressed 389 456 key = usbhid_parse_scancode(key_codes[i]); … … 392 459 usbhid_kbd_push_ev(kbd_dev, KEY_PRESS, key); 393 460 usbhid_kbd_repeat_start(kbd_dev, key); 394 } else { 461 } else {size_t 395 462 // found, nothing happens 396 463 } 397 464 } 398 // // report all currently pressed keys 399 // for (i = 0; i < kbd_dev->keycode_count; ++i) { 400 // if (key_codes[i] != 0) { 401 // key = usbhid_parse_scancode(key_codes[i]); 402 // usb_log_debug2("Key pressed: %d (keycode: %d)\n", key, 403 // key_codes[i]); 404 // usbhid_kbd_push_ev(kbd_dev, KEY_PRESS, key); 405 // } 406 // } 407 408 memcpy(kbd_dev->keys, key_codes, kbd_dev->key_count); 465 466 memcpy(kbd_dev->keys, key_codes, count); 409 467 410 468 usb_log_debug("New stored keycodes: %s\n", … … 415 473 /* Callbacks for parser */ 416 474 /*----------------------------------------------------------------------------*/ 417 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 */ 418 491 static void usbhid_kbd_process_keycodes(const uint8_t *key_codes, size_t count, 419 492 uint8_t modifiers, void *arg) … … 438 511 439 512 usbhid_kbd_check_modifier_changes(kbd_dev, modifiers); 440 usbhid_kbd_check_key_changes(kbd_dev, key_codes );513 usbhid_kbd_check_key_changes(kbd_dev, key_codes, count); 441 514 } 442 515 … … 686 759 usb_log_warning("Failed to start a session: %s.\n", 687 760 str_error(sess_rc)); 688 continue;761 break; 689 762 } 690 763 … … 698 771 usb_log_warning("Error polling the keyboard: %s.\n", 699 772 str_error(rc)); 700 continue;773 break; 701 774 } 702 775 … … 704 777 usb_log_warning("Error closing session: %s.\n", 705 778 str_error(sess_rc)); 706 continue;779 break; 707 780 } 708 781 … … 725 798 //async_usleep(kbd_dev->hid_dev->poll_interval); 726 799 } 727 728 // not reached729 assert(0);730 800 } 731 801 … … 773 843 * 774 844 * This functions initializes required structures from the device's descriptors 775 * and starts a new fibril for polling the keyboard for events. 845 * and starts new fibril for polling the keyboard for events and another one for 846 * handling auto-repeat of keys. 776 847 * 777 848 * During initialization, the keyboard is switched into boot protocol, the idle … … 791 862 * ddf_fun_bind() and ddf_fun_add_to_class(). 792 863 * 793 * @sa usbhid_kbd_fibril() 864 * @sa usbhid_kbd_fibril(), usbhid_kbd_repeat_fibril() 794 865 */ 795 866 int usbhid_kbd_try_add_device(ddf_dev_t *dev)
Note:
See TracChangeset
for help on using the changeset viewer.