Improve PS/2 mouse performance (#17111)

master
Andrew Dunai 2022-05-31 09:15:17 +03:00 committed by GitHub
parent d44a950c10
commit ecce9900c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 6 deletions

View File

@ -89,6 +89,7 @@ uint8_t ps2_host_send(uint8_t data);
uint8_t ps2_host_recv_response(void); uint8_t ps2_host_recv_response(void);
uint8_t ps2_host_recv(void); uint8_t ps2_host_recv(void);
void ps2_host_set_led(uint8_t usb_led); void ps2_host_set_led(uint8_t usb_led);
bool pbuf_has_data(void);
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
* static functions * static functions

View File

@ -66,8 +66,8 @@ uint8_t ps2_error = PS2_ERR_NONE;
static inline uint8_t pbuf_dequeue(void); static inline uint8_t pbuf_dequeue(void);
static inline void pbuf_enqueue(uint8_t data); static inline void pbuf_enqueue(uint8_t data);
static inline bool pbuf_has_data(void);
static inline void pbuf_clear(void); static inline void pbuf_clear(void);
bool pbuf_has_data(void);
#if defined(PROTOCOL_CHIBIOS) #if defined(PROTOCOL_CHIBIOS)
void ps2_interrupt_service_routine(void); void ps2_interrupt_service_routine(void);
@ -309,7 +309,7 @@ static inline uint8_t pbuf_dequeue(void) {
return val; return val;
} }
static inline bool pbuf_has_data(void) { bool pbuf_has_data(void) {
#if defined(__AVR__) #if defined(__AVR__)
uint8_t sreg = SREG; uint8_t sreg = SREG;
cli(); cli();

View File

@ -53,6 +53,7 @@ void ps2_mouse_init(void) {
ps2_mouse_set_remote_mode(); ps2_mouse_set_remote_mode();
#else #else
ps2_mouse_enable_data_reporting(); ps2_mouse_enable_data_reporting();
ps2_mouse_set_stream_mode();
#endif #endif
#ifdef PS2_MOUSE_ENABLE_SCROLLING #ifdef PS2_MOUSE_ENABLE_SCROLLING
@ -75,6 +76,7 @@ void ps2_mouse_task(void) {
extern int tp_buttons; extern int tp_buttons;
/* receives packet from mouse */ /* receives packet from mouse */
#ifdef PS2_MOUSE_USE_REMOTE_MODE
uint8_t rcv; uint8_t rcv;
rcv = ps2_host_send(PS2_MOUSE_READ_DATA); rcv = ps2_host_send(PS2_MOUSE_READ_DATA);
if (rcv == PS2_ACK) { if (rcv == PS2_ACK) {
@ -88,6 +90,19 @@ void ps2_mouse_task(void) {
if (debug_mouse) print("ps2_mouse: fail to get mouse packet\n"); if (debug_mouse) print("ps2_mouse: fail to get mouse packet\n");
return; 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 moves or buttons state changes */
if (mouse_report.x || mouse_report.y || mouse_report.v || ((mouse_report.buttons ^ buttons_prev) & PS2_MOUSE_BTN_MASK)) { if (mouse_report.x || mouse_report.y || mouse_report.v || ((mouse_report.buttons ^ buttons_prev) & PS2_MOUSE_BTN_MASK)) {

View File

@ -72,8 +72,8 @@ uint8_t ps2_error = PS2_ERR_NONE;
static inline uint8_t pbuf_dequeue(void); static inline uint8_t pbuf_dequeue(void);
static inline void pbuf_enqueue(uint8_t data); static inline void pbuf_enqueue(uint8_t data);
static inline bool pbuf_has_data(void);
static inline void pbuf_clear(void); static inline void pbuf_clear(void);
bool pbuf_has_data(void);
void ps2_host_init(void) { void ps2_host_init(void) {
idle(); // without this many USART errors occur when cable is disconnected idle(); // without this many USART errors occur when cable is disconnected
@ -212,7 +212,7 @@ static inline uint8_t pbuf_dequeue(void) {
return val; return val;
} }
static inline bool pbuf_has_data(void) { bool pbuf_has_data(void) {
uint8_t sreg = SREG; uint8_t sreg = SREG;
cli(); cli();
bool has_data = (pbuf_head != pbuf_tail); bool has_data = (pbuf_head != pbuf_tail);