Changeset e4f8c77 in mainline for uspace/srv/hid/input/port/chardev_mouse.c
- Timestamp:
- 2011-07-13T22:39:18Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- e6910c8
- Parents:
- 5974661 (diff), 8ecef91 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/input/port/chardev_mouse.c
r5974661 re4f8c77 1 1 /* 2 * Copyright (c) 201 0 Jiri Svoboda2 * Copyright (c) 2011 Martin Decky 3 3 * All rights reserved. 4 4 * … … 27 27 */ 28 28 29 /** @addtogroup mouse 29 /** @addtogroup mouse_port 30 * @ingroup mouse 30 31 * @{ 31 */ 32 */ 32 33 /** @file 33 * @brief 34 * @brief Chardev mouse port driver. 34 35 */ 35 36 36 #include <ipc/adb.h> 37 #include <ipc/char.h> 38 #include <stdio.h> 37 39 #include <async.h> 38 #include <vfs/vfs.h>39 #include <fcntl.h>40 40 #include <errno.h> 41 41 #include <devmap.h> 42 #include <devmap_obsolete.h> 43 #include <async.h> 44 #include <async_obsolete.h> 45 #include <kernel/ipc/ipc_methods.h> 42 #include <input.h> 43 #include <mouse_port.h> 44 #include <mouse.h> 46 45 47 #include "adb_mouse.h" 48 #include "adb_dev.h" 46 static mouse_dev_t *mouse_dev; 47 static async_sess_t *dev_sess; 49 48 50 static void adb_dev_events(ipc_callid_t iid, ipc_call_t *icall); 49 /** List of devices to try connecting to. */ 50 static const char *in_devs[] = { 51 "char/ps2b", 52 }; 51 53 52 int adb_dev_init(void) 54 static const unsigned int num_devs = sizeof(in_devs) / sizeof(in_devs[0]); 55 56 static void mouse_port_events(ipc_callid_t iid, ipc_call_t *icall, void *arg) 57 { 58 /* Ignore parameters, the connection is already opened */ 59 while (true) { 60 ipc_call_t call; 61 ipc_callid_t callid = async_get_call(&call); 62 63 if (!IPC_GET_IMETHOD(call)) { 64 /* TODO: Handle hangup */ 65 return; 66 } 67 68 int retval; 69 70 switch (IPC_GET_IMETHOD(call)) { 71 case CHAR_NOTIF_BYTE: 72 mouse_push_data(mouse_dev, IPC_GET_ARG1(call)); 73 break; 74 default: 75 retval = ENOENT; 76 } 77 78 async_answer_0(callid, retval); 79 } 80 } 81 82 static int chardev_port_init(mouse_dev_t *mdev) 53 83 { 54 84 devmap_handle_t handle; 55 int rc = devmap_device_get_handle("adb/mouse", &handle,56 IPC_FLAG_BLOCKING);85 unsigned int i; 86 int rc; 57 87 58 if (rc != EOK) { 59 printf("%s: Failed resolving ADB\n", NAME); 60 return rc; 88 mouse_dev = mdev; 89 90 for (i = 0; i < num_devs; i++) { 91 rc = devmap_device_get_handle(in_devs[i], &handle, 0); 92 if (rc == EOK) 93 break; 61 94 } 62 95 63 int dev_phone = devmap_obsolete_device_connect(handle, IPC_FLAG_BLOCKING); 64 if (dev_phone < 0) { 65 printf("%s: Failed connecting to ADB\n", NAME); 96 if (i >= num_devs) { 97 printf("%s: Could not find any suitable input device\n", NAME); 98 return -1; 99 } 100 101 dev_sess = devmap_device_connect(EXCHANGE_ATOMIC, handle, 102 IPC_FLAG_BLOCKING); 103 if (dev_sess == NULL) { 104 printf("%s: Failed connecting to device\n", NAME); 66 105 return ENOENT; 67 106 } 68 107 108 async_exch_t *exch = async_exchange_begin(dev_sess); 109 if (exch == NULL) { 110 printf("%s: Failed starting exchange with device\n", NAME); 111 async_hangup(dev_sess); 112 return ENOMEM; 113 } 114 69 115 /* NB: The callback connection is slotted for removal */ 70 if (async_obsolete_connect_to_me(dev_phone, 0, 0, 0, adb_dev_events) != 0) { 71 printf(NAME ": Failed to create callback from device\n"); 72 return false; 116 rc = async_connect_to_me(exch, 0, 0, 0, mouse_port_events, NULL); 117 async_exchange_end(exch); 118 119 if (rc != 0) { 120 printf("%s: Failed to create callback from device\n", NAME); 121 async_hangup(dev_sess); 122 return -1; 73 123 } 74 124 … … 76 126 } 77 127 78 static void adb_dev_events(ipc_callid_t iid, ipc_call_t *icall)128 static void chardev_port_yield(void) 79 129 { 80 /* Ignore parameters, the connection is already opened */ 81 while (true) { 130 } 82 131 83 ipc_call_t call; 84 ipc_callid_t callid = async_get_call(&call); 132 static void chardev_port_reclaim(void) 133 { 134 } 85 135 86 int retval; 87 88 if (!IPC_GET_IMETHOD(call)) { 89 /* TODO: Handle hangup */ 90 return; 91 } 136 static void chardev_port_write(uint8_t data) 137 { 138 async_exch_t *exch = async_exchange_begin(dev_sess); 139 if (exch == NULL) { 140 printf("%s: Failed starting exchange with device\n", NAME); 141 return; 142 } 92 143 93 switch (IPC_GET_IMETHOD(call)) { 94 case IPC_FIRST_USER_METHOD: 95 mouse_handle_data(IPC_GET_ARG1(call)); 96 break; 97 default: 98 retval = ENOENT; 99 } 100 async_answer_0(callid, retval); 101 } 144 async_msg_1(exch, CHAR_WRITE_BYTE, data); 145 async_exchange_end(exch); 102 146 } 147 148 mouse_port_ops_t chardev_mouse_port = { 149 .init = chardev_port_init, 150 .yield = chardev_port_yield, 151 .reclaim = chardev_port_reclaim, 152 .write = chardev_port_write 153 }; 103 154 104 155 /**
Note:
See TracChangeset
for help on using the changeset viewer.