Changeset c322fd6 in mainline
- Timestamp:
- 2011-12-31T16:06:11Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 1dea6d7
- Parents:
- c637571
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/char/ps2mouse/ps2mouse.c
rc637571 rc322fd6 53 53 #define INTELLIMOUSE_BUFSIZE 4 54 54 55 #define Z_SIGN (1 << 3) 56 #define X_SIGN (1 << 4) 57 #define Y_SIGN (1 << 5) 58 #define X_OVERFLOW (1 << 6) 59 #define Y_OVERFLOW (1 << 7) 55 #define Z_SIGN (1 << 3) /* 4th byte */ 56 #define X_SIGN (1 << 4) /* 1st byte */ 57 #define Y_SIGN (1 << 5) /* 1st byte */ 58 #define X_OVERFLOW (1 << 6) /* 1st byte */ 59 #define Y_OVERFLOW (1 << 7) /* 1st byte */ 60 60 61 61 #define BUTTON_LEFT 0 … … 63 63 #define BUTTON_MIDDLE 2 64 64 #define PS2_BUTTON_COUNT 3 65 66 #define INTELLIMOUSE_ALWAYS_ZERO (0xc0) 67 #define INTELLIMOUSE_BUTTON_4 (1 << 4) /* 4th byte */ 68 #define INTELLIMOUSE_BUTTON_5 (1 << 5) /* 4th byte */ 65 69 #define INTELLIMOUSE_BUTTON_COUNT 5 66 70 … … 75 79 return size < 0 ? size : EIO; \ 76 80 } \ 77 if (data != value) { \81 if (data != (value)) { \ 78 82 ddf_msg(LVL_ERROR, "Failed testing byte: got %hhx vs. %hhx)", \ 79 data, value); \83 data, (value)); \ 80 84 return EIO; \ 81 85 } \ … … 83 87 #define MOUSE_WRITE_BYTE(sess, value) \ 84 88 do { \ 85 uint8_t data = value; \89 uint8_t data = (value); \ 86 90 const ssize_t size = char_dev_write(session, &data, 1); \ 87 91 if (size < 0 ) { \ … … 93 97 static int polling_ps2(void *); 94 98 static int polling_intellimouse(void *); 95 static int probe_intellimouse(async_sess_t * );99 static int probe_intellimouse(async_sess_t *, bool); 96 100 static void default_connection_handler(ddf_fun_t *, ipc_callid_t, ipc_call_t *); 97 101 /*----------------------------------------------------------------------------*/ … … 143 147 /* Probe IntelliMouse extensions. */ 144 148 int (*polling_f)(void*) = polling_ps2; 145 if (probe_intellimouse(mouse->parent_sess ) == EOK) {149 if (probe_intellimouse(mouse->parent_sess, false) == EOK) { 146 150 ddf_msg(LVL_NOTE, "Enabled IntelliMouse extensions"); 147 151 polling_f = polling_intellimouse; 152 if (probe_intellimouse(mouse->parent_sess, true) == EOK) 153 ddf_msg(LVL_NOTE, "Enabled 4th and 5th button."); 148 154 } 149 155 /* Enable mouse data reporting. */ … … 237 243 } 238 244 /*----------------------------------------------------------------------------*/ 239 /** Get data and parse ps2 protocol with intellimouse extension packets.245 /** Get data and parse ps2 protocol with IntelliMouse extension packets. 240 246 * @param arg Pointer to ps2_mouse_t structure. 241 247 * @return Never. … … 268 274 continue; 269 275 } 270 /* ps/2 Buttons */ 271 for (unsigned i = 0; i < PS2_BUTTON_COUNT; ++i) { 272 const bool status = (packet[0] & PS2_BUTTON_MASK(i)); 273 if (buttons[i] != status) { 274 buttons[i] = status; 276 277 /* Buttons */ 278 /* NOTE: Parsing 4th and 5th button works even if this extension 279 * is not supported and whole 4th byte should be interpreted 280 * as Z-axis movement. the upper 4 bits are just a sign 281 * extension then. + sign is interpreted as "button up" 282 * (i.e no change since that is the default) and - sign fails 283 * the "imb" condition. Thus 4th and 5th buttons are never 284 * down on wheel only extension. */ 285 const bool imb = (packet[3] & INTELLIMOUSE_ALWAYS_ZERO) == 0; 286 const bool status[] = { 287 [0] = packet[0] & PS2_BUTTON_MASK(0), 288 [1] = packet[0] & PS2_BUTTON_MASK(1), 289 [2] = packet[0] & PS2_BUTTON_MASK(2), 290 [3] = (packet[3] & INTELLIMOUSE_BUTTON_4) && imb, 291 [4] = (packet[3] & INTELLIMOUSE_BUTTON_5) && imb, 292 }; 293 for (unsigned i = 0; i < INTELLIMOUSE_BUTTON_COUNT; ++i) { 294 if (buttons[i] != status[i]) { 295 buttons[i] = status[i]; 275 296 async_msg_2(exch, MOUSEEV_BUTTON_EVENT, i + 1, 276 297 buttons[i]); … … 296 317 } 297 318 /*----------------------------------------------------------------------------*/ 298 static int probe_intellimouse(async_sess_t *session) 319 /** Send magic sequence to initialize IntelliMouse extensions. 320 * @param session IPC session to the parent device. 321 * @param buttons True selects magic sequence for 4th and 5th button, 322 * false selects wheel support magic sequence. 323 * See http://www.computer-engineering.org/ps2mouse/ for details. 324 */ 325 static int probe_intellimouse(async_sess_t *session, bool buttons) 299 326 { 300 327 assert(session); … … 307 334 MOUSE_WRITE_BYTE(session, PS2_MOUSE_SET_SAMPLE_RATE); 308 335 MOUSE_READ_BYTE_TEST(session, PS2_MOUSE_ACK); 309 MOUSE_WRITE_BYTE(session, 100);336 MOUSE_WRITE_BYTE(session, buttons ? 200 : 100); 310 337 MOUSE_READ_BYTE_TEST(session, PS2_MOUSE_ACK); 311 338 … … 317 344 MOUSE_WRITE_BYTE(session, PS2_MOUSE_GET_DEVICE_ID); 318 345 MOUSE_READ_BYTE_TEST(session, PS2_MOUSE_ACK); 319 MOUSE_READ_BYTE_TEST(session, 3);346 MOUSE_READ_BYTE_TEST(session, buttons ? 4 : 3); 320 347 321 348 return EOK;
Note:
See TracChangeset
for help on using the changeset viewer.