Changes in uspace/srv/hid/input/port/chardev.c [7aa94304:7a6065c] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/input/port/chardev.c
r7aa94304 r7a6065c 35 35 */ 36 36 37 #include <ipc/char.h>38 37 #include <async.h> 38 #include <errno.h> 39 #include <fibril.h> 40 #include <io/chardev.h> 39 41 #include <loc.h> 40 #include <errno.h>41 42 #include <stdio.h> 42 43 #include "../input.h" … … 44 45 #include "../kbd.h" 45 46 46 static void kbd_port_events(ipc_callid_t iid, ipc_call_t *icall, void *arg);47 static int kbd_port_fibril(void *); 47 48 48 49 static int chardev_port_init(kbd_dev_t *); 49 static void chardev_port_write(uint8_t data);50 static void chardev_port_write(uint8_t); 50 51 51 52 kbd_port_ops_t chardev_port = { … … 56 57 static kbd_dev_t *kbd_dev; 57 58 static async_sess_t *dev_sess; 59 static chardev_t *chardev; 58 60 59 61 /** List of devices to try connecting to. */ … … 70 72 { 71 73 service_id_t service_id; 72 async_exch_t *exch;73 74 unsigned int i; 75 fid_t fid; 74 76 int rc; 75 77 … … 96 98 } 97 99 98 exch = async_exchange_begin(dev_sess);99 if ( exch == NULL) {100 printf("%s: Failed starting exchange withdevice\n", NAME);100 rc = chardev_open(dev_sess, &chardev); 101 if (rc != EOK) { 102 printf("%s: Failed opening character device\n", NAME); 101 103 async_hangup(dev_sess); 102 104 return ENOMEM; 103 105 } 104 106 105 port_id_t port; 106 rc = async_create_callback_port(exch, INTERFACE_CHAR_CB, 0, 0, 107 kbd_port_events, NULL, &port); 108 109 async_exchange_end(exch); 110 111 if (rc != 0) { 112 printf("%s: Failed to create callback from device\n", NAME); 107 fid = fibril_create(kbd_port_fibril, NULL); 108 if (fid == 0) { 109 printf("%s: Failed creating fibril\n", NAME); 110 chardev_close(chardev); 113 111 async_hangup(dev_sess); 114 return -1;112 return ENOMEM; 115 113 } 114 115 fibril_add_ready(fid); 116 116 117 117 printf("%s: Found input device '%s'\n", NAME, in_devs[i]); … … 121 121 static void chardev_port_write(uint8_t data) 122 122 { 123 async_exch_t *exch = async_exchange_begin(dev_sess); 124 if (exch == NULL) { 125 printf("%s: Failed starting exchange with device\n", NAME); 123 int rc; 124 size_t nwr; 125 126 rc = chardev_write(chardev, &data, sizeof(data), &nwr); 127 if (rc != EOK || nwr != sizeof(data)) { 128 printf("%s: Failed writing to character device\n", NAME); 126 129 return; 127 }128 129 async_msg_1(exch, CHAR_WRITE_BYTE, data);130 async_exchange_end(exch);131 }132 133 static void kbd_port_events(ipc_callid_t iid, ipc_call_t *icall, void *arg)134 {135 /* Ignore parameters, the connection is already opened */136 while (true) {137 138 ipc_call_t call;139 ipc_callid_t callid = async_get_call(&call);140 141 if (!IPC_GET_IMETHOD(call)) {142 /* TODO: Handle hangup */143 return;144 }145 146 int retval = EOK;147 148 switch (IPC_GET_IMETHOD(call)) {149 case CHAR_NOTIF_BYTE:150 kbd_push_data(kbd_dev, IPC_GET_ARG1(call));151 break;152 default:153 retval = ENOENT;154 }155 async_answer_0(callid, retval);156 130 } 157 131 } 158 132 133 static int kbd_port_fibril(void *arg) 134 { 135 int rc; 136 size_t nread; 137 uint8_t b; 138 139 while (true) { 140 rc = chardev_read(chardev, &b, sizeof(b), &nread); 141 if (rc != EOK || nread != sizeof(b)) { 142 printf("%s: Error reading data", NAME); 143 continue; 144 } 145 146 kbd_push_data(kbd_dev, b); 147 } 148 149 return 0; 150 } 159 151 160 152 /**
Note:
See TracChangeset
for help on using the changeset viewer.