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