Changes in uspace/srv/hid/input/generic/input.c [1875a0c:b72efe8] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/input/generic/input.c
r1875a0c rb72efe8 58 58 #include <kbd_port.h> 59 59 #include <kbd_ctl.h> 60 #include <mouse_proto.h>61 60 #include <layout.h> 62 61 #include <mouse.h> … … 66 65 67 66 /* In microseconds */ 68 #define DISCOVERY_POLL_INTERVAL (10 * 1000 * 1000) 69 70 #define NUM_LAYOUTS 3 67 #define DISCOVERY_POLL_INTERVAL (10*1000*1000) 68 69 static void kbd_devs_yield(void); 70 static void kbd_devs_reclaim(void); 71 72 static void input_event_key(int, unsigned int, unsigned, wchar_t); 73 74 int client_phone = -1; 75 76 /** List of keyboard devices */ 77 static list_t kbd_devs; 78 79 /** List of mouse devices */ 80 list_t mouse_devs; 81 82 bool irc_service = false; 83 int irc_phone = -1; 84 85 #define NUM_LAYOUTS 3 71 86 72 87 static layout_ops_t *layout[NUM_LAYOUTS] = { … … 76 91 }; 77 92 78 static void kbd_devs_yield(void); 79 static void kbd_devs_reclaim(void); 80 81 int client_phone = -1; 82 83 /** List of keyboard devices */ 84 static list_t kbd_devs; 85 86 /** List of mouse devices */ 87 static list_t mouse_devs; 88 89 bool irc_service = false; 90 int irc_phone = -1; 91 92 void kbd_push_data(kbd_dev_t *kdev, sysarg_t data) 93 { 94 (*kdev->ctl_ops->parse)(data); 95 } 96 97 void mouse_push_data(mouse_dev_t *mdev, sysarg_t data) 98 { 99 (*mdev->proto_ops->parse)(data); 100 } 101 102 void kbd_push_event(kbd_dev_t *kdev, int type, unsigned int key) 93 void kbd_push_scancode(kbd_dev_t *kdev, int scancode) 94 { 95 /* printf("scancode: 0x%x\n", scancode);*/ 96 (*kdev->ctl_ops->parse_scancode)(scancode); 97 } 98 99 void kbd_push_ev(kbd_dev_t *kdev, int type, unsigned int key) 103 100 { 104 101 kbd_event_t ev; 105 unsigned intmod_mask;106 102 unsigned mod_mask; 103 107 104 switch (key) { 108 105 case KC_LCTRL: mod_mask = KM_LCTRL; break; … … 114 111 default: mod_mask = 0; break; 115 112 } 116 113 117 114 if (mod_mask != 0) { 118 115 if (type == KEY_PRESS) … … 121 118 kdev->mods = kdev->mods & ~mod_mask; 122 119 } 123 120 124 121 switch (key) { 125 122 case KC_CAPS_LOCK: mod_mask = KM_CAPS_LOCK; break; … … 128 125 default: mod_mask = 0; break; 129 126 } 130 127 131 128 if (mod_mask != 0) { 132 129 if (type == KEY_PRESS) { … … 138 135 kdev->mods = kdev->mods ^ (mod_mask & ~kdev->lock_keys); 139 136 kdev->lock_keys = kdev->lock_keys | mod_mask; 140 137 141 138 /* Update keyboard lock indicator lights. */ 142 139 (*kdev->ctl_ops->set_ind)(kdev, kdev->mods); … … 145 142 } 146 143 } 147 144 /* 145 printf("type: %d\n", type); 146 printf("mods: 0x%x\n", mods); 147 printf("keycode: %u\n", key); 148 */ 148 149 if (type == KEY_PRESS && (kdev->mods & KM_LCTRL) && 149 150 key == KC_F1) { 150 151 layout_destroy(kdev->active_layout); 151 152 kdev->active_layout = layout_create(layout[0]); 152 153 return; 153 154 } 154 155 155 156 if (type == KEY_PRESS && (kdev->mods & KM_LCTRL) && 156 157 key == KC_F2) { 157 158 layout_destroy(kdev->active_layout); 158 159 kdev->active_layout = layout_create(layout[1]); 159 160 return; 160 161 } 161 162 162 163 if (type == KEY_PRESS && (kdev->mods & KM_LCTRL) && 163 164 key == KC_F3) { 164 165 layout_destroy(kdev->active_layout); 165 166 kdev->active_layout = layout_create(layout[2]); 166 167 return; 167 168 } 168 169 169 170 ev.type = type; 170 171 ev.key = key; 171 172 ev.mods = kdev->mods; 172 173 173 174 ev.c = layout_parse_ev(kdev->active_layout, &ev); 174 async_obsolete_msg_4(client_phone, INPUT_EVENT_KEY, ev.type, ev.key, 175 ev.mods, ev.c); 175 input_event_key(ev.type, ev.key, ev.mods, ev.c); 176 } 177 178 /** Key has been pressed or released. */ 179 static void input_event_key(int type, unsigned int key, unsigned mods, 180 wchar_t c) 181 { 182 async_obsolete_msg_4(client_phone, INPUT_EVENT_KEY, type, key, 183 mods, c); 176 184 } 177 185 178 186 /** Mouse pointer has moved. */ 179 void mouse_push_event_move(mouse_dev_t *mdev,int dx, int dy)187 void input_event_move(int dx, int dy) 180 188 { 181 189 async_obsolete_msg_2(client_phone, INPUT_EVENT_MOVE, dx, dy); … … 183 191 184 192 /** Mouse button has been pressed. */ 185 void mouse_push_event_button(mouse_dev_t *mdev,int bnum, int press)193 void input_event_button(int bnum, int press) 186 194 { 187 195 async_obsolete_msg_2(client_phone, INPUT_EVENT_BUTTON, bnum, press); … … 193 201 ipc_call_t call; 194 202 int retval; 195 203 196 204 async_answer_0(iid, EOK); 197 205 198 206 while (true) { 199 207 callid = async_get_call(&call); … … 229 237 retval = EINVAL; 230 238 } 231 232 239 async_answer_0(callid, retval); 233 } 240 } 234 241 } 235 242 236 243 static kbd_dev_t *kbd_dev_new(void) 237 244 { 238 kbd_dev_t *kdev = calloc(1, sizeof(kbd_dev_t)); 245 kbd_dev_t *kdev; 246 247 kdev = calloc(1, sizeof(kbd_dev_t)); 239 248 if (kdev == NULL) { 240 printf( "%s: Error allocating keyboard device. "241 "Out of memory.\n" , NAME);249 printf(NAME ": Error allocating keyboard device. " 250 "Out of memory.\n"); 242 251 return NULL; 243 252 } 244 253 245 254 link_initialize(&kdev->kbd_devs); 246 255 247 256 kdev->mods = KM_NUM_LOCK; 248 257 kdev->lock_keys = 0; 249 258 kdev->active_layout = layout_create(layout[0]); 250 259 251 260 return kdev; 252 }253 254 static mouse_dev_t *mouse_dev_new(void)255 {256 mouse_dev_t *mdev = calloc(1, sizeof(mouse_dev_t));257 if (mdev == NULL) {258 printf("%s: Error allocating keyboard device. "259 "Out of memory.\n", NAME);260 return NULL;261 }262 263 link_initialize(&mdev->mouse_devs);264 265 return mdev;266 261 } 267 262 … … 269 264 static void kbd_add_dev(kbd_port_ops_t *port, kbd_ctl_ops_t *ctl) 270 265 { 271 kbd_dev_t *kdev = kbd_dev_new(); 266 kbd_dev_t *kdev; 267 268 kdev = kbd_dev_new(); 272 269 if (kdev == NULL) 273 270 return; 274 271 275 272 kdev->port_ops = port; 276 273 kdev->ctl_ops = ctl; 277 274 kdev->dev_path = NULL; 278 275 279 276 /* Initialize port driver. */ 280 277 if ((*kdev->port_ops->init)(kdev) != 0) 281 278 goto fail; 282 279 283 280 /* Initialize controller driver. */ 284 281 if ((*kdev->ctl_ops->init)(kdev) != 0) { … … 286 283 goto fail; 287 284 } 288 285 289 286 list_append(&kdev->kbd_devs, &kbd_devs); 290 287 return; 291 292 288 fail: 293 289 free(kdev); 294 290 } 295 291 296 /** Add new legacy mouse device. */297 static void mouse_add_dev(mouse_port_ops_t *port, mouse_proto_ops_t *proto)298 {299 mouse_dev_t *mdev = mouse_dev_new();300 if (mdev == NULL)301 return;302 303 mdev->port_ops = port;304 mdev->proto_ops = proto;305 mdev->dev_path = NULL;306 307 /* Initialize port driver. */308 if ((*mdev->port_ops->init)(mdev) != 0)309 goto fail;310 311 /* Initialize protocol driver. */312 if ((*mdev->proto_ops->init)(mdev) != 0) {313 /* XXX Uninit port */314 goto fail;315 }316 317 list_append(&mdev->mouse_devs, &mouse_devs);318 return;319 320 fail:321 free(mdev);322 }323 324 292 /** Add new kbdev device. 325 293 * 326 * @param dev_path Filesystem path to the device (/dev/class/...) 327 * 294 * @param dev_path Filesystem path to the device (/dev/class/...) 328 295 */ 329 296 static int kbd_add_kbdev(const char *dev_path) 330 297 { 331 kbd_dev_t *kdev = kbd_dev_new(); 298 kbd_dev_t *kdev; 299 300 kdev = kbd_dev_new(); 332 301 if (kdev == NULL) 333 302 return -1; 334 303 335 304 kdev->dev_path = dev_path; 336 305 kdev->port_ops = NULL; 337 306 kdev->ctl_ops = &kbdev_ctl; 338 307 339 308 /* Initialize controller driver. */ 340 309 if ((*kdev->ctl_ops->init)(kdev) != 0) { 341 310 goto fail; 342 311 } 343 312 344 313 list_append(&kdev->kbd_devs, &kbd_devs); 345 314 return EOK; 346 347 315 fail: 348 316 free(kdev); 349 return -1;350 }351 352 /** Add new mousedev device.353 *354 * @param dev_path Filesystem path to the device (/dev/class/...)355 *356 */357 static int mouse_add_mousedev(const char *dev_path)358 {359 mouse_dev_t *mdev = mouse_dev_new();360 if (mdev == NULL)361 return -1;362 363 mdev->dev_path = dev_path;364 mdev->port_ops = NULL;365 mdev->proto_ops = &mousedev_proto;366 367 /* Initialize controller driver. */368 if ((*mdev->proto_ops->init)(mdev) != 0) {369 goto fail;370 }371 372 list_append(&mdev->mouse_devs, &mouse_devs);373 return EOK;374 375 fail:376 free(mdev);377 317 return -1; 378 318 } … … 435 375 } 436 376 437 /** Add legacy drivers/devices. */438 static void mouse_add_legacy_devs(void)439 {440 /*441 * Need to add these drivers based on config unless we can probe442 * them automatically.443 */444 #if defined(UARCH_amd64)445 mouse_add_dev(&chardev_mouse_port, &ps2_proto);446 #endif447 #if defined(UARCH_ia32)448 mouse_add_dev(&chardev_mouse_port, &ps2_proto);449 #endif450 #if defined(MACHINE_i460GX)451 mouse_add_dev(&chardev_mouse_port, &ps2_proto);452 #endif453 #if defined(UARCH_ppc32)454 mouse_add_dev(&adb_mouse_port, &adb_proto);455 #endif456 /* Silence warning on abs32le about mouse_add_dev() being unused */457 (void) mouse_add_dev;458 }459 460 377 static void kbd_devs_yield(void) 461 378 { … … 464 381 kbd_dev_t *kdev = list_get_instance(kdev_link, kbd_dev_t, 465 382 kbd_devs); 466 383 467 384 /* Yield port */ 468 385 if (kdev->port_ops != NULL) … … 477 394 kbd_dev_t *kdev = list_get_instance(kdev_link, kbd_dev_t, 478 395 kbd_devs); 479 396 480 397 /* Reclaim port */ 481 398 if (kdev->port_ops != NULL) … … 488 405 * Looks under /dev/class/keyboard and /dev/class/mouse. 489 406 * 490 * @param arg Ignored 491 * 407 * @param arg Ignored 492 408 */ 493 409 static int dev_discovery_fibril(void *arg) … … 497 413 size_t mouse_id = 1; 498 414 int rc; 499 415 500 416 while (true) { 501 417 async_usleep(DISCOVERY_POLL_INTERVAL); 502 418 503 419 /* 504 420 * Check for new keyboard device … … 507 423 if (rc < 0) 508 424 continue; 509 425 510 426 if (kbd_add_kbdev(dev_path) == EOK) { 511 printf( "%s: Connected keyboard device '%s'\n",512 NAME,dev_path);513 427 printf(NAME ": Connected keyboard device '%s'\n", 428 dev_path); 429 514 430 /* XXX Handle device removal */ 515 431 ++kbd_id; 516 432 } 517 433 518 434 free(dev_path); 519 435 520 436 /* 521 437 * Check for new mouse device … … 524 440 if (rc < 0) 525 441 continue; 526 527 if (mouse_add_ mousedev(dev_path) == EOK) {528 printf( "%s: Connected mouse device '%s'\n",529 NAME,dev_path);530 442 443 if (mouse_add_dev(dev_path) == EOK) { 444 printf(NAME ": Connected mouse device '%s'\n", 445 dev_path); 446 531 447 /* XXX Handle device removal */ 532 448 ++mouse_id; 533 449 } 534 450 535 451 free(dev_path); 536 452 } 537 453 538 454 return EOK; 539 455 } … … 542 458 static void input_start_dev_discovery(void) 543 459 { 544 fid_t fid = fibril_create(dev_discovery_fibril, NULL); 460 fid_t fid; 461 462 fid = fibril_create(dev_discovery_fibril, NULL); 545 463 if (!fid) { 546 printf("%s: Failed to create device discovery fibril.\n", 547 NAME); 464 printf(NAME ": Failed to create device discovery fibril.\n"); 548 465 return; 549 466 } 550 467 551 468 fibril_add_ready(fid); 552 469 } … … 573 490 /* Add legacy keyboard devices. */ 574 491 kbd_add_legacy_devs(); 575 576 /* Add legacy mouse devices. */577 mouse_add_legacy_devs();492 493 /* Add legacy (devmap-style) mouse device. */ 494 (void) mouse_add_dev("/dev/hid_in/mouse"); 578 495 579 496 /* Register driver */ … … 592 509 return -1; 593 510 } 594 511 595 512 /* Start looking for new input devices */ 596 513 input_start_dev_discovery(); 597 598 printf( "%s: Accepting connections\n", NAME);514 515 printf(NAME ": Accepting connections\n"); 599 516 async_manager(); 600 517 601 518 /* Not reached. */ 602 519 return 0;
Note:
See TracChangeset
for help on using the changeset viewer.