Changeset 3b2e387 in mainline for uspace/srv/hid/input/port/chardev_mouse.c
- Timestamp:
- 2011-06-21T19:36:05Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- e3a6c45
- Parents:
- 40f606b (diff), 022d9f67 (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
r40f606b r3b2e387 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 <async.h> 43 #include <kernel/ipc/ipc_methods.h> 42 #include <input.h> 43 #include <mouse_port.h> 44 #include <mouse.h> 44 45 45 #include "adb_mouse.h" 46 #include "adb_dev.h" 46 static mouse_dev_t *mouse_dev; 47 static async_sess_t *dev_sess; 47 48 48 static void adb_dev_events(ipc_callid_t iid, ipc_call_t *icall, void *arg); 49 /** List of devices to try connecting to. */ 50 static const char *in_devs[] = { 51 "char/ps2b", 52 }; 49 53 50 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) 51 83 { 52 84 devmap_handle_t handle; 53 async_exch_t *exch;85 unsigned int i; 54 86 int rc; 55 87 56 rc = devmap_device_get_handle("adb/mouse", &handle, 57 IPC_FLAG_BLOCKING); 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 async_sess_t *dev_sess = devmap_device_connect(EXCHANGE_ATOMIC, handle, 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, 64 102 IPC_FLAG_BLOCKING); 65 103 if (dev_sess == NULL) { 66 printf("%s: Failed connecting to ADB\n", NAME);104 printf("%s: Failed connecting to device\n", NAME); 67 105 return ENOENT; 68 106 } 69 107 70 exch = async_exchange_begin(dev_sess);108 async_exch_t *exch = async_exchange_begin(dev_sess); 71 109 if (exch == NULL) { 72 printf("%s: Failed starting exchange with ADB\n", NAME);110 printf("%s: Failed starting exchange with device\n", NAME); 73 111 async_hangup(dev_sess); 74 112 return ENOMEM; … … 76 114 77 115 /* NB: The callback connection is slotted for removal */ 78 rc = async_connect_to_me(exch, 0, 0, 0, adb_dev_events, NULL);116 rc = async_connect_to_me(exch, 0, 0, 0, mouse_port_events, NULL); 79 117 async_exchange_end(exch); 80 118 81 119 if (rc != 0) { 82 printf( NAME ": Failed to create callback from device\n");120 printf("%s: Failed to create callback from device\n", NAME); 83 121 async_hangup(dev_sess); 84 return ENOENT;122 return -1; 85 123 } 86 124 … … 88 126 } 89 127 90 static void adb_dev_events(ipc_callid_t iid, ipc_call_t *icall, void *arg)128 static void chardev_port_yield(void) 91 129 { 92 /* Ignore parameters, the connection is already opened */ 93 while (true) { 130 } 94 131 95 ipc_call_t call; 96 ipc_callid_t callid = async_get_call(&call); 132 static void chardev_port_reclaim(void) 133 { 134 } 97 135 98 int retval; 99 100 if (!IPC_GET_IMETHOD(call)) { 101 /* TODO: Handle hangup */ 102 return; 103 } 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 } 104 143 105 switch (IPC_GET_IMETHOD(call)) { 106 case IPC_FIRST_USER_METHOD: 107 mouse_handle_data(IPC_GET_ARG1(call)); 108 break; 109 default: 110 retval = ENOENT; 111 } 112 async_answer_0(callid, retval); 113 } 144 async_msg_1(exch, CHAR_WRITE_BYTE, data); 145 async_exchange_end(exch); 114 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 }; 115 154 116 155 /**
Note:
See TracChangeset
for help on using the changeset viewer.