Changeset d900699 in mainline for uspace/drv/usbhid/kbd/kbddev.c
- Timestamp:
- 2011-06-17T16:48:53Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f3a605be
- Parents:
- df8110d3 (diff), 98caf49 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbhid/kbd/kbddev.c
rdf8110d3 rd900699 40 40 41 41 #include <io/keycode.h> 42 #include <ipc/kbd.h> 42 #include <io/console.h> 43 #include <ipc/kbdev.h> 43 44 #include <async.h> 44 45 #include <async_obsolete.h> … … 63 64 #include "kbddev.h" 64 65 65 #include "layout.h"66 66 #include "conv.h" 67 67 #include "kbdrepeat.h" … … 73 73 74 74 /*----------------------------------------------------------------------------*/ 75 /** Default modifiers when the keyboard is initialized. */ 75 76 76 static const unsigned DEFAULT_ACTIVE_MODS = KM_NUM_LOCK; 77 77 … … 101 101 const char *HID_KBD_FUN_NAME = "keyboard"; 102 102 const char *HID_KBD_CLASS_NAME = "keyboard"; 103 104 static void usb_kbd_set_led(usb_hid_dev_t *hid_dev, usb_kbd_t *kbd_dev); 103 105 104 106 /*----------------------------------------------------------------------------*/ … … 154 156 155 157 /*----------------------------------------------------------------------------*/ 156 /* Keyboard layouts */157 /*----------------------------------------------------------------------------*/158 159 #define NUM_LAYOUTS 3160 161 /** Keyboard layout map. */162 static layout_op_t *layout[NUM_LAYOUTS] = {163 &us_qwerty_op,164 &us_dvorak_op,165 &cz_op166 };167 168 static int active_layout = 0;169 170 /*----------------------------------------------------------------------------*/171 158 /* IPC method handler */ 172 159 /*----------------------------------------------------------------------------*/ … … 174 161 static void default_connection_handler(ddf_fun_t *, ipc_callid_t, ipc_call_t *); 175 162 176 /** 163 /** 177 164 * Default handler for IPC methods not handled by DDF. 178 165 * … … 189 176 { 190 177 sysarg_t method = IPC_GET_IMETHOD(*icall); 178 int callback; 191 179 192 180 usb_kbd_t *kbd_dev = (usb_kbd_t *)fun->driver_data; … … 198 186 } 199 187 200 if (method == IPC_M_CONNECT_TO_ME) { 201 int callback = IPC_GET_ARG5(*icall); 188 switch (method) { 189 case IPC_M_CONNECT_TO_ME: 190 callback = IPC_GET_ARG5(*icall); 202 191 203 192 if (kbd_dev->console_phone != -1) { … … 212 201 usb_log_debug("default_connection_handler: OK\n"); 213 202 async_answer_0(icallid, EOK); 214 return; 215 } 216 217 usb_log_debug("default_connection_handler: Wrong function.\n"); 218 async_answer_0(icallid, EINVAL); 203 break; 204 case KBDEV_SET_IND: 205 kbd_dev->mods = IPC_GET_ARG1(*icall); 206 usb_kbd_set_led(kbd_dev->hid_dev, kbd_dev); 207 async_answer_0(icallid, EOK); 208 break; 209 default: 210 usb_log_debug("default_connection_handler: Wrong function.\n"); 211 async_answer_0(icallid, EINVAL); 212 break; 213 } 219 214 } 220 215 … … 225 220 * Handles turning of LED lights on and off. 226 221 * 227 * In case of USB keyboards, the LEDs are handled in the driver, not in the 228 * device. When there should be a change (lock key was pressed), the driver 229 * uses a Set_Report request sent to the device to set the state of the LEDs. 222 * As with most other keyboards, the LED indicators in USB keyboards are 223 * driven by software. When state of some modifier changes, the input server 224 * will call us and tell us to update the LED state and what the new state 225 * should be. 230 226 * 231 227 * This functions sets the LED lights according to current settings of modifiers … … 249 245 USB_HID_REPORT_TYPE_OUTPUT); 250 246 251 while (field != NULL) { 247 while (field != NULL) { 252 248 253 249 if ((field->usage == USB_HID_LED_NUM_LOCK) … … 292 288 293 289 /*----------------------------------------------------------------------------*/ 294 /** 295 * Processes key events. 296 * 297 * @note This function was copied from AT keyboard driver and modified to suit 298 * USB keyboard. 299 * 300 * @note Lock keys are not sent to the console, as they are completely handled 301 * in the driver. It may, however, be required later that the driver 302 * sends also these keys to application (otherwise it cannot use those 303 * keys at all). 304 * 290 /** Send key event. 291 * 305 292 * @param kbd_dev Keyboard device structure. 306 * @param type Type of the event (press / release). Recognized values: 293 * @param type Type of the event (press / release). Recognized values: 307 294 * KEY_PRESS, KEY_RELEASE 308 * @param key Key code of the key according to HID Usage Tables.295 * @param key Key code 309 296 */ 310 297 void usb_kbd_push_ev(usb_hid_dev_t *hid_dev, usb_kbd_t *kbd_dev, int type, 311 298 unsigned int key) 312 299 { 313 kbd_event_t ev; 314 unsigned mod_mask; 315 316 /* 317 * These parts are copy-pasted from the AT keyboard driver. 318 * 319 * They definitely require some refactoring, but will keep it for later 320 * when the console and keyboard system is changed in HelenOS. 321 */ 322 switch (key) { 323 case KC_LCTRL: mod_mask = KM_LCTRL; break; 324 case KC_RCTRL: mod_mask = KM_RCTRL; break; 325 case KC_LSHIFT: mod_mask = KM_LSHIFT; break; 326 case KC_RSHIFT: mod_mask = KM_RSHIFT; break; 327 case KC_LALT: mod_mask = KM_LALT; break; 328 case KC_RALT: mod_mask = KM_RALT; break; 329 default: mod_mask = 0; break; 330 } 331 332 if (mod_mask != 0) { 333 if (type == KEY_PRESS) 334 kbd_dev->mods = kbd_dev->mods | mod_mask; 335 else 336 kbd_dev->mods = kbd_dev->mods & ~mod_mask; 337 } 338 339 switch (key) { 340 case KC_CAPS_LOCK: mod_mask = KM_CAPS_LOCK; break; 341 case KC_NUM_LOCK: mod_mask = KM_NUM_LOCK; break; 342 case KC_SCROLL_LOCK: mod_mask = KM_SCROLL_LOCK; break; 343 default: mod_mask = 0; break; 344 } 345 346 if (mod_mask != 0) { 347 if (type == KEY_PRESS) { 348 /* 349 * Only change lock state on transition from released 350 * to pressed. This prevents autorepeat from messing 351 * up the lock state. 352 */ 353 unsigned int locks_old = kbd_dev->lock_keys; 354 355 kbd_dev->mods = 356 kbd_dev->mods ^ (mod_mask & ~kbd_dev->lock_keys); 357 kbd_dev->lock_keys = kbd_dev->lock_keys | mod_mask; 358 359 /* Update keyboard lock indicator lights. */ 360 if (kbd_dev->lock_keys != locks_old 361 && hid_dev != NULL) { // ugly hack 362 usb_kbd_set_led(hid_dev, kbd_dev); 363 } 364 } else { 365 kbd_dev->lock_keys = kbd_dev->lock_keys & ~mod_mask; 366 } 367 } 368 369 if (key == KC_CAPS_LOCK || key == KC_NUM_LOCK || key == KC_SCROLL_LOCK) { 370 // do not send anything to the console, this is our business 371 return; 372 } 373 374 if (type == KEY_PRESS && (kbd_dev->mods & KM_LCTRL) && key == KC_F1) { 375 active_layout = 0; 376 layout[active_layout]->reset(); 377 return; 378 } 379 380 if (type == KEY_PRESS && (kbd_dev->mods & KM_LCTRL) && key == KC_F2) { 381 active_layout = 1; 382 layout[active_layout]->reset(); 383 return; 384 } 385 386 if (type == KEY_PRESS && (kbd_dev->mods & KM_LCTRL) && key == KC_F3) { 387 active_layout = 2; 388 layout[active_layout]->reset(); 389 return; 390 } 391 392 ev.type = type; 393 ev.key = key; 394 ev.mods = kbd_dev->mods; 395 396 ev.c = layout[active_layout]->parse_ev(&ev); 397 398 usb_log_debug2("Sending key %d to the console\n", ev.key); 300 usb_log_debug2("Sending kbdev event %d/%d to the console\n", type, key); 399 301 if (kbd_dev->console_phone < 0) { 400 302 usb_log_warning( … … 403 305 } 404 306 405 async_obsolete_msg_4(kbd_dev->console_phone, KBD_EVENT, ev.type, ev.key, 406 ev.mods, ev.c); 307 async_obsolete_msg_2(kbd_dev->console_phone, KBDEV_EVENT, type, key); 407 308 } 408 309 … … 716 617 return ENOMEM; // TODO: some other code?? 717 618 } 619 620 /* Store link to HID device */ 621 kbd_dev->hid_dev = hid_dev; 718 622 719 623 /* … … 787 691 /* 788 692 * Modifiers and locks 789 */ 693 */ 790 694 kbd_dev->modifiers = 0; 791 695 kbd_dev->mods = DEFAULT_ACTIVE_MODS; … … 794 698 /* 795 699 * Autorepeat 796 */ 700 */ 797 701 kbd_dev->repeat.key_new = 0; 798 702 kbd_dev->repeat.key_repeated = 0;
Note:
See TracChangeset
for help on using the changeset viewer.