Skip to content

Commit

Permalink
fix mouse sample rate
Browse files Browse the repository at this point in the history
  • Loading branch information
No0ne committed Mar 2, 2024
1 parent c5ff397 commit 0ca3e64
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 7 deletions.
Binary file added ps2x2pico-boot.uf2
Binary file not shown.
Binary file added ps2x2pico-report.uf2
Binary file not shown.
4 changes: 2 additions & 2 deletions src/ps2in.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ void ps2in_task(ps2in* this, ps2out* out) {

printf("%02x %02x\n", this->sm, byte);

if(byte == 0x00 && this->byte_next == 0xaa) {
/* if(byte == 0x00 && this->byte_next == 0xaa) {
pio_sm_put(this->pio, this->sm, ps2_frame(0xf4));
} else { //if(byte != 0xfa) {
queue_try_add(&out->qbytes, &byte);
}
} */

this->byte_next = byte;

Expand Down
43 changes: 39 additions & 4 deletions src/ps2ms.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ ps2in ms_in;
bool ms_streaming = false;
u32 ms_magic_seq = 0;
u8 ms_type = 0;
u8 ms_rate = 60;
u8 ms_db = 0;
s8 ms_dx = 0;
s8 ms_dy = 0;
s8 ms_dz = 0;

void ms_send(u8 byte) {
queue_try_add(&ms_out.qbytes, &byte);
Expand Down Expand Up @@ -79,27 +84,51 @@ void ms_send_packet(u8 buttons, s8 x, s8 y, s8 h, s8 v) {
}
}

s64 ms_send_callback() {
if(!ms_streaming) {
return 0;
}

if(!ms_out.busy) {
ms_send_packet(ms_db, ms_dx, ms_dy, ms_dz, ms_dz);
ms_dx = 0;
ms_dy = 0;
ms_dz = 0;
}

return 1000000 / ms_rate;
}

void ms_usb_receive(u8 const* report) {
ms_send_packet(report[0], report[1], report[2], report[3], report[3]);
ms_db = report[0];
ms_dx += report[1];
ms_dy += report[2];
ms_dz += report[3];
}

void ms_receive(u8 byte, u8 prev_byte) {
switch (prev_byte) {
case 0xf3: // Set Sample Rate
/*ms_magic_seq = ((ms_magic_seq << 8) | byte) & 0xffffff;
ms_rate = byte;
ms_magic_seq = ((ms_magic_seq << 8) | ms_rate) & 0xffffff;

if(ms_type == 0 && ms_magic_seq == 0xc86450) {
ms_type = 3;
} else if(ms_type == 3 && ms_magic_seq == 0xc8c850) {
ms_type = 4;
}*/
}
break;

default:
switch (byte) {
case 0xff: // Reset
ms_streaming = false;
ms_type = 0;
ms_rate = 60;
ms_db = 0;
ms_dx = 0;
ms_dy = 0;
ms_dz = 0;

ms_send(0xfa);
ms_send(0xaa);
Expand All @@ -109,6 +138,11 @@ void ms_receive(u8 byte, u8 prev_byte) {
case 0xf6: // Set Defaults
ms_streaming = false;
ms_type = 0;
ms_rate = 60;
ms_db = 0;
ms_dx = 0;
ms_dy = 0;
ms_dz = 0;
break;

case 0xf5: // Disable Data Reporting
Expand All @@ -118,6 +152,7 @@ void ms_receive(u8 byte, u8 prev_byte) {

case 0xf4: // Enable Data Reporting
ms_streaming = true;
add_alarm_in_ms(100, ms_send_callback, NULL, false);
break;

case 0xf2: // Get Device ID
Expand All @@ -129,7 +164,7 @@ void ms_receive(u8 byte, u8 prev_byte) {
ms_send(0xfa);
ms_send(0x00); // Bit6: Mode, Bit 5: Enable, Bit 4: Scaling, Bits[2,1,0] = Buttons[L,M,R]
ms_send(0x02); // Resolution
ms_send(100); // Sample Rate
ms_send(ms_rate); // Sample Rate
return;

// TODO: Implement (more of) these?
Expand Down
2 changes: 1 addition & 1 deletion src/ps2x2pico.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void tuh_hid_mount_cb(u8 dev_addr, u8 instance, u8 const* desc_report, u16 desc_

case HID_ITF_PROTOCOL_MOUSE:
printf("HID Interface Protocol = Mouse\n");
//tuh_hid_set_protocol(dev_addr, instance, HID_PROTOCOL_REPORT);
tuh_hid_set_protocol(dev_addr, instance, HID_PROTOCOL_REPORT);
tuh_hid_receive_report(dev_addr, instance);
break;
}
Expand Down

0 comments on commit 0ca3e64

Please sign in to comment.