xref: /onnv-gate/usr/src/uts/common/io/vuidmice/vuidm5p.c (revision 9840:bff764ffad2c)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
56990Sgd78059  * Common Development and Distribution License (the "License").
66990Sgd78059  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*9840Sgdamore@opensolaris.org  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate /*
270Sstevel@tonic-gate  * 5-Byte Mouse Protocol
280Sstevel@tonic-gate  */
290Sstevel@tonic-gate 
300Sstevel@tonic-gate #include <sys/param.h>
310Sstevel@tonic-gate #include <sys/stream.h>
326990Sgd78059 #include <sys/strsun.h>
330Sstevel@tonic-gate #include <sys/vuid_event.h>
34*9840Sgdamore@opensolaris.org #include "vuidmice.h"
350Sstevel@tonic-gate 
360Sstevel@tonic-gate #define	LOGI_NUMBUTTONS		3		/* Number of buttons	*/
370Sstevel@tonic-gate 
380Sstevel@tonic-gate #define	LOGI_BMASK		(uchar_t)7	/* Button mask in packet */
390Sstevel@tonic-gate #define	LOGI_NOT_BMASK		(uchar_t)(~LOGI_BMASK) /* Rest of the bits */
400Sstevel@tonic-gate #define	LOGI_START_CODE		(uchar_t)(0x80)	/* Start code in char	*/
410Sstevel@tonic-gate 
420Sstevel@tonic-gate #define	LOGI_START		0		/* Beginning of packet	*/
430Sstevel@tonic-gate #define	LOGI_BUTTON		1		/* Got button status	*/
440Sstevel@tonic-gate #define	LOGI_DELTA_X1		2		/* First of 2 delta X	*/
450Sstevel@tonic-gate #define	LOGI_DELTA_Y1		3		/* First of 2 delta Y	*/
460Sstevel@tonic-gate #define	LOGI_DELTA_X2		4		/* Second of 2 delta X	*/
470Sstevel@tonic-gate 
480Sstevel@tonic-gate extern void VUID_PUTNEXT(queue_t *const, uchar_t, uchar_t, uchar_t, int);
490Sstevel@tonic-gate 
500Sstevel@tonic-gate int
VUID_OPEN(queue_t * const qp)510Sstevel@tonic-gate VUID_OPEN(queue_t *const qp)
520Sstevel@tonic-gate {
530Sstevel@tonic-gate 	/*
540Sstevel@tonic-gate 	 * The current kdmconfig tables imply that this module can be used
550Sstevel@tonic-gate 	 * for both 2- and 3- button mice, so based on that evidence we
560Sstevel@tonic-gate 	 * can't assume a constant.  I don't know whether it's possible
570Sstevel@tonic-gate 	 * to autodetect.
580Sstevel@tonic-gate 	 */
590Sstevel@tonic-gate 	STATEP->nbuttons = 0;	/* Don't know. */
600Sstevel@tonic-gate 
610Sstevel@tonic-gate 	return (0);
620Sstevel@tonic-gate }
630Sstevel@tonic-gate 
640Sstevel@tonic-gate static void
vuidm5p_sendButtonEvent(queue_t * const qp)650Sstevel@tonic-gate vuidm5p_sendButtonEvent(queue_t *const qp)
660Sstevel@tonic-gate {
670Sstevel@tonic-gate 	int b;
680Sstevel@tonic-gate 
690Sstevel@tonic-gate 	/* for each button, see if it has changed */
700Sstevel@tonic-gate 	for (b = 0; b < 3; b++) {
710Sstevel@tonic-gate 		uchar_t mask = 4 >> b;
720Sstevel@tonic-gate 
730Sstevel@tonic-gate 		if ((STATEP->buttons&mask) != (STATEP->oldbuttons&mask))
740Sstevel@tonic-gate 			VUID_PUTNEXT(qp, BUT(b+1), FE_PAIR_NONE, 0,
750Sstevel@tonic-gate 			    (STATEP->buttons & mask ? 1 : 0));
760Sstevel@tonic-gate 	}
770Sstevel@tonic-gate }
780Sstevel@tonic-gate 
790Sstevel@tonic-gate void
vuidm5p(queue_t * const qp,mblk_t * mp)800Sstevel@tonic-gate vuidm5p(queue_t *const qp, mblk_t *mp)
810Sstevel@tonic-gate {
820Sstevel@tonic-gate 	int r, code;
830Sstevel@tonic-gate 	uchar_t *bufp;
840Sstevel@tonic-gate 
850Sstevel@tonic-gate 	bufp = mp->b_rptr;
866990Sgd78059 	r = MBLKL(mp);
870Sstevel@tonic-gate 
880Sstevel@tonic-gate 	for (r--; r >= 0; r--) {
890Sstevel@tonic-gate 		code = *bufp++;
900Sstevel@tonic-gate 
910Sstevel@tonic-gate 		switch (STATEP->state) {
920Sstevel@tonic-gate 			/*
930Sstevel@tonic-gate 			 * Start state. We stay here if the start code is not
940Sstevel@tonic-gate 			 * received thus forcing us back into sync. When we
950Sstevel@tonic-gate 			 * get a start code the button mask comes with it
960Sstevel@tonic-gate 			 * forcing us to the next state.
970Sstevel@tonic-gate 			 */
980Sstevel@tonic-gate 		default:
990Sstevel@tonic-gate resync:
1000Sstevel@tonic-gate 		case LOGI_START:
1010Sstevel@tonic-gate 			if ((code & LOGI_NOT_BMASK) != LOGI_START_CODE)
1020Sstevel@tonic-gate 				break;
1030Sstevel@tonic-gate 
1040Sstevel@tonic-gate 			STATEP->state   = LOGI_BUTTON;
1050Sstevel@tonic-gate 			STATEP->deltax  = STATEP->deltay = 0;
1060Sstevel@tonic-gate 			STATEP->buttons = (~code) & LOGI_BMASK;
1070Sstevel@tonic-gate 						/* or xlate[code & ] */
1080Sstevel@tonic-gate 			break;
1090Sstevel@tonic-gate 
1100Sstevel@tonic-gate 		case LOGI_BUTTON:
1110Sstevel@tonic-gate 			/*
1120Sstevel@tonic-gate 			 * We receive the first of 2 delta x which forces us
1130Sstevel@tonic-gate 			 * to the next state. We just add the values of each
1140Sstevel@tonic-gate 			 * delta x together.
1150Sstevel@tonic-gate 			 */
1160Sstevel@tonic-gate 			if ((code & LOGI_NOT_BMASK) == LOGI_START_CODE) {
1170Sstevel@tonic-gate 				STATEP->state = LOGI_START;
1180Sstevel@tonic-gate 				goto resync;
1190Sstevel@tonic-gate 			}
1200Sstevel@tonic-gate 
1210Sstevel@tonic-gate 			/* (The cast sign extends the 8-bit value.) */
1220Sstevel@tonic-gate 			STATEP->deltax += (signed char)code;
1230Sstevel@tonic-gate 			STATEP->state = LOGI_DELTA_X1;
1240Sstevel@tonic-gate 			break;
1250Sstevel@tonic-gate 
1260Sstevel@tonic-gate 		case LOGI_DELTA_X1:
1270Sstevel@tonic-gate 			/*
1280Sstevel@tonic-gate 			 * The first of 2 delta y. We just add
1290Sstevel@tonic-gate 			 * the 2 delta y together
1300Sstevel@tonic-gate 			 */
1310Sstevel@tonic-gate 			if ((code & LOGI_NOT_BMASK) == LOGI_START_CODE) {
1320Sstevel@tonic-gate 				STATEP->state = LOGI_START;
1330Sstevel@tonic-gate 				goto resync;
1340Sstevel@tonic-gate 			}
1350Sstevel@tonic-gate 
1360Sstevel@tonic-gate 			/* (The cast sign extends the 8-bit value.) */
1370Sstevel@tonic-gate 			STATEP->deltay += (signed char)code;
1380Sstevel@tonic-gate 			STATEP->state = LOGI_DELTA_Y1;
1390Sstevel@tonic-gate 			break;
1400Sstevel@tonic-gate 
1410Sstevel@tonic-gate 		case LOGI_DELTA_Y1:
1420Sstevel@tonic-gate 			/*
1430Sstevel@tonic-gate 			 * The second of 2 delta x. We just add
1440Sstevel@tonic-gate 			 * the 2 delta x together.
1450Sstevel@tonic-gate 			 */
1460Sstevel@tonic-gate 			if ((code & LOGI_NOT_BMASK) == LOGI_START_CODE) {
1470Sstevel@tonic-gate 				STATEP->state = LOGI_START;
1480Sstevel@tonic-gate 				goto resync;
1490Sstevel@tonic-gate 			}
1500Sstevel@tonic-gate 
1510Sstevel@tonic-gate 			/* (The cast sign extends the 8-bit value.) */
1520Sstevel@tonic-gate 			STATEP->deltax += (signed char)code;
1530Sstevel@tonic-gate 			STATEP->state = LOGI_DELTA_X2;
1540Sstevel@tonic-gate 			break;
1550Sstevel@tonic-gate 
1560Sstevel@tonic-gate 		case LOGI_DELTA_X2:
1570Sstevel@tonic-gate 			/*
1580Sstevel@tonic-gate 			 * The second of 2 delta y. We just add
1590Sstevel@tonic-gate 			 * the 2 delta y together.
1600Sstevel@tonic-gate 			 */
1610Sstevel@tonic-gate 			if ((code & LOGI_NOT_BMASK) == LOGI_START_CODE) {
1620Sstevel@tonic-gate 				STATEP->state = LOGI_START;
1630Sstevel@tonic-gate 				goto resync;
1640Sstevel@tonic-gate 			}
1650Sstevel@tonic-gate 
1660Sstevel@tonic-gate 			/* (The cast sign extends the 8-bit value.) */
1670Sstevel@tonic-gate 			STATEP->deltay += (signed char)code;
1680Sstevel@tonic-gate 			STATEP->state = LOGI_START;
1690Sstevel@tonic-gate 
1700Sstevel@tonic-gate 			/* check if motion has occurred and send event(s)... */
1710Sstevel@tonic-gate 			if (STATEP->deltax)
1720Sstevel@tonic-gate 				VUID_PUTNEXT(qp,
1730Sstevel@tonic-gate 				    (uchar_t)LOC_X_DELTA, FE_PAIR_ABSOLUTE,
1740Sstevel@tonic-gate 				    (uchar_t)LOC_X_ABSOLUTE, STATEP->deltax);
1750Sstevel@tonic-gate 
1760Sstevel@tonic-gate 			if (STATEP->deltay)
1770Sstevel@tonic-gate 				VUID_PUTNEXT(qp,
1780Sstevel@tonic-gate 				    (uchar_t)LOC_Y_DELTA, FE_PAIR_ABSOLUTE,
1790Sstevel@tonic-gate 				    (uchar_t)LOC_Y_ABSOLUTE, STATEP->deltay);
1800Sstevel@tonic-gate 
1810Sstevel@tonic-gate 			STATEP->deltax = STATEP->deltay = 0;
1820Sstevel@tonic-gate 
1830Sstevel@tonic-gate 			/* see if the buttons have changed */
1840Sstevel@tonic-gate 			if (STATEP->buttons != STATEP->oldbuttons) {
1850Sstevel@tonic-gate 				/* buttons have changed */
1860Sstevel@tonic-gate 				vuidm5p_sendButtonEvent(qp);
1870Sstevel@tonic-gate 
1880Sstevel@tonic-gate 				/* update new button state */
1890Sstevel@tonic-gate 				STATEP->oldbuttons = STATEP->buttons;
1900Sstevel@tonic-gate 			}
1910Sstevel@tonic-gate 		}
1920Sstevel@tonic-gate 	}
1930Sstevel@tonic-gate 	freemsg(mp);
1940Sstevel@tonic-gate }
195