4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
27 * 3-Byte Mouse Protocol
30 #include <sys/param.h>
31 #include <sys/stream.h>
32 #include <sys/strsun.h>
33 #include <sys/vuid_event.h>
36 #define VUID_BUT(b) BUT((b*2)+1)
39 * VUID_BUT(0) BUT(1) LEFT BUTTON
40 * VUID_BUT(1) BUT(3) RIGHT BUTTON
43 #define MOUSE_BUTTON_L (uchar_t)(0x20) /* Left button pressed */
44 #define MOUSE_BUTTON_R (uchar_t)(0x10) /* Right button pressed */
46 #define MOUSE_START_CODE (uchar_t)(0x40) /* Start code in char */
48 #define MOUSE_START 0 /* Beginning of packet */
49 #define MOUSE_BUTTON 1 /* Got button status */
50 #define MOUSE_DELTA_X 2 /* got delta X */
52 extern void VUID_PUTNEXT(queue_t
*const, uchar_t
, uchar_t
, uchar_t
, int);
55 VUID_OPEN(queue_t
*const qp
)
63 vuidm3p_sendButtonEvent(queue_t
*const qp
)
67 if ((STATEP
->buttons
== 0x30) && (!STATEP
->oldbuttons
)) {
69 * both buttons going down simultaneously means button
72 vuidm3p_putnext(qp
, (uchar_t
)MS_MIDDLE
, FE_PAIR_NONE
, 0, 1);
74 } else if ((!STATEP
->buttons
) && (STATEP
->oldbuttons
== 0x30)) {
76 * both buttons going up simultaneously means button
79 vuidm3p_putnext(qp
, (uchar_t
)MS_MIDDLE
, FE_PAIR_NONE
, 0, 0);
84 * for each button, see if it has changed
86 for (b
= 0; b
< 2; b
++) {
87 uchar_t mask
= 0x20 >> b
;
89 if ((STATEP
->buttons
& mask
) != (STATEP
->oldbuttons
& mask
))
90 VUID_PUTNEXT(qp
, VUID_BUT(b
), FE_PAIR_NONE
, 0,
91 (STATEP
->buttons
& mask
? 1 : 0));
96 vuidm3p(queue_t
*const qp
, mblk_t
*mp
)
104 for (r
--; r
>= 0; r
--) {
107 /* strip the high-order bit (mouse sends 7-bit data) */
110 switch (STATEP
->state
) {
113 * Start state. We stay here if the start code is not
114 * received thus forcing us back into sync. When we
115 * get a start code the button mask comes with it
116 * forcing us to the next state.
122 STATEP
->deltax
= STATEP
->deltay
= 0;
125 if ((code
& MOUSE_START_CODE
) == 0)
128 STATEP
->buttons
= code
& 0x30;
130 if (STATEP
->buttons
!= STATEP
->oldbuttons
) {
131 vuidm3p_sendButtonEvent(qp
);
135 STATEP
->oldbuttons
= STATEP
->buttons
;
139 * bits 0 & 1 are bits 6 & 7 of X value
140 * (Sign extend them with the cast.)
142 STATEP
->deltax
= (signed char)((code
& 0x03) << 6);
145 * bits 2 & 3 are bits 6 & 7 of Y value
146 * (Sign extend them with the cast.)
148 STATEP
->deltay
= (signed char)((code
& 0x0c) << 4);
151 * go to the next state
153 STATEP
->state
= MOUSE_BUTTON
;
157 * We receive the remaining 6 bits of delta x, forcing
158 * us to the next state. We just piece the value of
162 if (code
& MOUSE_START_CODE
) {
163 STATEP
->state
= MOUSE_START
;
164 goto start_code
; /* restart */
167 STATEP
->deltax
|= code
& 0x3f;
168 STATEP
->state
= MOUSE_DELTA_X
;
172 * The last part of delta Y, and the packet
176 if (code
& MOUSE_START_CODE
) {
177 STATEP
->state
= MOUSE_START
;
178 goto start_code
; /* restart */
181 STATEP
->deltay
|= code
& 0x3f;
184 * generate motion Event
187 VUID_PUTNEXT(qp
, (uchar_t
)LOC_X_DELTA
,
188 FE_PAIR_ABSOLUTE
, (uchar_t
)LOC_X_ABSOLUTE
,
192 VUID_PUTNEXT(qp
, (uchar_t
)LOC_Y_DELTA
,
193 FE_PAIR_ABSOLUTE
, (uchar_t
)LOC_Y_ABSOLUTE
,
196 STATEP
->deltax
= STATEP
->deltay
= 0;