adb.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2010 Jiri Svoboda
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * - Redistributions of source code must retain the above copyright
00010  *   notice, this list of conditions and the following disclaimer.
00011  * - Redistributions in binary form must reproduce the above copyright
00012  *   notice, this list of conditions and the following disclaimer in the
00013  *   documentation and/or other materials provided with the distribution.
00014  * - The name of the author may not be used to endorse or promote products
00015  *   derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00019  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00020  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00022  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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         /* NB: The callback connection is slotted for removal */
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         /*async_msg_1(dev_phone, CHAR_WRITE_BYTE, data);*/
00091 }
00092 
00093 static void kbd_port_events(ipc_callid_t iid, ipc_call_t *icall)
00094 {
00095         /* Ignore parameters, the connection is already opened */
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                         /* TODO: Handle hangup */
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 

Generated on Thu Jun 2 07:45:50 2011 for HelenOS/USB by  doxygen 1.4.7