Changes in uspace/srv/hid/input/port/chardev.c [7a6065c:7aa94304] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/input/port/chardev.c
r7a6065c r7aa94304 35 35 */ 36 36 37 #include <ipc/char.h> 37 38 #include <async.h> 39 #include <loc.h> 38 40 #include <errno.h> 39 #include <fibril.h>40 #include <io/chardev.h>41 #include <loc.h>42 41 #include <stdio.h> 43 42 #include "../input.h" … … 45 44 #include "../kbd.h" 46 45 47 static int kbd_port_fibril(void *);46 static void kbd_port_events(ipc_callid_t iid, ipc_call_t *icall, void *arg); 48 47 49 48 static int chardev_port_init(kbd_dev_t *); 50 static void chardev_port_write(uint8_t );49 static void chardev_port_write(uint8_t data); 51 50 52 51 kbd_port_ops_t chardev_port = { … … 57 56 static kbd_dev_t *kbd_dev; 58 57 static async_sess_t *dev_sess; 59 static chardev_t *chardev;60 58 61 59 /** List of devices to try connecting to. */ … … 72 70 { 73 71 service_id_t service_id; 72 async_exch_t *exch; 74 73 unsigned int i; 75 fid_t fid;76 74 int rc; 77 75 … … 98 96 } 99 97 100 rc = chardev_open(dev_sess, &chardev);101 if ( rc != EOK) {102 printf("%s: Failed opening characterdevice\n", NAME);98 exch = async_exchange_begin(dev_sess); 99 if (exch == NULL) { 100 printf("%s: Failed starting exchange with device\n", NAME); 103 101 async_hangup(dev_sess); 104 102 return ENOMEM; 105 103 } 106 104 107 fid = fibril_create(kbd_port_fibril, NULL); 108 if (fid == 0) { 109 printf("%s: Failed creating fibril\n", NAME); 110 chardev_close(chardev); 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); 111 113 async_hangup(dev_sess); 112 return ENOMEM;114 return -1; 113 115 } 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 int rc; 124 size_t nwr; 123 async_exch_t *exch = async_exchange_begin(dev_sess); 124 if (exch == NULL) { 125 printf("%s: Failed starting exchange with device\n", NAME); 126 return; 127 } 125 128 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); 129 return; 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); 130 156 } 131 157 } 132 158 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 }151 159 152 160 /**
Note:
See TracChangeset
for help on using the changeset viewer.