diff options
| author | Daniel Kao <daniel.m.kao@gmail.com> | 2023-05-20 05:07:50 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-05-20 22:07:50 +1000 |
| commit | e278715f7f48e6a2e46cb3f4702b2c6eb27eb1d3 (patch) | |
| tree | 225203537a545548f25574c10ff6a882eac11008 /drivers/ps2 | |
| parent | d1395ca4d52ee8c510b5105917f9138a85721548 (diff) | |
Support PS/2 mouse 9-bit output with MOUSE_EXTENDED_REPORT (#20734)
Diffstat (limited to 'drivers/ps2')
| -rw-r--r-- | drivers/ps2/ps2_mouse.c | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/drivers/ps2/ps2_mouse.c b/drivers/ps2/ps2_mouse.c index b32ad1e222..d6911d66f2 100644 --- a/drivers/ps2/ps2_mouse.c +++ b/drivers/ps2/ps2_mouse.c | |||
| @@ -81,10 +81,10 @@ void ps2_mouse_task(void) { | |||
| 81 | rcv = ps2_host_send(PS2_MOUSE_READ_DATA); | 81 | rcv = ps2_host_send(PS2_MOUSE_READ_DATA); |
| 82 | if (rcv == PS2_ACK) { | 82 | if (rcv == PS2_ACK) { |
| 83 | mouse_report.buttons = ps2_host_recv_response(); | 83 | mouse_report.buttons = ps2_host_recv_response(); |
| 84 | mouse_report.x = ps2_host_recv_response() * PS2_MOUSE_X_MULTIPLIER; | 84 | mouse_report.x = ps2_host_recv_response(); |
| 85 | mouse_report.y = ps2_host_recv_response() * PS2_MOUSE_Y_MULTIPLIER; | 85 | mouse_report.y = ps2_host_recv_response(); |
| 86 | # ifdef PS2_MOUSE_ENABLE_SCROLLING | 86 | # ifdef PS2_MOUSE_ENABLE_SCROLLING |
| 87 | mouse_report.v = -(ps2_host_recv_response() & PS2_MOUSE_SCROLL_MASK) * PS2_MOUSE_V_MULTIPLIER; | 87 | mouse_report.v = -(ps2_host_recv_response() & PS2_MOUSE_SCROLL_MASK); |
| 88 | # endif | 88 | # endif |
| 89 | } else { | 89 | } else { |
| 90 | if (debug_mouse) print("ps2_mouse: fail to get mouse packet\n"); | 90 | if (debug_mouse) print("ps2_mouse: fail to get mouse packet\n"); |
| @@ -92,10 +92,10 @@ void ps2_mouse_task(void) { | |||
| 92 | #else | 92 | #else |
| 93 | if (pbuf_has_data()) { | 93 | if (pbuf_has_data()) { |
| 94 | mouse_report.buttons = ps2_host_recv_response(); | 94 | mouse_report.buttons = ps2_host_recv_response(); |
| 95 | mouse_report.x = ps2_host_recv_response() * PS2_MOUSE_X_MULTIPLIER; | 95 | mouse_report.x = ps2_host_recv_response(); |
| 96 | mouse_report.y = ps2_host_recv_response() * PS2_MOUSE_Y_MULTIPLIER; | 96 | mouse_report.y = ps2_host_recv_response(); |
| 97 | # ifdef PS2_MOUSE_ENABLE_SCROLLING | 97 | # ifdef PS2_MOUSE_ENABLE_SCROLLING |
| 98 | mouse_report.v = -(ps2_host_recv_response() & PS2_MOUSE_SCROLL_MASK) * PS2_MOUSE_V_MULTIPLIER; | 98 | mouse_report.v = -(ps2_host_recv_response() & PS2_MOUSE_SCROLL_MASK); |
| 99 | # endif | 99 | # endif |
| 100 | } else { | 100 | } else { |
| 101 | if (debug_mouse) print("ps2_mouse: fail to get mouse packet\n"); | 101 | if (debug_mouse) print("ps2_mouse: fail to get mouse packet\n"); |
| @@ -168,6 +168,7 @@ void ps2_mouse_set_sample_rate(ps2_mouse_sample_rate_t sample_rate) { | |||
| 168 | #define X_IS_OVF (mouse_report->buttons & (1 << PS2_MOUSE_X_OVFLW)) | 168 | #define X_IS_OVF (mouse_report->buttons & (1 << PS2_MOUSE_X_OVFLW)) |
| 169 | #define Y_IS_OVF (mouse_report->buttons & (1 << PS2_MOUSE_Y_OVFLW)) | 169 | #define Y_IS_OVF (mouse_report->buttons & (1 << PS2_MOUSE_Y_OVFLW)) |
| 170 | static inline void ps2_mouse_convert_report_to_hid(report_mouse_t *mouse_report) { | 170 | static inline void ps2_mouse_convert_report_to_hid(report_mouse_t *mouse_report) { |
| 171 | #ifndef MOUSE_EXTENDED_REPORT | ||
| 171 | // PS/2 mouse data is '9-bit integer'(-256 to 255) which is comprised of sign-bit and 8-bit value. | 172 | // PS/2 mouse data is '9-bit integer'(-256 to 255) which is comprised of sign-bit and 8-bit value. |
| 172 | // bit: 8 7 ... 0 | 173 | // bit: 8 7 ... 0 |
| 173 | // sign \8-bit/ | 174 | // sign \8-bit/ |
| @@ -175,8 +176,18 @@ static inline void ps2_mouse_convert_report_to_hid(report_mouse_t *mouse_report) | |||
| 175 | // Meanwhile USB HID mouse indicates 8bit data(-127 to 127), note that -128 is not used. | 176 | // Meanwhile USB HID mouse indicates 8bit data(-127 to 127), note that -128 is not used. |
| 176 | // | 177 | // |
| 177 | // This converts PS/2 data into HID value. Use only -127-127 out of PS/2 9-bit. | 178 | // This converts PS/2 data into HID value. Use only -127-127 out of PS/2 9-bit. |
| 179 | mouse_report->x *= PS2_MOUSE_X_MULTIPLIER; | ||
| 180 | mouse_report->y *= PS2_MOUSE_Y_MULTIPLIER; | ||
| 178 | mouse_report->x = X_IS_NEG ? ((!X_IS_OVF && -127 <= mouse_report->x && mouse_report->x <= -1) ? mouse_report->x : -127) : ((!X_IS_OVF && 0 <= mouse_report->x && mouse_report->x <= 127) ? mouse_report->x : 127); | 181 | mouse_report->x = X_IS_NEG ? ((!X_IS_OVF && -127 <= mouse_report->x && mouse_report->x <= -1) ? mouse_report->x : -127) : ((!X_IS_OVF && 0 <= mouse_report->x && mouse_report->x <= 127) ? mouse_report->x : 127); |
| 179 | mouse_report->y = Y_IS_NEG ? ((!Y_IS_OVF && -127 <= mouse_report->y && mouse_report->y <= -1) ? mouse_report->y : -127) : ((!Y_IS_OVF && 0 <= mouse_report->y && mouse_report->y <= 127) ? mouse_report->y : 127); | 182 | mouse_report->y = Y_IS_NEG ? ((!Y_IS_OVF && -127 <= mouse_report->y && mouse_report->y <= -1) ? mouse_report->y : -127) : ((!Y_IS_OVF && 0 <= mouse_report->y && mouse_report->y <= 127) ? mouse_report->y : 127); |
| 183 | #else | ||
| 184 | // Sign extend if negative, otherwise leave positive 8-bits as-is | ||
| 185 | mouse_report->x = X_IS_NEG ? (mouse_report->x | ~0xFF) : mouse_report->x; | ||
| 186 | mouse_report->y = Y_IS_NEG ? (mouse_report->y | ~0xFF) : mouse_report->y; | ||
| 187 | mouse_report->x *= PS2_MOUSE_X_MULTIPLIER; | ||
| 188 | mouse_report->y *= PS2_MOUSE_Y_MULTIPLIER; | ||
| 189 | #endif | ||
| 190 | mouse_report->v *= PS2_MOUSE_V_MULTIPLIER; | ||
| 180 | 191 | ||
| 181 | #ifdef PS2_MOUSE_INVERT_BUTTONS | 192 | #ifdef PS2_MOUSE_INVERT_BUTTONS |
| 182 | // swap left & right buttons | 193 | // swap left & right buttons |
| @@ -197,8 +208,8 @@ static inline void ps2_mouse_convert_report_to_hid(report_mouse_t *mouse_report) | |||
| 197 | #endif | 208 | #endif |
| 198 | 209 | ||
| 199 | #ifdef PS2_MOUSE_ROTATE | 210 | #ifdef PS2_MOUSE_ROTATE |
| 200 | int8_t x = mouse_report->x; | 211 | mouse_xy_report_t x = mouse_report->x; |
| 201 | int8_t y = mouse_report->y; | 212 | mouse_xy_report_t y = mouse_report->y; |
| 202 | # if PS2_MOUSE_ROTATE == 90 | 213 | # if PS2_MOUSE_ROTATE == 90 |
| 203 | mouse_report->x = y; | 214 | mouse_report->x = y; |
| 204 | mouse_report->y = -x; | 215 | mouse_report->y = -x; |
