Changeset b0f00a9 in mainline for uspace/srv/hid/input/port/adb_mouse.c
- Timestamp:
- 2011-11-06T22:21:05Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 898e847
- Parents:
- 2bdf8313 (diff), 7b5f4c9 (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
-
uspace/srv/hid/input/port/adb_mouse.c (moved) (moved from uspace/srv/hid/char_mouse/chardev.c ) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/input/port/adb_mouse.c
r2bdf8313 rb0f00a9 1 1 /* 2 * Copyright (c) 20 09 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 ADB mouse port driver. 34 35 */ 35 36 36 #include <ipc/ char.h>37 #include <ipc/adb.h> 37 38 #include <async.h> 38 #include <vfs/vfs.h> 39 #include <fcntl.h> 39 #include <input.h> 40 #include <mouse_port.h> 41 #include <mouse.h> 40 42 #include <errno.h> 43 #include <loc.h> 44 #include <stdio.h> 41 45 42 #include <char_mouse.h> 43 #include <mouse_port.h> 46 static mouse_dev_t *mouse_dev; 47 static async_sess_t *dev_sess; 44 48 45 static void chardev_events(ipc_callid_t iid, ipc_call_t *icall); 46 47 static int dev_phone; 48 49 #define NAME "char_mouse" 50 51 int mouse_port_init(void) 52 { 53 const char *input = "/dev/char/ps2b"; 54 int input_fd; 55 56 printf(NAME ": open %s\n", input); 57 58 input_fd = open(input, O_RDONLY); 59 if (input_fd < 0) { 60 printf(NAME ": Failed opening %s (%d)\n", input, input_fd); 61 return false; 62 } 63 64 dev_phone = fd_phone(input_fd); 65 if (dev_phone < 0) { 66 printf(NAME ": Failed to connect to device\n"); 67 return false; 68 } 69 70 /* NB: The callback connection is slotted for removal */ 71 if (async_connect_to_me(dev_phone, 0, 0, 0, chardev_events) != 0) { 72 printf(NAME ": Failed to create callback from device\n"); 73 return false; 74 } 75 76 return 0; 77 } 78 79 void mouse_port_yield(void) 80 { 81 } 82 83 void mouse_port_reclaim(void) 84 { 85 } 86 87 void mouse_port_write(uint8_t data) 88 { 89 async_msg_1(dev_phone, CHAR_WRITE_BYTE, data); 90 } 91 92 static void chardev_events(ipc_callid_t iid, ipc_call_t *icall) 49 static void mouse_port_events(ipc_callid_t iid, ipc_call_t *icall, void *arg) 93 50 { 94 51 /* Ignore parameters, the connection is already opened */ 95 52 while (true) { 96 97 53 ipc_call_t call; 98 54 ipc_callid_t callid = async_get_call(&call); 99 55 100 56 int retval; 101 102 switch (IPC_GET_IMETHOD(call)) { 103 case IPC_M_PHONE_HUNGUP: 57 58 if (!IPC_GET_IMETHOD(call)) { 104 59 /* TODO: Handle hangup */ 105 60 return; 106 case IPC_FIRST_USER_METHOD: 107 mouse_handle_byte(IPC_GET_ARG1(call)); 61 } 62 63 switch (IPC_GET_IMETHOD(call)) { 64 case ADB_REG_NOTIF: 65 mouse_push_data(mouse_dev, IPC_GET_ARG1(call)); 108 66 break; 109 67 default: 110 68 retval = ENOENT; 111 69 } 70 112 71 async_answer_0(callid, retval); 113 72 } 114 73 } 115 74 75 static int adb_port_init(mouse_dev_t *mdev) 76 { 77 const char *dev = "adb/mouse"; 78 79 mouse_dev = mdev; 80 81 service_id_t service_id; 82 int rc = loc_service_get_id(dev, &service_id, 0); 83 if (rc != EOK) 84 return rc; 85 86 dev_sess = loc_service_connect(EXCHANGE_ATOMIC, service_id, 0); 87 if (dev_sess == NULL) { 88 printf("%s: Failed to connect to device\n", NAME); 89 return ENOENT; 90 } 91 92 async_exch_t *exch = async_exchange_begin(dev_sess); 93 if (exch == NULL) { 94 printf("%s: Failed starting exchange with device\n", NAME); 95 async_hangup(dev_sess); 96 return ENOMEM; 97 } 98 99 /* NB: The callback connection is slotted for removal */ 100 rc = async_connect_to_me(exch, 0, 0, 0, mouse_port_events, NULL); 101 async_exchange_end(exch); 102 if (rc != EOK) { 103 printf("%s: Failed to create callback from device\n", NAME); 104 async_hangup(dev_sess); 105 return rc; 106 } 107 108 return EOK; 109 } 110 111 static void adb_port_yield(void) 112 { 113 } 114 115 static void adb_port_reclaim(void) 116 { 117 } 118 119 static void adb_port_write(uint8_t data) 120 { 121 } 122 123 mouse_port_ops_t adb_mouse_port = { 124 .init = adb_port_init, 125 .yield = adb_port_yield, 126 .reclaim = adb_port_reclaim, 127 .write = adb_port_write 128 }; 129 116 130 /** 117 131 * @}
Note:
See TracChangeset
for help on using the changeset viewer.
