-
Notifications
You must be signed in to change notification settings - Fork 55
/
ps2mouse.c
620 lines (582 loc) · 17.9 KB
/
ps2mouse.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
/* Copyright 2021 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
* i2c to PS2 compat mouse emulation using hid-i2c to ps2 conversion
* This is designed to function with a pixart hid-i2c touchpad
* and there are a few settings that configure this touchpad
* mouse mode based on fixed assumptions from the hid descriptor
* specifically the mode switch command.
*/
#include "system.h"
#include "task.h"
#include "config.h"
#include "console.h"
#include "task.h"
#include "hooks.h"
#include "util.h"
#include "i2c.h"
#include "timer.h"
#include "keyboard_8042.h"
#include "ps2mouse.h"
#include "power.h"
#include "diagnostics.h"
#define CPRINTS(format, args...) cprints(CC_KEYBOARD, format, ## args)
#define CPRINTF(format, args...) cprintf(CC_KEYBOARD, format, ## args)
static enum ps2_mouse_state mouse_state = PS2MSTATE_STREAM;
static enum ps2_mouse_state prev_mouse_state = PS2MSTATE_STREAM;
static uint8_t prev_command;
static uint8_t data_report_en = true;
static int32_t current_pos[4] = {0x08, 0, 0, 0};
static uint8_t button_state;
/*in 5 button mode deltaz is changed by +-1 for vertical scroll, and +-2 for horizontal scroll*/
static uint8_t five_button_mode;
/* State of magic Knock to enter 5 button mode */
static uint8_t five_button_flags;
static uint8_t mouse_scale;
static uint8_t resolution;
static uint8_t sample_rate = 100;
static uint8_t ec_mode_disabled;
static uint8_t detected_host_packet = true;
static uint8_t emumouse_task_id;
static uint8_t aux_data;
void send_data_byte(uint8_t data) {
int timeout = 0;
/* sometimes the host will get behind */
while (aux_buffer_available() < 1 && timeout++ < AUX_BUFFER_FULL_RETRIES)
usleep(10*MSEC);
send_aux_data_to_host_interrupt(data);
}
void send_movement_packet(void)
{
int i;
int max = 3;
int timeout = 0;
if (five_button_mode)
max = 4;
/* sometimes the host will get behind */
while (aux_buffer_available() < max && timeout++ < AUX_BUFFER_FULL_RETRIES &&
(*task_get_event_bitmap(emumouse_task_id) & PS2MOUSE_EVT_AUX_DATA) == 0) {
usleep(10*MSEC);
}
if (timeout == AUX_BUFFER_FULL_RETRIES ||
(*task_get_event_bitmap(emumouse_task_id) & PS2MOUSE_EVT_AUX_DATA)) {
CPRINTS("PS2M Dropping");
/*drop mouse packet - host is too far behind */
return;
}
for (i = 0; i < max; i++) {
send_data_byte(current_pos[i]);
}
}
void send_aux_data_to_device(uint8_t data)
{
aux_data = data;
task_set_event(emumouse_task_id, PS2MOUSE_EVT_AUX_DATA, 0);
}
void process_request(uint8_t data)
{
uint8_t response;
if (ec_mode_disabled) {
return;
}
switch (mouse_state) {
case PS2MSTATE_RESET:
send_data_byte(PS2MOUSE_ACKNOWLEDGE);
send_data_byte(PS2MOUSE_BAT_SUCCESS);
send_data_byte(PS2MOUSE_ID_PS2);
mouse_state = PS2MSTATE_STREAM;
mouse_scale = 1;
five_button_mode = 0;
break;
case PS2MSTATE_CONSUME_1_BYTE:
mouse_state = prev_mouse_state;
break;
case PS2MSTATE_CONSUME_1_BYTE_ACK:
if (prev_command == PS2MOUSE_SET_SAMPLE_RATE) {
if (five_button_flags == 0 && data == 200) {
five_button_flags = BIT(0);
} else if (five_button_flags == BIT(0) && data == 200) {
five_button_flags |= BIT(1);
} else if (five_button_flags == (BIT(0) | BIT(1)) && data == 80) {
five_button_flags |= BIT(2);
CPRINTS("PS2M 5 Button Magic Knock!");
five_button_mode = 1;
}
sample_rate = data;
} else if (prev_command == PS2MOUSE_SET_RESOLUTION) {
resolution = data;
}
mouse_state = prev_mouse_state;
goto SENDACK;
case PS2MSTATE_STREAM:
case PS2MSTATE_REMOTE:
prev_command = data;
switch (data) {
case PS2MOUSE_RESET:
mouse_state = PS2MSTATE_STREAM;
send_data_byte(PS2MOUSE_ACKNOWLEDGE);
send_data_byte(PS2MOUSE_BAT_SUCCESS);
send_data_byte(PS2MOUSE_ID_PS2);
five_button_mode = 0;
five_button_flags = 0;
break;
case PS2MOUSE_READ_DATA:
send_data_byte(PS2MOUSE_ACKNOWLEDGE);
case PS2MOUSE_RESEND:
CPRINTS("PS2M Got resend");
send_movement_packet();
break;
case PS2MOUSE_SET_REMOTE_MODE:
mouse_state = PS2MSTATE_REMOTE;
goto SENDACK;
case PS2MOUSE_DISABLE_DATA_REPORT:
data_report_en = false;
goto SENDACK;
case PS2MOUSE_SET_STREAM_MODE:
case PS2MOUSE_ENABLE_DATA_REPORT:
data_report_en = true;
mouse_state = PS2MSTATE_STREAM;
goto SENDACK;
case PS2MOUSE_SET_SAMPLE_RATE:
prev_mouse_state = mouse_state;
mouse_state = PS2MSTATE_CONSUME_1_BYTE_ACK;
goto SENDACK;
case PS2MOUSE_GET_DEVICE_ID:
send_data_byte(PS2MOUSE_ACKNOWLEDGE);
if (five_button_mode) {
send_data_byte(PS2MOUSE_ID_INTELLIMOUSE_5BTN);
} else {
send_data_byte(PS2MOUSE_ID_PS2);
}
break;
case PS2MOUSE_SET_WRAP_MODE:
mouse_state = PS2MSTATE_WRAP;
goto SENDACK;
case PS2MOUSE_STATUS_REQUEST:
send_data_byte(PS2MOUSE_ACKNOWLEDGE);
response = mouse_state == PS2MSTATE_REMOTE ? BIT(6) : 0;
response |= data_report_en ? STATUS_DATA_ENABLED : 0;
send_data_byte(response);
send_data_byte(resolution);
send_data_byte(sample_rate);
break;
case PS2MOUSE_SET_SCALE_2:
mouse_scale = 2;
goto SENDACK;
case PS2MOUSE_SET_SCALE_1:
mouse_scale = 1;
goto SENDACK;
case PS2MOUSE_SET_RESOLUTION:
prev_mouse_state = mouse_state;
mouse_state = PS2MSTATE_CONSUME_1_BYTE_ACK;
goto SENDACK;
case PS2MOUSE_SET_DEFAULTS:
goto SENDACK;
default:
CPRINTS("PS2 unhandled data 0x%x", data);
goto SENDACK;
break;
}
break;
case PS2MSTATE_WRAP:
if (data == PS2MOUSE_RESET || data == PS2MOUSE_RESET_WRAP_MODE) {
mouse_state = PS2MSTATE_RESET;
goto SENDACK;
} else
send_data_byte(data);
break;
default:
CPRINTS("PS2 Invalid state 0x%x", mouse_state);
}
return;
SENDACK:
send_data_byte(PS2MOUSE_ACKNOWLEDGE);
}
/*this interrupt is used to monitor if the main SOC is directly communicating with the
* touchpad outside of the EC. If we detect this condition - then we disable the ec 8042
* mouse emulation mode
* */
void touchpad_i2c_interrupt(enum gpio_signal signal)
{
task_set_event(emumouse_task_id, PS2MOUSE_EVT_I2C_INTERRUPT, 0);
if (power_get_state() == POWER_S0 || power_get_state() == POWER_S0ix)
detected_host_packet = true;
}
/* sometimes we get spurious interrupts from the host? that causes the tp to
* get disabled but the touchpad will attempt to get the host to process
* data by toggling the touchpad interrupt continuously every 100ms or so,
* so we watch for several of these to reenable the touchpad
*/
timestamp_t last_int_time;
int unprocessed_tp_int_count;
void tp_int_count_clear(void)
{
/*
* The touchpad will assert the interrupt when HID driver does the HID reset,
* due to the GPIO_EC_I2C_3_SDA does not have interrupt function, so the
* detected_host_packet does not set to true when HID driver is working.
*
* If we don't clear this count every power on, EC will re-enable the touchpad
* and cause the HID driver yellow bang
*/
unprocessed_tp_int_count = 0;
}
void touchpad_interrupt(enum gpio_signal signal)
{
timestamp_t now = get_time();
if (ec_mode_disabled) {
return;
}
if (!detected_host_packet) {
task_set_event(emumouse_task_id, PS2MOUSE_EVT_INTERRUPT, 0);
unprocessed_tp_int_count = 0;
} else {
if (timestamp_expired(last_int_time, &now)) {
if (unprocessed_tp_int_count++ > TOUCHPAD_I2C_RETRY_COUNT_TO_RENABLE) {
detected_host_packet = false;
unprocessed_tp_int_count = 0;
task_set_event(emumouse_task_id, PS2MOUSE_EVT_REENABLE, 0);
}
} else {
unprocessed_tp_int_count = 0;
}
}
last_int_time.val = now.val + 80*MSEC;
}
static void ps2mouse_powerstate_change(void)
{
task_set_event(emumouse_task_id, PS2MOUSE_EVT_POWERSTATE, 0);
}
DECLARE_HOOK(HOOK_CHIPSET_RESUME,
ps2mouse_powerstate_change,
HOOK_PRIO_DEFAULT);
DECLARE_HOOK(HOOK_CHIPSET_SUSPEND,
ps2mouse_powerstate_change,
HOOK_PRIO_DEFAULT);
/*
* CMD REGISTER
* 0xnXYZ
* X = op code, eg SET_POWER, SET_REPORT, RESET, GET_REPORT
* Y = report type, 0=res, 1=input, 2=output, 3=feature
* Z = Report ID
* setup does the following
* CMD DATA ID
* W 0x0022 0x0233 0x0023 opcode 0x02 - GET_REPORT, report id 0x3 INPUT_MODE_TOUCH, report type 3 - feature
* LEN REPORT
* R 0x0004 0x0503
*
*
* CMD DATA ID
* W 0x0022 0x0234 0x0023 opcode 0x02 - GET_REPORT, report id , report type 3 feature
* LEN REPORT
* R 0x0004 0x0004
*
* The following issue set report opcodes
* CMDREG DATA DATAREG LEN DATA
* W 0x0022 0x0336 0x0023 0x0004 0x0306 opcode 0x03 feature report set configuration register to mode touch
*
* W 0x0022 0x0337 0x0023 0x0004 0x0307 opcode 0x03 feature report set switch mode
*
* W 0x0022 0x0338 0x0023 0x0004 0x0008 opcode 0x03 feature report set latency mode
*
* I think if we want to set mouse mode we would do:
* 0x0022 0x0336 0x0023 0x0004 0x0006 which sets feature report id 6 to input mode mouse
*/
void set_ps2_mouse_emulation(bool disable)
{
if (disable)
task_set_event(emumouse_task_id, PS2MOUSE_EVT_HC_DISABLE, 0);
else
task_set_event(emumouse_task_id, PS2MOUSE_EVT_HC_ENABLE, 0);
}
void set_power(bool standby)
{
uint16_t data = BIT(11) | (standby ? 0x01 : 0x0);
i2c_write_offset16(I2C_PORT_TOUCHPAD,
TOUCHPAD_I2C_HID_EP | I2C_FLAG_ADDR16_LITTLE_ENDIAN, PCT3854_COMMAND, data, 2);
}
void set_reset(void)
{
uint16_t data = BIT(8);
i2c_write_offset16(I2C_PORT_TOUCHPAD,
TOUCHPAD_I2C_HID_EP | I2C_FLAG_ADDR16_LITTLE_ENDIAN, PCT3854_COMMAND, data, 2);
}
void setup_touchpad(void)
{
int rv;
/* These are touchpad firmware dependent
* They set the touchpad into the mouse device mode, instead of PTP mode
* And are based on the HID descriptor for our unique device */
const static uint16_t cmd[4] = {0x0336, 0x0023, 0x0004, 0x0006};
rv = i2c_write_offset16_block(I2C_PORT_TOUCHPAD,
TOUCHPAD_I2C_HID_EP | I2C_FLAG_ADDR16_LITTLE_ENDIAN,
PCT3854_COMMAND,
(void *)cmd, ARRAY_SIZE(cmd) * sizeof(uint16_t));
if (rv == EC_SUCCESS) {
CPRINTS("Touchpad detected!");
}
}
static void retry_tp_read_evt_deferred(void)
{
task_set_event(emumouse_task_id, PS2MOUSE_EVT_INTERRUPT, 0);
}
DECLARE_DEFERRED(retry_tp_read_evt_deferred);
static int inreport_retries;
void read_touchpad_in_report(void)
{
int rv = EC_SUCCESS;
int need_reset = 0;
uint8_t data[128];
int xfer_len = 0;
int report_mode = PS2MOUSE_REPORT_UNKNOWN;
int16_t x, y;
uint8_t response_byte = 0x08;
/* Make sure report id is set to an invalid value */
data[2] = 0;
if (power_get_state() == POWER_S5)
return;
/*dont trigger disable state during our own transactions*/
gpio_disable_interrupt(GPIO_EC_I2C_3_SDA);
/* need to disable SOC_TP_INT_L if we need to setup touchpad */
gpio_disable_interrupt(GPIO_SOC_TP_INT_L);
i2c_set_timeout(I2C_PORT_TOUCHPAD, 25*MSEC);
i2c_lock(I2C_PORT_TOUCHPAD, 1);
rv = i2c_xfer_unlocked(I2C_PORT_TOUCHPAD,
TOUCHPAD_I2C_HID_EP | I2C_FLAG_ADDR16_LITTLE_ENDIAN,
NULL, 0, data, 2, I2C_XFER_START);
if (rv != EC_SUCCESS)
goto read_failed;
xfer_len = (data[1]<<8) + data[0];
if (xfer_len == 0) {
/**
* touchpad has reset per i2c-hid-protocol 7.3
* We need to complete the read protocol to make sure i2c state machine
* is correct.
*/
CPRINTS("PS2M Touchpad need to reset");
xfer_len = 6;
need_reset = 1;
} else if (xfer_len == 7)
report_mode = PS2MOUSE_REPORT_HYBRID;
else if (xfer_len == 8)
report_mode = PS2MOUSE_REPORT_PARALLEL;
xfer_len = MIN(126, xfer_len-2);
rv = i2c_xfer_unlocked(I2C_PORT_TOUCHPAD,
TOUCHPAD_I2C_HID_EP | I2C_FLAG_ADDR16_LITTLE_ENDIAN,
NULL, 0, data+2, xfer_len, I2C_XFER_STOP);
read_failed:
if (rv != EC_SUCCESS) {
/* sometimes we get a read failed for unknown reason to try again in a while
* to recover
*/
inreport_retries++;
if (inreport_retries > 10) {
/* try again some other time later if the TP keeps interrupting us */
detected_host_packet = true;
inreport_retries = 0;
usleep(10*MSEC);
/*The EC SMB controller sometimes gets in a bad state, so try to recover */
MCHP_I2C_CTRL(MCHP_I2C_CTRL4) = BIT(7) |
BIT(6) |
BIT(3) |
BIT(0);
CPRINTS("PS2M %d Too many retries", rv);
} else {
hook_call_deferred(&retry_tp_read_evt_deferred_data, 25*MSEC);
}
} else {
inreport_retries = 0;
}
i2c_lock(I2C_PORT_TOUCHPAD, 0);
gpio_enable_interrupt(GPIO_EC_I2C_3_SDA);
gpio_enable_interrupt(GPIO_SOC_TP_INT_L);
if (mouse_state == PS2MSTATE_RESET) {
return;
}
/* Packet structure:
* first two bytes are length (LSB MSB) including length field?
* 3rd byte is report ID
* rest of the packet is the input report
*/
if (rv == EC_SUCCESS && data[2] == 0x02) {
/*0x0800 02 04 feff 0000
*0x0800 02 04 fdff ffff */
if (report_mode == PS2MOUSE_REPORT_HYBRID) {
if (data[4] & 0x80)
x = (int16_t)(data[4] + (0xff << 8));
else
x = (int16_t)data[4];
if (data[5] & 0x80)
y = -(int16_t)(data[5] + (0xff << 8));
else
y = -(int16_t)data[5];
} else {
x = (int16_t)(data[4] + (data[5] << 8));
y = -(int16_t)(data[6] + (data[7] << 8));
}
x = MIN(255, MAX(x, -255));
y = MIN(255, MAX(y, -255));
/*button data*/
response_byte |= data[3] & 0x03;
if ((x & 0xFFFFFE00) != 0 && (x & 0xFFFFFE00) != 0xFFFFFE00)
response_byte |= X_OVERFLOW;
if (x & 0x100)
response_byte |= X_SIGN;
if ((y & 0xFFFFFE00) != 0 && (y & 0xFFFFFE00) != 0xFFFFFE00)
response_byte |= Y_OVERFLOW;
if (y & 0x100)
response_byte |= Y_SIGN;
/*CPRINTS("Mouse Packet: 0x%02x %d, %d", response_byte, x, y);*/
current_pos[0] = response_byte;
current_pos[1] = x;
current_pos[2] = y;
send_movement_packet();
}
if (need_reset) {
CPRINTS("PS2M Unexpected Report ID %d reconfiguring", data[2]);
setup_touchpad();
need_reset = 0;
}
}
/*
* Looking at timing it takes the SOC about 2ms to grab a tp packet from start of
* packet to interrupt cleared. however the very
* first interrupt triggered by the touchpad may take much longer - I have measured around 25ms
*/
void mouse_interrupt_handler_task(void *p)
{
int power_state = 0;
int evt;
int i;
emumouse_task_id = task_get_current();
while (1) {
evt = task_wait_event(-1);
/*host disabled this*/
if (evt & PS2MOUSE_EVT_HC_DISABLE && ec_mode_disabled == false) {
ec_mode_disabled = true;
CPRINTS("PS2M HC Disable");
tp_int_count_clear();
gpio_disable_interrupt(GPIO_SOC_TP_INT_L);
gpio_disable_interrupt(GPIO_EC_I2C_3_SDA);
}
if (evt & PS2MOUSE_EVT_HC_ENABLE && ec_mode_disabled == true) {
CPRINTS("PS2M HC Enable");
ec_mode_disabled = false;
setup_touchpad();
gpio_enable_interrupt(GPIO_SOC_TP_INT_L);
gpio_enable_interrupt(GPIO_EC_I2C_3_SDA);
}
if (ec_mode_disabled == false) {
if (evt & PS2MOUSE_EVT_AUX_DATA) {
process_request(aux_data);
} else if (evt & PS2MOUSE_EVT_INTERRUPT) {
/* at the expensive of a slight additional latency
* check to see if the soc has grabbed this out from under us
*/
for (i = 0; i < 4; i++) {
usleep(MSEC);
if (gpio_get_level(GPIO_SOC_TP_INT_L) == 1) {
CPRINTS("PS2M Detected host pkt during int");
detected_host_packet = true;
break;
}
}
if (detected_host_packet != true)
read_touchpad_in_report();
}
if (evt & PS2MOUSE_EVT_I2C_INTERRUPT) {
if (detected_host_packet) {
CPRINTS("PS2M detected host packet from i2c");
gpio_disable_interrupt(GPIO_EC_I2C_3_SDA);
}
}
if (evt & PS2MOUSE_EVT_POWERSTATE) {
power_state = power_get_state();
CPRINTS("PS2M Got S0 Event %d", power_state);
if (!ec_mode_disabled &&
(power_state == POWER_S3S0)) {
CPRINTS("PS2M Configuring for ps2 emulation mode");
/*tp takes about 80 ms to come up, wait a bit*/
usleep(200*MSEC);
set_power(false);
set_reset();
setup_touchpad();
gpio_enable_interrupt(GPIO_SOC_TP_INT_L);
gpio_enable_interrupt(GPIO_EC_I2C_3_SDA);
}
if ((power_state == POWER_S3S0) && gpio_get_level(GPIO_SOC_TP_INT_L) == 0) {
read_touchpad_in_report();
}
if (power_state == POWER_S0S3 || power_state == POWER_S5) {
/* Power Down */
set_power(true);
tp_int_count_clear();
gpio_disable_interrupt(GPIO_SOC_TP_INT_L);
gpio_disable_interrupt(GPIO_EC_I2C_3_SDA);
}
}
if (evt & PS2MOUSE_EVT_REENABLE) {
CPRINTS("PS2M renabling");
set_power(false);
set_reset();
setup_touchpad();
gpio_enable_interrupt(GPIO_SOC_TP_INT_L);
gpio_enable_interrupt(GPIO_EC_I2C_3_SDA);
}
}
}
}
static int command_emumouse(int argc, char **argv)
{
int32_t btn_state, x, y, response_byte;
char *e;
if (argc == 2 && !strncmp(argv[1], "int", 3)) {
CPRINTS("Triggering interrupt");
task_set_event(emumouse_task_id, PS2MOUSE_EVT_INTERRUPT, 0);
}
if (argc == 2 && !strncmp(argv[1], "res", 3)) {
CPRINTS("Resetting to auto");
ec_mode_disabled = 0;
data_report_en = 1;
detected_host_packet = true;
task_set_event(emumouse_task_id, PS2MOUSE_EVT_REENABLE, 0);
}
if (argc < 4) {
CPRINTS("mouse state 0x%x data_report: 0x%x btn:0x%x", mouse_state, data_report_en, button_state);
CPRINTS("X:0x%x Y:0x%x Z:0x%x ", current_pos[0], current_pos[1], current_pos[2]);
CPRINTS("Emulation: %s ", ec_mode_disabled ? "Disabled" : "Auto");
CPRINTS("HostCtl: %s ", detected_host_packet ? "Detected" : "Not Detected");
CPRINTS("MouseState %d", mouse_state);
return 0;
}
btn_state = strtoi(argv[1], &e, 0);
if (*e)
return EC_ERROR_PARAM1;
x = strtoi(argv[2], &e, 0);
if (*e)
return EC_ERROR_PARAM2;
y = strtoi(argv[3], &e, 0);
if (*e)
return EC_ERROR_PARAM3;
response_byte = 0x08;
response_byte |= btn_state & 0x03;
if ((x & 0xFFFFFE00) != 0 && (x & 0xFFFFFE00) != 0xFFFFFE00)
response_byte |= X_OVERFLOW;
if (x & 0x100)
response_byte |= X_SIGN;
if ((y & 0xFFFFFE00) != 0 && (y & 0xFFFFFE00) != 0xFFFFFE00)
response_byte |= Y_OVERFLOW;
if (y & 0x100)
response_byte |= Y_SIGN;
current_pos[0] = response_byte;
current_pos[1] = x;
current_pos[2] = y;
button_state = btn_state;
if (mouse_state == PS2MSTATE_STREAM)
send_movement_packet();
return EC_SUCCESS;
}
DECLARE_CONSOLE_COMMAND(emumouse, command_emumouse,
"emumouse buttons posx posy",
"Emulate ps2 mouse events on the 8042 aux channel");