00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00036 #include <ipc/char.h>
00037 #include <async.h>
00038 #include <vfs/vfs.h>
00039 #include <fcntl.h>
00040 #include <errno.h>
00041
00042 #include <char_mouse.h>
00043 #include <mouse_port.h>
00044
00045 static void chardev_events(ipc_callid_t iid, ipc_call_t *icall);
00046
00047 static int dev_phone;
00048
00049 #define NAME "char_mouse"
00050
00051 int mouse_port_init(void)
00052 {
00053 const char *input = "/dev/char/ps2b";
00054 int input_fd;
00055
00056 printf(NAME ": open %s\n", input);
00057
00058 input_fd = open(input, O_RDONLY);
00059 if (input_fd < 0) {
00060 printf(NAME ": Failed opening %s (%d)\n", input, input_fd);
00061 return false;
00062 }
00063
00064 dev_phone = fd_phone(input_fd);
00065 if (dev_phone < 0) {
00066 printf(NAME ": Failed to connect to device\n");
00067 return false;
00068 }
00069
00070
00071 if (async_connect_to_me(dev_phone, 0, 0, 0, chardev_events) != 0) {
00072 printf(NAME ": Failed to create callback from device\n");
00073 return false;
00074 }
00075
00076 return 0;
00077 }
00078
00079 void mouse_port_yield(void)
00080 {
00081 }
00082
00083 void mouse_port_reclaim(void)
00084 {
00085 }
00086
00087 void mouse_port_write(uint8_t data)
00088 {
00089 async_msg_1(dev_phone, CHAR_WRITE_BYTE, data);
00090 }
00091
00092 static void chardev_events(ipc_callid_t iid, ipc_call_t *icall)
00093 {
00094
00095 while (true) {
00096
00097 ipc_call_t call;
00098 ipc_callid_t callid = async_get_call(&call);
00099
00100 int retval;
00101
00102 switch (IPC_GET_IMETHOD(call)) {
00103 case IPC_M_PHONE_HUNGUP:
00104
00105 return;
00106 case IPC_FIRST_USER_METHOD:
00107 mouse_handle_byte(IPC_GET_ARG1(call));
00108 break;
00109 default:
00110 retval = ENOENT;
00111 }
00112 async_answer_0(callid, retval);
00113 }
00114 }
00115