Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve PS/2 mouse performance #17111

Merged
merged 2 commits into from
May 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions drivers/ps2/ps2.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ uint8_t ps2_host_send(uint8_t data);
uint8_t ps2_host_recv_response(void);
uint8_t ps2_host_recv(void);
void ps2_host_set_led(uint8_t usb_led);
bool pbuf_has_data(void);

/*--------------------------------------------------------------------
* static functions
Expand Down
4 changes: 2 additions & 2 deletions drivers/ps2/ps2_interrupt.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ uint8_t ps2_error = PS2_ERR_NONE;

static inline uint8_t pbuf_dequeue(void);
static inline void pbuf_enqueue(uint8_t data);
static inline bool pbuf_has_data(void);
static inline void pbuf_clear(void);
bool pbuf_has_data(void);

#if defined(PROTOCOL_CHIBIOS)
void ps2_interrupt_service_routine(void);
Expand Down Expand Up @@ -309,7 +309,7 @@ static inline uint8_t pbuf_dequeue(void) {

return val;
}
static inline bool pbuf_has_data(void) {
bool pbuf_has_data(void) {
#if defined(__AVR__)
uint8_t sreg = SREG;
cli();
Expand Down
19 changes: 17 additions & 2 deletions drivers/ps2/ps2_mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ void ps2_mouse_init(void) {
ps2_mouse_set_remote_mode();
#else
ps2_mouse_enable_data_reporting();
ps2_mouse_set_stream_mode();
#endif

#ifdef PS2_MOUSE_ENABLE_SCROLLING
Expand All @@ -75,19 +76,33 @@ void ps2_mouse_task(void) {
extern int tp_buttons;

/* receives packet from mouse */
#ifdef PS2_MOUSE_USE_REMOTE_MODE
uint8_t rcv;
rcv = ps2_host_send(PS2_MOUSE_READ_DATA);
if (rcv == PS2_ACK) {
mouse_report.buttons = ps2_host_recv_response() | tp_buttons;
mouse_report.x = ps2_host_recv_response() * PS2_MOUSE_X_MULTIPLIER;
mouse_report.y = ps2_host_recv_response() * PS2_MOUSE_Y_MULTIPLIER;
#ifdef PS2_MOUSE_ENABLE_SCROLLING
# ifdef PS2_MOUSE_ENABLE_SCROLLING
mouse_report.v = -(ps2_host_recv_response() & PS2_MOUSE_SCROLL_MASK) * PS2_MOUSE_V_MULTIPLIER;
#endif
# endif
} else {
if (debug_mouse) print("ps2_mouse: fail to get mouse packet\n");
return;
}
#else
if (pbuf_has_data()) {
mouse_report.buttons = ps2_host_recv_response() | tp_buttons;
mouse_report.x = ps2_host_recv_response() * PS2_MOUSE_X_MULTIPLIER;
mouse_report.y = ps2_host_recv_response() * PS2_MOUSE_Y_MULTIPLIER;
# ifdef PS2_MOUSE_ENABLE_SCROLLING
mouse_report.v = -(ps2_host_recv_response() & PS2_MOUSE_SCROLL_MASK) * PS2_MOUSE_V_MULTIPLIER;
# endif
} else {
if (debug_mouse) print("ps2_mouse: fail to get mouse packet\n");
return;
}
#endif

/* if mouse moves or buttons state changes */
if (mouse_report.x || mouse_report.y || mouse_report.v || ((mouse_report.buttons ^ buttons_prev) & PS2_MOUSE_BTN_MASK)) {
Expand Down
4 changes: 2 additions & 2 deletions platforms/avr/drivers/ps2/ps2_usart.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ uint8_t ps2_error = PS2_ERR_NONE;

static inline uint8_t pbuf_dequeue(void);
static inline void pbuf_enqueue(uint8_t data);
static inline bool pbuf_has_data(void);
static inline void pbuf_clear(void);
bool pbuf_has_data(void);

void ps2_host_init(void) {
idle(); // without this many USART errors occur when cable is disconnected
Expand Down Expand Up @@ -212,7 +212,7 @@ static inline uint8_t pbuf_dequeue(void) {

return val;
}
static inline bool pbuf_has_data(void) {
bool pbuf_has_data(void) {
uint8_t sreg = SREG;
cli();
bool has_data = (pbuf_head != pbuf_tail);
Expand Down