Changes in / [a465a56:467bf40] in mainline
- Location:
- uspace
- Files:
-
- 2 added
- 3 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbkbd/main.c
ra465a56 r467bf40 29 29 #include <driver.h> 30 30 #include <ipc/driver.h> 31 #include <ipc/kbd.h>32 #include <io/keycode.h>33 #include <io/console.h>34 31 #include <errno.h> 35 32 #include <fibril.h> … … 44 41 #define GUESSED_POLL_ENDPOINT 1 45 42 46 static void default_connection_handler(device_t *, ipc_callid_t, ipc_call_t *);47 static device_ops_t keyboard_ops = {48 .default_handler = default_connection_handler49 };50 51 static int console_callback_phone = -1;52 53 /** Default handler for IPC methods not handled by DDF.54 *55 * @param dev Device handling the call.56 * @param icallid Call id.57 * @param icall Call data.58 */59 void default_connection_handler(device_t *dev,60 ipc_callid_t icallid, ipc_call_t *icall)61 {62 sysarg_t method = IPC_GET_IMETHOD(*icall);63 64 if (method == IPC_M_CONNECT_TO_ME) {65 int callback = IPC_GET_ARG5(*icall);66 67 if (console_callback_phone != -1) {68 ipc_answer_0(icallid, ELIMIT);69 return;70 }71 72 console_callback_phone = callback;73 ipc_answer_0(icallid, EOK);74 return;75 }76 77 ipc_answer_0(icallid, EINVAL);78 }79 80 static void send_key(int key, int type, wchar_t c) {81 async_msg_4(console_callback_phone, KBD_EVENT, type, key,82 KM_NUM_LOCK, c);83 }84 85 static void send_alnum(int key, wchar_t c) {86 printf(NAME ": sending key '%lc' to console\n", c);87 send_key(key, KEY_PRESS, c);88 send_key(key, KEY_RELEASE, c);89 }90 91 43 /* 92 44 * Callbacks for parser … … 231 183 sizeof(usb_hid_report_in_callbacks_t)); 232 184 callbacks->keyboard = usbkbd_process_keycodes; 233 234 if (console_callback_phone != -1) {235 static size_t counter = 0;236 counter++;237 if (counter > 3) {238 counter = 0;239 send_alnum(KC_A, L'a');240 }241 }242 185 243 186 usb_hid_parse_report(kbd_dev->parser, buffer, actual_size, callbacks, … … 346 289 fibril_add_ready(fid); 347 290 348 dev->ops = &keyboard_ops;349 350 add_device_to_class(dev, "keyboard");351 352 291 /* 353 292 * Hurrah, device is initialized. -
uspace/drv/vhc/hcd.c
ra465a56 r467bf40 72 72 73 73 /* 74 * Initialize address management. 75 */ 76 address_init(); 77 78 /* 74 79 * Initialize our hub and announce its presence. 75 80 */ … … 103 108 printf(NAME ": virtual USB host controller driver.\n"); 104 109 105 /*106 * Initialize address management.107 */108 address_init();109 110 /*111 * Run the transfer scheduler.112 */113 110 hc_manager(); 114 111 115 /*116 * We are also a driver within devman framework.117 */118 112 return driver_main(&vhc_driver); 119 113 } -
uspace/lib/c/include/ipc/kbd.h
ra465a56 r467bf40 39 39 40 40 #include <ipc/ipc.h> 41 #include <ipc/dev_iface.h>42 41 43 42 typedef enum { 44 KBD_YIELD = DEV_FIRST_CUSTOM_METHOD,43 KBD_YIELD = IPC_FIRST_USER_METHOD, 45 44 KBD_RECLAIM 46 45 } kbd_request_t; -
uspace/srv/hid/console/console.c
ra465a56 r467bf40 317 317 static void change_console(console_t *cons) 318 318 { 319 if (cons == active_console) {319 if (cons == active_console) 320 320 return; 321 }322 321 323 322 fb_pending_flush(); … … 459 458 if (IPC_GET_ARG1(call) == 1) { 460 459 int newcon = gcons_mouse_btn((bool) IPC_GET_ARG2(call)); 461 if (newcon != -1) {460 if (newcon != -1) 462 461 change_console(&consoles[newcon]); 463 }464 462 } 465 463 retval = 0; … … 712 710 } 713 711 714 static int connect_keyboard(char *path) 715 { 716 int fd = open(path, O_RDONLY); 717 if (fd < 0) { 718 return fd; 719 } 720 721 int phone = fd_phone(fd); 722 if (phone < 0) { 712 static bool console_init(char *input) 713 { 714 /* Connect to input device */ 715 int input_fd = open(input, O_RDONLY); 716 if (input_fd < 0) { 717 printf(NAME ": Failed opening %s\n", input); 718 return false; 719 } 720 721 kbd_phone = fd_phone(input_fd); 722 if (kbd_phone < 0) { 723 723 printf(NAME ": Failed to connect to input device\n"); 724 return phone;724 return false; 725 725 } 726 726 727 727 /* NB: The callback connection is slotted for removal */ 728 728 sysarg_t phonehash; 729 int rc = async_req_3_5(phone, IPC_M_CONNECT_TO_ME, SERVICE_CONSOLE, 730 0, 0, NULL, NULL, NULL, NULL, &phonehash); 731 if (rc != EOK) { 729 if (ipc_connect_to_me(kbd_phone, SERVICE_CONSOLE, 0, 0, &phonehash) != 0) { 732 730 printf(NAME ": Failed to create callback from input device\n"); 733 return rc;731 return false; 734 732 } 735 733 736 734 async_new_connection(phonehash, 0, NULL, keyboard_events); 737 738 printf(NAME ": we got a hit (new keyboard \"%s\").\n", path); 739 740 return phone; 741 } 742 743 744 static int check_new_keyboards(void *arg) 745 { 746 char *class_name = (char *) arg; 747 748 int index = 1; 749 750 while (true) { 751 async_usleep(1 * 500 * 1000); 752 char *path; 753 int rc = asprintf(&path, "/dev/class/%s\\%d", class_name, index); 754 if (rc < 0) { 755 continue; 756 } 757 rc = 0; 758 rc = connect_keyboard(path); 759 if (rc > 0) { 760 /* We do not allow unplug. */ 761 index++; 762 } 763 764 free(path); 765 } 766 767 return EOK; 768 } 769 770 771 /** Start a fibril monitoring hot-plugged keyboards. 772 */ 773 static void check_new_keyboards_in_background() 774 { 775 fid_t fid = fibril_create(check_new_keyboards, (void *)"keyboard"); 776 if (!fid) { 777 printf(NAME ": failed to create hot-plug-watch fibril.\n"); 778 return; 779 } 780 fibril_add_ready(fid); 781 } 782 783 static bool console_init(char *input) 784 { 785 /* Connect to input device */ 786 kbd_phone = connect_keyboard(input); 787 if (kbd_phone < 0) { 788 return false; 789 } 790 735 791 736 /* Connect to mouse device */ 792 737 mouse_phone = -1; … … 804 749 } 805 750 806 sysarg_t phonehash;807 751 if (ipc_connect_to_me(mouse_phone, SERVICE_CONSOLE, 0, 0, &phonehash) != 0) { 808 752 printf(NAME ": Failed to create callback from mouse device\n"); … … 897 841 async_set_interrupt_received(interrupt_received); 898 842 899 /* Start fibril for checking on hot-plugged keyboards. */900 check_new_keyboards_in_background();901 902 843 return true; 903 844 } … … 919 860 if (!console_init(argv[1])) 920 861 return -1; 921 862 922 863 printf(NAME ": Accepting connections\n"); 923 864 async_manager();
Note:
See TracChangeset
for help on using the changeset viewer.