diff --git a/drivers/ps2/ps2_mouse.c b/drivers/ps2/ps2_mouse.c index 19a84e41c2d1..04acf7804621 100644 --- a/drivers/ps2/ps2_mouse.c +++ b/drivers/ps2/ps2_mouse.c @@ -27,7 +27,7 @@ along with this program. If not, see . #include "pointing_device.h" #include "pointing_device_internal.h" -/* ============================= MACROS ============================ */ +/* ============================= HELPERS ============================ */ static inline void ps2_mouse_convert_report_to_hid(ps2_mouse_report_t *ps2_report, report_mouse_t *mouse_report); static inline void ps2_mouse_enable_scrolling(void); @@ -149,6 +149,42 @@ void ps2_mouse_set_sample_rate(ps2_mouse_sample_rate_t sample_rate) { PS2_MOUSE_SET_SAFE(PS2_MOUSE_SET_SAMPLE_RATE, sample_rate, "ps2 mouse set sample rate"); } +/* Note: PS/2 mouse uses counts/mm */ +uint16_t ps2_mouse_get_cpi(void) { + uint8_t rcv, cpm; + rcv = ps2_host_send(PS2_MOUSE_STATUS_REQUEST); + if (rcv == PS2_ACK) { + rcv = ps2_host_recv_response(); + cpm = ps2_host_recv_response(); + rcv = ps2_host_recv_response(); + + return (1 << cpm); + } + + return 0; +} + +/* Note: PS/2 mouse uses counts/mm */ +void ps2_mouse_set_cpi(uint16_t cpi) { + switch (cpi) { + case 1: + ps2_mouse_set_resolution(PS2_MOUSE_1_COUNT_MM); + break; + case 2: + ps2_mouse_set_resolution(PS2_MOUSE_2_COUNT_MM); + break; + case 4: + ps2_mouse_set_resolution(PS2_MOUSE_4_COUNT_MM); + break; + case 8: + ps2_mouse_set_resolution(PS2_MOUSE_8_COUNT_MM); + break; + default: + pd_dprintf("ps2_mouse: invalid cpi: %u\n", cpi); + break; + } +} + /* ============================= HELPERS ============================ */ #define min(a,b) ((a)<(b)?(a):(b)) @@ -178,6 +214,7 @@ static inline void ps2_mouse_convert_report_to_hid(ps2_mouse_report_t *ps2_repor mouse_report->y = -mouse_report->y; #ifdef PS2_MOUSE_ENABLE_SCROLLING + // Valid z values are in the range -8 to +7 mouse_report->v = -(ps2_report->z & PS2_MOUSE_SCROLL_MASK); mouse_report->v *= PS2_MOUSE_V_MULTIPLIER; #endif @@ -210,38 +247,3 @@ static inline void ps2_mouse_enable_scrolling(void) { wait_ms(20); } -/* Note: PS/2 mouse uses counts/mm */ -uint16_t ps2_mouse_get_cpi(void) { - uint8_t rcv, cpm; - rcv = ps2_host_send(PS2_MOUSE_STATUS_REQUEST); - if (rcv == PS2_ACK) { - rcv = ps2_host_recv_response(); - cpm = ps2_host_recv_response(); - rcv = ps2_host_recv_response(); - - return (1 << cpm); - } - - return 0; -} - -/* Note: PS/2 mouse uses counts/mm */ -void ps2_mouse_set_cpi(uint16_t cpi) { - switch (cpi) { - case 1: - ps2_mouse_set_resolution(PS2_MOUSE_1_COUNT_MM); - break; - case 2: - ps2_mouse_set_resolution(PS2_MOUSE_2_COUNT_MM); - break; - case 4: - ps2_mouse_set_resolution(PS2_MOUSE_4_COUNT_MM); - break; - case 8: - ps2_mouse_set_resolution(PS2_MOUSE_8_COUNT_MM); - break; - default: - pd_dprintf("ps2_mouse: invalid cpi: %u\n", cpi); - break; - } -}