17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 522eb7cb5Sgd78059 * Common Development and Distribution License (the "License"). 622eb7cb5Sgd78059 * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22*57f4a14aSGarrett D'Amore * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate /* 277c478bd9Sstevel@tonic-gate * 5-Byte Mouse Protocol 287c478bd9Sstevel@tonic-gate */ 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate #include <sys/param.h> 317c478bd9Sstevel@tonic-gate #include <sys/stream.h> 3222eb7cb5Sgd78059 #include <sys/strsun.h> 337c478bd9Sstevel@tonic-gate #include <sys/vuid_event.h> 34*57f4a14aSGarrett D'Amore #include "vuidmice.h" 357c478bd9Sstevel@tonic-gate 367c478bd9Sstevel@tonic-gate #define LOGI_NUMBUTTONS 3 /* Number of buttons */ 377c478bd9Sstevel@tonic-gate 387c478bd9Sstevel@tonic-gate #define LOGI_BMASK (uchar_t)7 /* Button mask in packet */ 397c478bd9Sstevel@tonic-gate #define LOGI_NOT_BMASK (uchar_t)(~LOGI_BMASK) /* Rest of the bits */ 407c478bd9Sstevel@tonic-gate #define LOGI_START_CODE (uchar_t)(0x80) /* Start code in char */ 417c478bd9Sstevel@tonic-gate 427c478bd9Sstevel@tonic-gate #define LOGI_START 0 /* Beginning of packet */ 437c478bd9Sstevel@tonic-gate #define LOGI_BUTTON 1 /* Got button status */ 447c478bd9Sstevel@tonic-gate #define LOGI_DELTA_X1 2 /* First of 2 delta X */ 457c478bd9Sstevel@tonic-gate #define LOGI_DELTA_Y1 3 /* First of 2 delta Y */ 467c478bd9Sstevel@tonic-gate #define LOGI_DELTA_X2 4 /* Second of 2 delta X */ 477c478bd9Sstevel@tonic-gate 487c478bd9Sstevel@tonic-gate extern void VUID_PUTNEXT(queue_t *const, uchar_t, uchar_t, uchar_t, int); 497c478bd9Sstevel@tonic-gate 507c478bd9Sstevel@tonic-gate int 517c478bd9Sstevel@tonic-gate VUID_OPEN(queue_t *const qp) 527c478bd9Sstevel@tonic-gate { 537c478bd9Sstevel@tonic-gate /* 547c478bd9Sstevel@tonic-gate * The current kdmconfig tables imply that this module can be used 557c478bd9Sstevel@tonic-gate * for both 2- and 3- button mice, so based on that evidence we 567c478bd9Sstevel@tonic-gate * can't assume a constant. I don't know whether it's possible 577c478bd9Sstevel@tonic-gate * to autodetect. 587c478bd9Sstevel@tonic-gate */ 597c478bd9Sstevel@tonic-gate STATEP->nbuttons = 0; /* Don't know. */ 607c478bd9Sstevel@tonic-gate 617c478bd9Sstevel@tonic-gate return (0); 627c478bd9Sstevel@tonic-gate } 637c478bd9Sstevel@tonic-gate 647c478bd9Sstevel@tonic-gate static void 657c478bd9Sstevel@tonic-gate vuidm5p_sendButtonEvent(queue_t *const qp) 667c478bd9Sstevel@tonic-gate { 677c478bd9Sstevel@tonic-gate int b; 687c478bd9Sstevel@tonic-gate 697c478bd9Sstevel@tonic-gate /* for each button, see if it has changed */ 707c478bd9Sstevel@tonic-gate for (b = 0; b < 3; b++) { 717c478bd9Sstevel@tonic-gate uchar_t mask = 4 >> b; 727c478bd9Sstevel@tonic-gate 737c478bd9Sstevel@tonic-gate if ((STATEP->buttons&mask) != (STATEP->oldbuttons&mask)) 747c478bd9Sstevel@tonic-gate VUID_PUTNEXT(qp, BUT(b+1), FE_PAIR_NONE, 0, 757c478bd9Sstevel@tonic-gate (STATEP->buttons & mask ? 1 : 0)); 767c478bd9Sstevel@tonic-gate } 777c478bd9Sstevel@tonic-gate } 787c478bd9Sstevel@tonic-gate 797c478bd9Sstevel@tonic-gate void 807c478bd9Sstevel@tonic-gate vuidm5p(queue_t *const qp, mblk_t *mp) 817c478bd9Sstevel@tonic-gate { 827c478bd9Sstevel@tonic-gate int r, code; 837c478bd9Sstevel@tonic-gate uchar_t *bufp; 847c478bd9Sstevel@tonic-gate 857c478bd9Sstevel@tonic-gate bufp = mp->b_rptr; 8622eb7cb5Sgd78059 r = MBLKL(mp); 877c478bd9Sstevel@tonic-gate 887c478bd9Sstevel@tonic-gate for (r--; r >= 0; r--) { 897c478bd9Sstevel@tonic-gate code = *bufp++; 907c478bd9Sstevel@tonic-gate 917c478bd9Sstevel@tonic-gate switch (STATEP->state) { 927c478bd9Sstevel@tonic-gate /* 937c478bd9Sstevel@tonic-gate * Start state. We stay here if the start code is not 947c478bd9Sstevel@tonic-gate * received thus forcing us back into sync. When we 957c478bd9Sstevel@tonic-gate * get a start code the button mask comes with it 967c478bd9Sstevel@tonic-gate * forcing us to the next state. 977c478bd9Sstevel@tonic-gate */ 987c478bd9Sstevel@tonic-gate default: 997c478bd9Sstevel@tonic-gate resync: 1007c478bd9Sstevel@tonic-gate case LOGI_START: 1017c478bd9Sstevel@tonic-gate if ((code & LOGI_NOT_BMASK) != LOGI_START_CODE) 1027c478bd9Sstevel@tonic-gate break; 1037c478bd9Sstevel@tonic-gate 1047c478bd9Sstevel@tonic-gate STATEP->state = LOGI_BUTTON; 1057c478bd9Sstevel@tonic-gate STATEP->deltax = STATEP->deltay = 0; 1067c478bd9Sstevel@tonic-gate STATEP->buttons = (~code) & LOGI_BMASK; 1077c478bd9Sstevel@tonic-gate /* or xlate[code & ] */ 1087c478bd9Sstevel@tonic-gate break; 1097c478bd9Sstevel@tonic-gate 1107c478bd9Sstevel@tonic-gate case LOGI_BUTTON: 1117c478bd9Sstevel@tonic-gate /* 1127c478bd9Sstevel@tonic-gate * We receive the first of 2 delta x which forces us 1137c478bd9Sstevel@tonic-gate * to the next state. We just add the values of each 1147c478bd9Sstevel@tonic-gate * delta x together. 1157c478bd9Sstevel@tonic-gate */ 1167c478bd9Sstevel@tonic-gate if ((code & LOGI_NOT_BMASK) == LOGI_START_CODE) { 1177c478bd9Sstevel@tonic-gate STATEP->state = LOGI_START; 1187c478bd9Sstevel@tonic-gate goto resync; 1197c478bd9Sstevel@tonic-gate } 1207c478bd9Sstevel@tonic-gate 1217c478bd9Sstevel@tonic-gate /* (The cast sign extends the 8-bit value.) */ 1227c478bd9Sstevel@tonic-gate STATEP->deltax += (signed char)code; 1237c478bd9Sstevel@tonic-gate STATEP->state = LOGI_DELTA_X1; 1247c478bd9Sstevel@tonic-gate break; 1257c478bd9Sstevel@tonic-gate 1267c478bd9Sstevel@tonic-gate case LOGI_DELTA_X1: 1277c478bd9Sstevel@tonic-gate /* 1287c478bd9Sstevel@tonic-gate * The first of 2 delta y. We just add 1297c478bd9Sstevel@tonic-gate * the 2 delta y together 1307c478bd9Sstevel@tonic-gate */ 1317c478bd9Sstevel@tonic-gate if ((code & LOGI_NOT_BMASK) == LOGI_START_CODE) { 1327c478bd9Sstevel@tonic-gate STATEP->state = LOGI_START; 1337c478bd9Sstevel@tonic-gate goto resync; 1347c478bd9Sstevel@tonic-gate } 1357c478bd9Sstevel@tonic-gate 1367c478bd9Sstevel@tonic-gate /* (The cast sign extends the 8-bit value.) */ 1377c478bd9Sstevel@tonic-gate STATEP->deltay += (signed char)code; 1387c478bd9Sstevel@tonic-gate STATEP->state = LOGI_DELTA_Y1; 1397c478bd9Sstevel@tonic-gate break; 1407c478bd9Sstevel@tonic-gate 1417c478bd9Sstevel@tonic-gate case LOGI_DELTA_Y1: 1427c478bd9Sstevel@tonic-gate /* 1437c478bd9Sstevel@tonic-gate * The second of 2 delta x. We just add 1447c478bd9Sstevel@tonic-gate * the 2 delta x together. 1457c478bd9Sstevel@tonic-gate */ 1467c478bd9Sstevel@tonic-gate if ((code & LOGI_NOT_BMASK) == LOGI_START_CODE) { 1477c478bd9Sstevel@tonic-gate STATEP->state = LOGI_START; 1487c478bd9Sstevel@tonic-gate goto resync; 1497c478bd9Sstevel@tonic-gate } 1507c478bd9Sstevel@tonic-gate 1517c478bd9Sstevel@tonic-gate /* (The cast sign extends the 8-bit value.) */ 1527c478bd9Sstevel@tonic-gate STATEP->deltax += (signed char)code; 1537c478bd9Sstevel@tonic-gate STATEP->state = LOGI_DELTA_X2; 1547c478bd9Sstevel@tonic-gate break; 1557c478bd9Sstevel@tonic-gate 1567c478bd9Sstevel@tonic-gate case LOGI_DELTA_X2: 1577c478bd9Sstevel@tonic-gate /* 1587c478bd9Sstevel@tonic-gate * The second of 2 delta y. We just add 1597c478bd9Sstevel@tonic-gate * the 2 delta y together. 1607c478bd9Sstevel@tonic-gate */ 1617c478bd9Sstevel@tonic-gate if ((code & LOGI_NOT_BMASK) == LOGI_START_CODE) { 1627c478bd9Sstevel@tonic-gate STATEP->state = LOGI_START; 1637c478bd9Sstevel@tonic-gate goto resync; 1647c478bd9Sstevel@tonic-gate } 1657c478bd9Sstevel@tonic-gate 1667c478bd9Sstevel@tonic-gate /* (The cast sign extends the 8-bit value.) */ 1677c478bd9Sstevel@tonic-gate STATEP->deltay += (signed char)code; 1687c478bd9Sstevel@tonic-gate STATEP->state = LOGI_START; 1697c478bd9Sstevel@tonic-gate 1707c478bd9Sstevel@tonic-gate /* check if motion has occurred and send event(s)... */ 1717c478bd9Sstevel@tonic-gate if (STATEP->deltax) 1727c478bd9Sstevel@tonic-gate VUID_PUTNEXT(qp, 1737c478bd9Sstevel@tonic-gate (uchar_t)LOC_X_DELTA, FE_PAIR_ABSOLUTE, 1747c478bd9Sstevel@tonic-gate (uchar_t)LOC_X_ABSOLUTE, STATEP->deltax); 1757c478bd9Sstevel@tonic-gate 1767c478bd9Sstevel@tonic-gate if (STATEP->deltay) 1777c478bd9Sstevel@tonic-gate VUID_PUTNEXT(qp, 1787c478bd9Sstevel@tonic-gate (uchar_t)LOC_Y_DELTA, FE_PAIR_ABSOLUTE, 1797c478bd9Sstevel@tonic-gate (uchar_t)LOC_Y_ABSOLUTE, STATEP->deltay); 1807c478bd9Sstevel@tonic-gate 1817c478bd9Sstevel@tonic-gate STATEP->deltax = STATEP->deltay = 0; 1827c478bd9Sstevel@tonic-gate 1837c478bd9Sstevel@tonic-gate /* see if the buttons have changed */ 1847c478bd9Sstevel@tonic-gate if (STATEP->buttons != STATEP->oldbuttons) { 1857c478bd9Sstevel@tonic-gate /* buttons have changed */ 1867c478bd9Sstevel@tonic-gate vuidm5p_sendButtonEvent(qp); 1877c478bd9Sstevel@tonic-gate 1887c478bd9Sstevel@tonic-gate /* update new button state */ 1897c478bd9Sstevel@tonic-gate STATEP->oldbuttons = STATEP->buttons; 1907c478bd9Sstevel@tonic-gate } 1917c478bd9Sstevel@tonic-gate } 1927c478bd9Sstevel@tonic-gate } 1937c478bd9Sstevel@tonic-gate freemsg(mp); 1947c478bd9Sstevel@tonic-gate } 195