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
00037 #include <ipc/adb.h>
00038 #include <async.h>
00039 #include <kbd_port.h>
00040 #include <kbd.h>
00041 #include <vfs/vfs.h>
00042 #include <fcntl.h>
00043 #include <errno.h>
00044
00045 static void kbd_port_events(ipc_callid_t iid, ipc_call_t *icall);
00046 static void adb_kbd_reg0_data(uint16_t data);
00047
00048 static int dev_phone;
00049
00050 #define NAME "kbd"
00051
00052 int kbd_port_init(void)
00053 {
00054 const char *input = "/dev/adb/kbd";
00055 int input_fd;
00056
00057 printf(NAME ": open %s\n", input);
00058
00059 input_fd = open(input, O_RDONLY);
00060 if (input_fd < 0) {
00061 printf(NAME ": Failed opening %s (%d)\n", input, input_fd);
00062 return false;
00063 }
00064
00065 dev_phone = fd_phone(input_fd);
00066 if (dev_phone < 0) {
00067 printf(NAME ": Failed to connect to device\n");
00068 return false;
00069 }
00070
00071
00072 if (async_connect_to_me(dev_phone, 0, 0, 0, kbd_port_events) != 0) {
00073 printf(NAME ": Failed to create callback from device\n");
00074 return false;
00075 }
00076
00077 return 0;
00078 }
00079
00080 void kbd_port_yield(void)
00081 {
00082 }
00083
00084 void kbd_port_reclaim(void)
00085 {
00086 }
00087
00088 void kbd_port_write(uint8_t data)
00089 {
00090
00091 }
00092
00093 static void kbd_port_events(ipc_callid_t iid, ipc_call_t *icall)
00094 {
00095
00096 while (true) {
00097
00098 ipc_call_t call;
00099 ipc_callid_t callid = async_get_call(&call);
00100
00101 int retval;
00102
00103 switch (IPC_GET_IMETHOD(call)) {
00104 case IPC_M_PHONE_HUNGUP:
00105
00106 return;
00107 case ADB_REG_NOTIF:
00108 adb_kbd_reg0_data(IPC_GET_ARG1(call));
00109 break;
00110 default:
00111 retval = ENOENT;
00112 }
00113 async_answer_0(callid, retval);
00114 }
00115 }
00116
00117 static void adb_kbd_reg0_data(uint16_t data)
00118 {
00119 uint8_t b0, b1;
00120
00121 b0 = (data >> 8) & 0xff;
00122 b1 = data & 0xff;
00123
00124 if (b0 != 0xff)
00125 kbd_push_scancode(b0);
00126 if (b1 != 0xff)
00127 kbd_push_scancode(b1);
00128 }
00129