mirror of
https://github.com/dekuNukem/USB4VC.git
synced 2025-10-31 11:26:46 -07:00
removed remote and wrap modes, added duel scroll wheel 5 button intellimouse support
This commit is contained in:
@@ -34,7 +34,6 @@ uint8_t sample_rate_history[SAMPLE_RATE_HISTORY_BUF_SIZE];
|
||||
uint8_t sample_rate_history_index;
|
||||
uint8_t mouse_device_id;
|
||||
uint8_t ps2mouse_current_mode;
|
||||
uint8_t ps2mouse_prev_mode;
|
||||
uint8_t x_accumulator, y_accumulator, scroll_accumulator;
|
||||
|
||||
#define PS2MOUSE_PACKET_SIZE_GENERIC 3
|
||||
@@ -57,22 +56,13 @@ void ps2mouse_release_lines(void)
|
||||
PS2MOUSE_DATA_HI();
|
||||
}
|
||||
|
||||
void reset_accumulators(void)
|
||||
{
|
||||
x_accumulator = 0;
|
||||
y_accumulator = 0;
|
||||
scroll_accumulator = 0;
|
||||
}
|
||||
|
||||
void ps2mouse_restore_defaults(void)
|
||||
{
|
||||
ps2mouse_sampling_rate = 100;
|
||||
ps2mouse_resolution = 2;
|
||||
ps2mouse_scale = 1;
|
||||
ps2mouse_data_reporting_enabled = 1;
|
||||
ps2mouse_data_reporting_enabled = 0;
|
||||
ps2mouse_current_mode = PS2MOUSE_MODE_STREAM;
|
||||
ps2mouse_prev_mode = PS2MOUSE_MODE_STREAM;
|
||||
reset_accumulators();
|
||||
}
|
||||
|
||||
void ps2mouse_reset(void)
|
||||
@@ -190,19 +180,6 @@ void ps2mouse_host_req_reply(uint8_t cmd, mouse_event* mevent)
|
||||
ps2mouse_write(0, PS2MOUSE_WRITE_DEFAULT_TIMEOUT_MS);
|
||||
return;
|
||||
}
|
||||
if(cmd == 0xEC) // reset wrap mode
|
||||
{
|
||||
ps2mouse_current_mode = ps2mouse_prev_mode;
|
||||
reset_accumulators();
|
||||
PS2MOUSE_SENDACK();
|
||||
return;
|
||||
}
|
||||
if(ps2mouse_current_mode == PS2MOUSE_MODE_WRAP)
|
||||
{
|
||||
ps2mouse_write(cmd, PS2MOUSE_WRITE_DEFAULT_TIMEOUT_MS);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
case 0xFE: //resend
|
||||
@@ -214,17 +191,14 @@ void ps2mouse_host_req_reply(uint8_t cmd, mouse_event* mevent)
|
||||
break;
|
||||
case 0xF5: //disable data reporting
|
||||
ps2mouse_data_reporting_enabled = 0;
|
||||
reset_accumulators();
|
||||
PS2MOUSE_SENDACK();
|
||||
break;
|
||||
case 0xF4: //enable data reporting
|
||||
ps2mouse_data_reporting_enabled = 1;
|
||||
reset_accumulators();
|
||||
PS2MOUSE_SENDACK();
|
||||
break;
|
||||
case 0xF3: //set sampling rate
|
||||
PS2MOUSE_SENDACK();
|
||||
reset_accumulators();
|
||||
if(ps2mouse_read(&ps2mouse_sampling_rate, 150) == 0)
|
||||
{
|
||||
sample_rate_history[sample_rate_history_index] = ps2mouse_sampling_rate;
|
||||
@@ -234,35 +208,26 @@ void ps2mouse_host_req_reply(uint8_t cmd, mouse_event* mevent)
|
||||
}
|
||||
break;
|
||||
case 0xF2: //get device id
|
||||
reset_accumulators();
|
||||
PS2MOUSE_SENDACK();
|
||||
mouse_device_id = 0; // standard ps/2 mouse
|
||||
// if (sample_rate_history_index > 2 && sample_rate_history[sample_rate_history_index-1] == 80 && sample_rate_history[sample_rate_history_index-2] == 100 && sample_rate_history[sample_rate_history_index-3] == 200)
|
||||
// mouse_device_id = 3; // intellimouse with scroll wheel
|
||||
if (sample_rate_history_index > 2 && sample_rate_history[sample_rate_history_index-1] == 80 && sample_rate_history[sample_rate_history_index-2] == 100 && sample_rate_history[sample_rate_history_index-3] == 200)
|
||||
mouse_device_id = 3; // intellimouse with scroll wheel
|
||||
if (sample_rate_history_index > 2 && sample_rate_history[sample_rate_history_index-1] == 80 && sample_rate_history[sample_rate_history_index-2] == 200 && sample_rate_history[sample_rate_history_index-3] == 200)
|
||||
mouse_device_id = 4; // intellimouse 5-button scrolling mouse
|
||||
ps2mouse_write(mouse_device_id, PS2MOUSE_WRITE_DEFAULT_TIMEOUT_MS);
|
||||
break;
|
||||
case 0xF0: // set remote mode
|
||||
reset_accumulators();
|
||||
ps2mouse_prev_mode = ps2mouse_current_mode;
|
||||
ps2mouse_current_mode = PS2MOUSE_MODE_REMOTE;
|
||||
PS2MOUSE_SENDACK();
|
||||
ps2mouse_current_mode = PS2MOUSE_MODE_REMOTE;
|
||||
break;
|
||||
case 0xEE: // set wrap mode
|
||||
if(ps2mouse_current_mode != PS2MOUSE_MODE_WRAP)
|
||||
ps2mouse_prev_mode = ps2mouse_current_mode;
|
||||
ps2mouse_current_mode = PS2MOUSE_MODE_WRAP;
|
||||
reset_accumulators();
|
||||
PS2MOUSE_SENDACK();
|
||||
ps2mouse_current_mode = PS2MOUSE_MODE_WRAP;
|
||||
break;
|
||||
case 0xEB: // read data
|
||||
PS2MOUSE_SENDACK();
|
||||
// do stuff
|
||||
reset_accumulators();
|
||||
break;
|
||||
case 0xEA: // set stream mode
|
||||
ps2mouse_prev_mode = ps2mouse_current_mode;
|
||||
ps2mouse_current_mode = PS2MOUSE_MODE_STREAM;
|
||||
reset_accumulators();
|
||||
PS2MOUSE_SENDACK();
|
||||
break;
|
||||
case 0xE9: // status request
|
||||
@@ -282,13 +247,11 @@ void ps2mouse_host_req_reply(uint8_t cmd, mouse_event* mevent)
|
||||
ps2mouse_write(first_byte, PS2MOUSE_WRITE_DEFAULT_TIMEOUT_MS);
|
||||
ps2mouse_write(ps2mouse_resolution, PS2MOUSE_WRITE_DEFAULT_TIMEOUT_MS);
|
||||
ps2mouse_write(ps2mouse_sampling_rate, PS2MOUSE_WRITE_DEFAULT_TIMEOUT_MS);
|
||||
reset_accumulators();
|
||||
break;
|
||||
case 0xE8: // set resolution
|
||||
PS2MOUSE_SENDACK();
|
||||
if(ps2mouse_read(&ps2mouse_resolution, 150) == 0)
|
||||
PS2MOUSE_SENDACK();
|
||||
reset_accumulators();
|
||||
break;
|
||||
case 0xE6: // reset scale
|
||||
PS2MOUSE_SENDACK();
|
||||
@@ -305,17 +268,10 @@ void ps2mouse_host_req_reply(uint8_t cmd, mouse_event* mevent)
|
||||
|
||||
uint8_t ps2mouse_get_outgoing_data(mouse_event* this_event, ps2_outgoing_buf* pbuf)
|
||||
{
|
||||
if(ps2mouse_current_mode == PS2MOUSE_MODE_REMOTE)
|
||||
{
|
||||
x_accumulator += (uint8_t)(this_event->movement_x);
|
||||
y_accumulator += (uint8_t)(this_event->movement_y);
|
||||
scroll_accumulator += (uint8_t)(this_event->scroll_vertical);
|
||||
return 1;
|
||||
}
|
||||
if(ps2mouse_current_mode == PS2MOUSE_MODE_WRAP)
|
||||
return 2;
|
||||
if(ps2mouse_data_reporting_enabled == 0)
|
||||
return 3;
|
||||
return PS2_ERROR_REPORTING_DISABLED;
|
||||
if(ps2mouse_current_mode != PS2MOUSE_MODE_STREAM)
|
||||
return PS2_ERROR_UNIMPLEMENTED_MODE;
|
||||
|
||||
memset(pbuf->data, 0, PS2_OUT_BUF_MAXSIZE);
|
||||
pbuf->size = PS2MOUSE_PACKET_SIZE_GENERIC;
|
||||
@@ -333,7 +289,27 @@ uint8_t ps2mouse_get_outgoing_data(mouse_event* this_event, ps2_outgoing_buf* pb
|
||||
pbuf->data[0] = pbuf->data[0] | 0x20;
|
||||
pbuf->data[1] = (uint8_t)(this_event->movement_x);
|
||||
pbuf->data[2] = (uint8_t)(this_event->movement_y);
|
||||
pbuf->data[3] = (uint8_t)(this_event->scroll_vertical);
|
||||
if(mouse_device_id == 3) // 3 button intellimouse with 1 scroll wheel
|
||||
{
|
||||
pbuf->data[3] = (uint8_t)(this_event->scroll_vertical);
|
||||
}
|
||||
else if(mouse_device_id == 4) // 5 button intellimouse with 2 scroll wheels
|
||||
{
|
||||
if(this_event->button_side)
|
||||
pbuf->data[3] = pbuf->data[3] | 0x10;
|
||||
if(this_event->button_extra)
|
||||
pbuf->data[3] = pbuf->data[3] | 0x20;
|
||||
|
||||
if(this_event->scroll_horizontal > 0)
|
||||
pbuf->data[3] = pbuf->data[3] | 0x2;
|
||||
else if(this_event->scroll_horizontal < 0)
|
||||
pbuf->data[3] = pbuf->data[3] | 0xe;
|
||||
|
||||
if(this_event->scroll_vertical > 0)
|
||||
pbuf->data[3] = pbuf->data[3] | 0x1;
|
||||
else if(this_event->scroll_vertical < 0)
|
||||
pbuf->data[3] = pbuf->data[3] | 0xf;
|
||||
}
|
||||
if(mouse_device_id != 0)
|
||||
pbuf->size = PS2MOUSE_PACKET_SIZE_INTELLIMOUSE;
|
||||
return PS2_OK;
|
||||
@@ -402,11 +378,6 @@ uint8_t ps2mouse_write_nowait(uint8_t data)
|
||||
delay_us(CLKFULL);
|
||||
PS2MOUSE_CLK_HI();
|
||||
delay_us(CLKHALF);
|
||||
// if(PS2MOUSE_READ_CLK_PIN() == GPIO_PIN_RESET)
|
||||
// {
|
||||
// ps2mouse_release_lines();
|
||||
// return PS2_ERROR_HOST_INHIBIT;
|
||||
// }
|
||||
delay_us(BYTEWAIT_END);
|
||||
return PS2_OK;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user