2 * PROJECT: ReactOS i8042 (ps/2 keyboard-mouse controller) driver
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: drivers/input/i8042prt/ps2pp.c
5 * PURPOSE: ps2pp protocol handling
6 * PROGRAMMERS: Copyright Martijn Vernooij (o112w8r02@sneakemail.com)
7 * Copyright 2006-2007 Hervé Poussineau (hpoussin@reactos.org)
10 /* INCLUDES ****************************************************************/
16 /* FUNCTIONS *****************************************************************/
20 IN PI8042_MOUSE_EXTENSION DeviceExtension
,
24 PMOUSE_INPUT_DATA MouseInput
;
26 MouseInput
= DeviceExtension
->MouseBuffer
+ DeviceExtension
->MouseInBuffer
;
28 /* First, collect 3 bytes for a packet
29 * We can detect out-of-sync only by checking
30 * the whole packet anyway.
32 * If bit 7 and 8 of the first byte are 0, its
35 * Otherwise, the packet is different, like this:
36 * 1: E 1 b3 b2 1 x x x
37 * 2: x x b1 b0 x1 x0 1 0
38 * 3: x x x x x x x1 x0
40 * b3-0 form a code that specifies the packet type:
43 * 1 Rollers and buttons
48 * 6 Wireless notifications
50 * 8 ShortID LSB (ShortID is a number that is supposed to differentiate
51 * 9 ShortID MSB between your mouse and your neighbours')
53 * 11 Mouse capabilities
54 * 12 Remote control LSB
55 * 13 Remote control MSB
60 switch (DeviceExtension
->MouseState
)
64 DeviceExtension
->MouseLogiBuffer
[DeviceExtension
->MouseState
] = Input
;
65 DeviceExtension
->MouseState
++;
69 DeviceExtension
->MouseLogiBuffer
[2] = Input
;
70 DeviceExtension
->MouseState
= MouseIdle
;
72 /* first check if it's a normal packet */
74 if (!(DeviceExtension
->MouseLogiBuffer
[0] & 0xC0))
76 DeviceExtension
->MouseState
= MouseIdle
;
77 i8042MouHandle(DeviceExtension
, DeviceExtension
->MouseLogiBuffer
[0]);
78 i8042MouHandle(DeviceExtension
, DeviceExtension
->MouseLogiBuffer
[1]);
79 i8042MouHandle(DeviceExtension
, DeviceExtension
->MouseLogiBuffer
[2]);
80 /* We could care about wether MouseState really
81 * advances, but we don't need to because we're
82 * only doing three bytes anyway, so the packet
83 * will never complete if it's broken.
89 if (((DeviceExtension
->MouseLogiBuffer
[0] & 0x48) != 0x48) ||
90 (((DeviceExtension
->MouseLogiBuffer
[1] & 0x0C) >> 2) !=
91 (DeviceExtension
->MouseLogiBuffer
[2] & 0x03)))
93 WARN_(I8042PRT
, "Ps2pp packet fails sanity checks\n");
97 /* Now get the packet type */
98 PktType
= ((DeviceExtension
->MouseLogiBuffer
[0] & 0x30) >> 2) |
99 ((DeviceExtension
->MouseLogiBuffer
[1] & 0x30) >> 4);
104 /* The packet contains the device ID, but we
105 * already read that in the initialization
106 * sequence. Ignore it.
110 RtlZeroMemory(MouseInput
, sizeof(MOUSE_INPUT_DATA
));
111 if (DeviceExtension
->MouseLogiBuffer
[2] & 0x10)
112 MouseInput
->RawButtons
|= MOUSE_BUTTON_4_DOWN
;
114 if (DeviceExtension
->MouseLogiBuffer
[2] & 0x20)
115 MouseInput
->RawButtons
|= MOUSE_BUTTON_5_DOWN
;
117 if (DeviceExtension
->MouseLogiBuffer
[2] & 0x0F)
119 MouseInput
->ButtonFlags
|= MOUSE_WHEEL
;
120 if (DeviceExtension
->MouseLogiBuffer
[2] & 0x08)
121 MouseInput
->ButtonData
= (DeviceExtension
->MouseLogiBuffer
[2] & 0x07) - 8;
123 MouseInput
->ButtonData
= DeviceExtension
->MouseLogiBuffer
[2] & 0x07;
125 i8042MouHandleButtons(
127 MOUSE_BUTTON_4_DOWN
| MOUSE_BUTTON_5_DOWN
);
128 DeviceExtension
->MouseHook
.QueueMousePacket(DeviceExtension
->MouseHook
.CallContext
);
131 /* These are for things that would probably
132 * be handled by logitechs own driver.
138 WARN_(I8042PRT
, "Unexpected input state for ps2pp!\n");