Changeset a33f0a6 in mainline for uspace/srv/hid/input/proto/ps2.c
- Timestamp:
- 2011-08-03T17:34:57Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 1940326
- Parents:
- 52a79081 (diff), 3fab770 (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/proto/ps2.c
r52a79081 ra33f0a6 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.