Changeset 1875a0c in mainline for uspace/srv/hid/input/proto
- Timestamp:
- 2011-06-21T19:10:20Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 022d9f67
- Parents:
- a9d85df
- Location:
- uspace/srv/hid/input/proto
- Files:
-
- 3 moved
-
adb.c (moved) (moved from uspace/srv/hid/adb_mouse/adb_mouse.h ) (2 diffs)
-
mousedev.c (moved) (moved from uspace/srv/hid/input/generic/mouse.c ) (3 diffs)
-
ps2.c (moved) (moved from uspace/srv/hid/char_mouse/proto/ps2.c ) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/input/proto/adb.c
ra9d85df r1875a0c 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 30 * @ brief29 /** @addtogroup mouse_proto 30 * @ingroup input 31 31 * @{ 32 32 */ 33 /** @file 33 /** 34 * @file 35 * @brief ADB protocol driver. 34 36 */ 35 37 36 #ifndef ADB_MOUSE_H_ 37 #define ADB_MOUSE_H_ 38 #include <bool.h> 39 #include <mouse.h> 40 #include <mouse_port.h> 41 #include <mouse_proto.h> 38 42 39 #include <sys/types.h> 43 static mouse_dev_t *mouse_dev; 44 static bool b1_pressed; 45 static bool b2_pressed; 40 46 41 #define NAME "adb_ms" 42 #define NAMESPACE "hid_in" 47 static int adb_proto_init(mouse_dev_t *mdev) 48 { 49 mouse_dev = mdev; 50 b1_pressed = false; 51 b2_pressed = false; 52 53 return 0; 54 } 43 55 44 extern void mouse_handle_data(uint16_t); 56 /** Process mouse data */ 57 static void adb_proto_parse(sysarg_t data) 58 { 59 bool b1, b2; 60 uint16_t udx, udy; 61 int dx, dy; 62 63 /* Extract fields. */ 64 b1 = ((data >> 15) & 1) == 0; 65 udy = (data >> 8) & 0x7f; 66 b2 = ((data >> 7) & 1) == 0; 67 udx = data & 0x7f; 68 69 /* Decode 7-bit two's complement signed values. */ 70 dx = (udx & 0x40) ? (udx - 0x80) : udx; 71 dy = (udy & 0x40) ? (udy - 0x80) : udy; 72 73 if (b1 != b1_pressed) { 74 mouse_push_event_button(mouse_dev, 1, b1); 75 b1_pressed = b1; 76 } 77 78 if (b2 != b2_pressed) { 79 mouse_push_event_button(mouse_dev, 2, b2); 80 b1_pressed = b1; 81 } 82 83 if (dx != 0 || dy != 0) 84 mouse_push_event_move(mouse_dev, dx, dy); 85 } 45 86 46 #endif 87 mouse_proto_ops_t adb_proto = { 88 .parse = adb_proto_parse, 89 .init = adb_proto_init 90 }; 47 91 48 92 /** -
uspace/srv/hid/input/proto/mousedev.c
ra9d85df r1875a0c 1 1 /* 2 * Copyright (c) 2011 Jiri Svoboda2 * Copyright (c) 2011 Martin Decky 3 3 * All rights reserved. 4 4 * … … 27 27 */ 28 28 29 /** 30 * @addtogroup inputgen generic 31 * @brief Mouse device handling. 29 /** @addtogroup mouse_proto 32 30 * @ingroup input 33 31 * @{ 34 32 */ 35 /** @file 33 /** 34 * @file 35 * @brief Mouse device connector controller driver. 36 36 */ 37 37 38 #include <adt/list.h> 38 #include <stdio.h> 39 #include <fcntl.h> 40 #include <vfs/vfs_sess.h> 41 #include <malloc.h> 39 42 #include <async.h> 40 43 #include <errno.h> 41 #include < fcntl.h>44 #include <ipc/mouseev.h> 42 45 #include <input.h> 43 #include <ipc/mouse.h>44 46 #include <mouse.h> 45 #include <stdio.h> 46 #include <stdlib.h> 47 #include <vfs/vfs_sess.h> 47 #include <mouse_port.h> 48 #include <mouse_proto.h> 48 49 49 static void mouse_callback_conn(ipc_callid_t, ipc_call_t *, void *); 50 /** Mousedev softstate */ 51 typedef struct { 52 /** Link to generic mouse device */ 53 mouse_dev_t *mouse_dev; 54 55 /** Session to mouse device */ 56 async_sess_t *sess; 57 58 /** File descriptor of open mousedev device */ 59 int fd; 60 } mousedev_t; 50 61 51 static mouse _dev_t *mouse_dev_new(void)62 static mousedev_t *mousedev_new(mouse_dev_t *mdev) 52 63 { 53 mouse_dev_t *mdev; 54 55 mdev = calloc(1, sizeof(mouse_dev_t)); 56 if (mdev == NULL) { 57 printf(NAME ": Error allocating mouse device. " 58 "Out of memory.\n"); 64 mousedev_t *mousedev = calloc(1, sizeof(mousedev_t)); 65 if (mousedev == NULL) 59 66 return NULL; 60 } 61 62 link_initialize(&mdev->mouse_devs); 63 return mdev; 67 68 mousedev->mouse_dev = mdev; 69 mousedev->fd = -1; 70 71 return mousedev; 64 72 } 65 73 66 static int mouse_dev_connect(mouse_dev_t *mdev, const char *dev_path)74 static void mousedev_destroy(mousedev_t *mousedev) 67 75 { 68 async_sess_t *sess; 69 async_exch_t *exch; 70 int fd; 71 int rc; 72 73 fd = open(dev_path, O_RDWR); 74 if (fd < 0) { 75 return -1; 76 } 77 78 sess = fd_session(EXCHANGE_SERIALIZE, fd); 79 if (sess == NULL) { 80 printf(NAME ": Failed starting session with '%s'\n", dev_path); 81 close(fd); 82 return -1; 83 } 84 85 exch = async_exchange_begin(sess); 86 if (exch == NULL) { 87 printf(NAME ": Failed starting exchange with '%s'.\n", dev_path); 88 return -1; 89 } 90 91 rc = async_connect_to_me(exch, 0, 0, 0, mouse_callback_conn, mdev); 92 if (rc != EOK) { 93 printf(NAME ": Failed creating callback connection from '%s'.\n", 94 dev_path); 95 async_exchange_end(exch); 96 return -1; 97 } 98 99 async_exchange_end(exch); 100 101 mdev->dev_path = dev_path; 102 return 0; 76 if (mousedev->sess != NULL) 77 async_hangup(mousedev->sess); 78 79 if (mousedev->fd >= 0) 80 close(mousedev->fd); 81 82 free(mousedev); 103 83 } 104 84 105 /** Add new mouse device. 106 * 107 * @param dev_path Filesystem path to the device (/dev/class/...) 108 */ 109 int mouse_add_dev(const char *dev_path) 85 static void mousedev_callback_conn(ipc_callid_t iid, ipc_call_t *icall, 86 void *arg) 110 87 { 111 mouse_dev_t *mdev; 112 int rc; 113 114 mdev = mouse_dev_new(); 115 if (mdev == NULL) 116 return -1; 117 118 rc = mouse_dev_connect(mdev, dev_path); 119 if (rc != EOK) { 120 free(mdev); 121 return -1; 122 } 123 124 list_append(&mdev->mouse_devs, &mouse_devs); 125 return EOK; 126 } 127 128 /** Mouse device callback connection handler. */ 129 static void mouse_callback_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg) 130 { 131 int retval; 132 88 /* Mousedev device structure */ 89 mousedev_t *mousedev = (mousedev_t *) arg; 90 133 91 while (true) { 134 92 ipc_call_t call; 135 ipc_callid_t callid; 136 137 callid = async_get_call(&call); 93 ipc_callid_t callid = async_get_call(&call); 94 138 95 if (!IPC_GET_IMETHOD(call)) { 139 96 /* XXX Handle hangup */ 140 97 return; 141 98 } 142 99 100 int retval; 101 143 102 switch (IPC_GET_IMETHOD(call)) { 144 case M EVENT_BUTTON:145 input_event_button(IPC_GET_ARG1(call),103 case MOUSEEV_MOVE_EVENT: 104 mouse_push_event_move(mousedev->mouse_dev, IPC_GET_ARG1(call), 146 105 IPC_GET_ARG2(call)); 147 retval = 0;106 retval = EOK; 148 107 break; 149 case M EVENT_MOVE:150 input_event_move(IPC_GET_ARG1(call),108 case MOUSEEV_BUTTON_EVENT: 109 mouse_push_event_button(mousedev->mouse_dev, IPC_GET_ARG1(call), 151 110 IPC_GET_ARG2(call)); 152 retval = 0;111 retval = EOK; 153 112 break; 154 113 default: … … 156 115 break; 157 116 } 158 117 159 118 async_answer_0(callid, retval); 160 119 } 161 120 } 162 121 122 static int mousedev_proto_init(mouse_dev_t *mdev) 123 { 124 const char *pathname = mdev->dev_path; 125 126 int fd = open(pathname, O_RDWR); 127 if (fd < 0) 128 return -1; 129 130 async_sess_t *sess = fd_session(EXCHANGE_SERIALIZE, fd); 131 if (sess == NULL) { 132 printf("%s: Failed starting session with '%s'\n", NAME, pathname); 133 close(fd); 134 return -1; 135 } 136 137 mousedev_t *mousedev = mousedev_new(mdev); 138 if (mousedev == NULL) { 139 printf("%s: Failed allocating device structure for '%s'.\n", 140 NAME, pathname); 141 return -1; 142 } 143 144 mousedev->fd = fd; 145 mousedev->sess = sess; 146 147 async_exch_t *exch = async_exchange_begin(sess); 148 if (exch == NULL) { 149 printf("%s: Failed starting exchange with '%s'.\n", NAME, pathname); 150 mousedev_destroy(mousedev); 151 return -1; 152 } 153 154 int rc = async_connect_to_me(exch, 0, 0, 0, mousedev_callback_conn, mousedev); 155 async_exchange_end(exch); 156 157 if (rc != EOK) { 158 printf("%s: Failed creating callback connection from '%s'.\n", 159 NAME, pathname); 160 mousedev_destroy(mousedev); 161 return -1; 162 } 163 164 return 0; 165 } 166 167 mouse_proto_ops_t mousedev_proto = { 168 .init = mousedev_proto_init 169 }; 170 163 171 /** 164 172 * @} -
uspace/srv/hid/input/proto/ps2.c
ra9d85df r1875a0c 1 1 /* 2 * Copyright (c) 20 06 Ondrej Palkovsky2 * Copyright (c) 2011 Martin Decky 3 3 * All rights reserved. 4 4 * … … 27 27 */ 28 28 29 /** @addtogroup mouse 29 /** @addtogroup mouse_proto 30 * @ingroup input 30 31 * @{ 31 32 */ 32 33 /** 33 34 * @file 34 * @brief PS/2 mouseprotocol driver.35 * @brief PS/2 protocol driver. 35 36 */ 36 37 37 #include < stdio.h>38 #include <mouse.h> 38 39 #include <mouse_port.h> 39 #include <char_mouse.h>40 40 #include <mouse_proto.h> 41 42 #define BUFSIZE 343 41 44 42 #define PS2_MOUSE_OUT_INIT 0xf4 45 43 #define PS2_MOUSE_ACK 0xfa 44 45 #define BUFSIZE 3 46 46 47 47 typedef struct { … … 49 49 unsigned char data[BUFSIZE]; 50 50 struct { 51 unsigned leftbtn : 1;52 unsigned rightbtn : 1;53 unsigned middlebtn : 1;54 unsigned i sone : 1; /* Always one */55 unsigned xsign : 1;56 unsigned ysign : 1;57 unsigned xovfl : 1;58 unsigned yovfl : 1;51 unsigned int leftbtn : 1; 52 unsigned int rightbtn : 1; 53 unsigned int middlebtn : 1; 54 unsigned int isone : 1; /* Always one */ 55 unsigned int xsign : 1; 56 unsigned int ysign : 1; 57 unsigned int xovfl : 1; 58 unsigned int yovfl : 1; 59 59 unsigned char x; 60 60 unsigned char y; … … 64 64 65 65 static ps2packet_t buf; 66 static int bufpos = 0;67 static int leftbtn = 0;68 static int rightbtn = 0;69 static int middlebtn = 0;66 static unsigned int bufpos; 67 static unsigned int leftbtn; 68 static unsigned int rightbtn; 69 static unsigned int middlebtn; 70 70 71 int mouse_proto_init(void) 71 static mouse_dev_t *mouse_dev; 72 73 static int ps2_proto_init(mouse_dev_t *mdev) 72 74 { 73 mouse_port_write(PS2_MOUSE_OUT_INIT); 75 mouse_dev = mdev; 76 bufpos = 0; 77 leftbtn = 0; 78 rightbtn = 0; 79 80 mouse_dev->port_ops->write(PS2_MOUSE_OUT_INIT); 74 81 return 0; 75 82 } … … 79 86 { 80 87 int tmp; 81 88 82 89 if (!sign) 83 90 return data; 84 85 tmp = ((unsigned char) ~data) + 1;91 92 tmp = ((unsigned char) ~data) + 1; 86 93 return -tmp; 87 94 } 88 95 89 96 /** Process mouse data */ 90 void mouse_proto_parse_byte(int data)97 static void ps2_proto_parse(sysarg_t data) 91 98 { 92 99 int x, y; 93 100 94 101 /* Check that we have not lost synchronization */ 95 102 if (bufpos == 0 && !(data & 0x8)) 96 103 return; /* Synchro lost, ignore byte */ 97 104 98 105 buf.u.data[bufpos++] = data; 99 106 if (bufpos == BUFSIZE) { 100 107 bufpos = 0; 101 108 102 109 if (buf.u.val.leftbtn ^ leftbtn) { 103 110 leftbtn = buf.u.val.leftbtn; 104 mouse_ ev_btn(1, leftbtn);111 mouse_push_event_button(mouse_dev, 1, leftbtn); 105 112 } 106 113 107 114 if (buf.u.val.rightbtn ^ rightbtn) { 108 115 rightbtn = buf.u.val.rightbtn; 109 mouse_ ev_btn(2, rightbtn);116 mouse_push_event_button(mouse_dev, 2, rightbtn); 110 117 } 111 118 112 119 if (buf.u.val.middlebtn ^ middlebtn) { 113 120 middlebtn = buf.u.val.middlebtn; 114 mouse_ ev_btn(3, middlebtn);121 mouse_push_event_button(mouse_dev, 3, middlebtn); 115 122 } 123 124 x = bit9toint(buf.u.val.xsign, buf.u.val.x); 125 y = -bit9toint(buf.u.val.ysign, buf.u.val.y); 126 127 if (x != 0 || y != 0) 128 mouse_push_event_move(mouse_dev, x, y); 129 } 130 } 116 131 117 x = bit9toint(buf.u.val.xsign, buf.u.val.x); 118 y = - bit9toint(buf.u.val.ysign, buf.u.val.y); 119 120 if (x != 0 || y != 0) { 121 mouse_ev_move(x, y); 122 } 123 } 124 125 return; 126 } 132 mouse_proto_ops_t ps2_proto = { 133 .parse = ps2_proto_parse, 134 .init = ps2_proto_init 135 }; 127 136 128 137 /**
Note:
See TracChangeset
for help on using the changeset viewer.
