Skip to content

Commit

Permalink
Improve PS/2 mouse performance (qmk#17111)
Browse files Browse the repository at this point in the history
  • Loading branch information
and3rson authored and zykrah committed Jul 2, 2022
1 parent 1baecbf commit fb72d25
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
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

0 comments on commit fb72d25

Please sign in to comment.