Created
August 1, 2024 14:14
-
-
Save axel-angel/12f5c4a4048bc68594854d4673d4af37 to your computer and use it in GitHub Desktop.
QMK PS2 mouse as pointing device so it works for splits
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/drivers/ps2/ps2_mouse.c b/drivers/ps2/ps2_mouse.c | |
index ef1a0e26f9..b2dafb1f3c 100644 | |
--- a/drivers/ps2/ps2_mouse.c | |
+++ b/drivers/ps2/ps2_mouse.c | |
@@ -29,6 +29,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |
/* ============================= MACROS ============================ */ | |
static report_mouse_t mouse_report = {}; | |
+#if defined(POINTING_DEVICE_DRIVER_ps2_mouse) | |
+static report_mouse_t mouse_report_buffer = {}; | |
+#endif | |
static inline void ps2_mouse_print_report(report_mouse_t *mouse_report); | |
static inline void ps2_mouse_convert_report_to_hid(report_mouse_t *mouse_report); | |
@@ -125,7 +128,15 @@ void ps2_mouse_task(void) { | |
// Used to debug the bytes sent to the host | |
ps2_mouse_print_report(&mouse_report); | |
#endif | |
+ | |
+#if defined(POINTING_DEVICE_DRIVER_ps2_mouse) | |
+ mouse_report_buffer.x += mouse_report.x; | |
+ mouse_report_buffer.y += mouse_report.y; | |
+ mouse_report_buffer.h += mouse_report.h; | |
+ mouse_report_buffer.v += mouse_report.v; | |
+#else | |
host_mouse_send(&mouse_report); | |
+#endif | |
} | |
ps2_mouse_clear_report(&mouse_report); | |
@@ -305,7 +316,14 @@ static inline void ps2_mouse_scroll_button_task(report_mouse_t *mouse_report) { | |
#if PS2_MOUSE_SCROLL_BTN_SEND | |
if (scroll_state == SCROLL_BTN && timer_elapsed(scroll_button_time) < PS2_MOUSE_SCROLL_BTN_SEND) { | |
PRESS_SCROLL_BUTTONS; | |
+#if defined(POINTING_DEVICE_DRIVER_ps2_mouse) | |
+ mouse_report_buffer.x += mouse_report->x; | |
+ mouse_report_buffer.y += mouse_report->y; | |
+ mouse_report_buffer.h += mouse_report->h; | |
+ mouse_report_buffer.v += mouse_report->v; | |
+#else | |
host_mouse_send(mouse_report); | |
+#endif | |
wait_ms(100); | |
RELEASE_SCROLL_BUTTONS; | |
} | |
@@ -315,3 +333,11 @@ static inline void ps2_mouse_scroll_button_task(report_mouse_t *mouse_report) { | |
RELEASE_SCROLL_BUTTONS; | |
} | |
+ | |
+void ps2_mouse_accumulated_report(report_mouse_t* destination) { | |
+ destination->x = mouse_report_buffer.x; | |
+ destination->y = mouse_report_buffer.y; | |
+ destination->v = mouse_report_buffer.v; | |
+ destination->h = mouse_report_buffer.h; | |
+ memset(&mouse_report_buffer, 0, sizeof(mouse_report_buffer)); | |
+} | |
diff --git a/drivers/ps2/ps2_mouse.h b/drivers/ps2/ps2_mouse.h | |
index 885eeecbd2..bd17e4f5bc 100644 | |
--- a/drivers/ps2/ps2_mouse.h | |
+++ b/drivers/ps2/ps2_mouse.h | |
@@ -175,3 +175,5 @@ void ps2_mouse_set_resolution(ps2_mouse_resolution_t resolution); | |
void ps2_mouse_set_sample_rate(ps2_mouse_sample_rate_t sample_rate); | |
void ps2_mouse_moved_user(report_mouse_t *mouse_report); | |
+ | |
+void ps2_mouse_accumulated_report(report_mouse_t* destination); | |
diff --git a/quantum/keyboard.c b/quantum/keyboard.c | |
index df1dc1c3ee..58a20570dd 100644 | |
--- a/quantum/keyboard.c | |
+++ b/quantum/keyboard.c | |
@@ -695,6 +695,10 @@ void keyboard_task(void) { | |
} | |
#endif | |
+#ifdef PS2_MOUSE_ENABLE | |
+ ps2_mouse_task(); | |
+#endif | |
+ | |
#ifdef POINTING_DEVICE_ENABLE | |
if (pointing_device_task()) { | |
last_pointing_device_activity_trigger(); | |
@@ -723,10 +727,6 @@ void keyboard_task(void) { | |
mousekey_task(); | |
#endif | |
-#ifdef PS2_MOUSE_ENABLE | |
- ps2_mouse_task(); | |
-#endif | |
- | |
#ifdef MIDI_ENABLE | |
midi_task(); | |
#endif | |
diff --git a/quantum/pointing_device/pointing_device.h b/quantum/pointing_device/pointing_device.h | |
index 1cd4b0b5e6..09f4ee6df9 100644 | |
--- a/quantum/pointing_device/pointing_device.h | |
+++ b/quantum/pointing_device/pointing_device.h | |
@@ -39,6 +39,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |
# include "analog.h" | |
# include "drivers/sensors/analog_joystick.h" | |
# define POINTING_DEVICE_MOTION_PIN_ACTIVE_LOW | |
+#elif defined(POINTING_DEVICE_DRIVER_ps2_mouse) | |
+# include "ps2_mouse.h" | |
#elif defined(POINTING_DEVICE_DRIVER_azoteq_iqs5xx) | |
# include "i2c_master.h" | |
# include "drivers/sensors/azoteq_iqs5xx.h" | |
diff --git a/quantum/pointing_device/pointing_device_drivers.c b/quantum/pointing_device/pointing_device_drivers.c | |
index bf131c6eda..b74b5e32ae 100644 | |
--- a/quantum/pointing_device/pointing_device_drivers.c | |
+++ b/quantum/pointing_device/pointing_device_drivers.c | |
@@ -115,6 +115,26 @@ const pointing_device_driver_t pointing_device_driver = { | |
}; | |
// clang-format on | |
+#elif defined(POINTING_DEVICE_DRIVER_ps2_mouse) | |
+void ps2_mouse_driver_init(void) { } // nothing | |
+ | |
+report_mouse_t ps2_mouse_driver_get_report(report_mouse_t mouse_report) { | |
+ ps2_mouse_accumulated_report(&mouse_report); | |
+ | |
+ pd_dprintf("Raw ] X: %d, Y: %d, V: %d, H: %d\n", mouse_report.x, mouse_report.y, mouse_report.v, mouse_report.h); | |
+ | |
+ return mouse_report; | |
+} | |
+ | |
+// clang-format off | |
+const pointing_device_driver_t pointing_device_driver = { | |
+ .init = ps2_mouse_driver_init, | |
+ .get_report = ps2_mouse_driver_get_report, | |
+ .set_cpi = NULL, | |
+ .get_cpi = NULL | |
+}; | |
+// clang-format on | |
+ | |
#elif defined(POINTING_DEVICE_DRIVER_azoteq_iqs5xx) | |
static i2c_status_t azoteq_iqs5xx_init_status = 1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment