From 2f9a26d670a7072af5ff4308cdcb0674cf3dc603 Mon Sep 17 00:00:00 2001 From: daskygit <32983009+daskygit@users.noreply.github.com> Date: Thu, 25 Nov 2021 21:57:29 +0000 Subject: [PATCH 01/25] Draft implementation --- quantum/pointing_device.c | 60 +++++++++++++++++++- quantum/split_common/transaction_id_define.h | 4 ++ quantum/split_common/transactions.c | 36 ++++++++++++ quantum/split_common/transactions.h | 3 + quantum/split_common/transport.h | 8 +++ 5 files changed, 109 insertions(+), 2 deletions(-) diff --git a/quantum/pointing_device.c b/quantum/pointing_device.c index 2fefdb67b6af..2482e16052aa 100644 --- a/quantum/pointing_device.c +++ b/quantum/pointing_device.c @@ -24,6 +24,11 @@ #if (defined(POINTING_DEVICE_ROTATION_90) + defined(POINTING_DEVICE_ROTATION_180) + defined(POINTING_DEVICE_ROTATION_270)) > 1 # error More than one rotation selected. This is not supported. #endif +#if defined(SPLIT_POINTING_ENABLE) +# include "transactions.h" +# include "keyboard.h" +# include "timer.h" +#endif static report_mouse_t mouseReport = {}; @@ -71,13 +76,64 @@ __attribute__((weak)) void pointing_device_send(void) { } __attribute__((weak)) void pointing_device_task(void) { +#if defined(SPLIT_POINTING_ENABLE) + // Don't poll the target side pointing device. + if (!is_keyboard_master()) { + return; + }; +#endif + +#if defined(POINTING_DEVICE_TASK_THROTTLE) + static uint32_t last_exec = 0; + if (timer_elapsed32(last_exec) < 1) { + return; + } + last_exec = timer_read32(); +#else +# if defined(SPLIT_POINTING_ENABLE) +# pragma message("It's recommended you enable a throttle when sharing pointing devices.") +# endif +#endif + // Gather report info #ifdef POINTING_DEVICE_MOTION_PIN +# if defined(SPLIT_POINTING_ENABLE) +# error POINTING_DEVICE_MOTION_PIN not supported when sharing the pointing device report between sides. +# endif if (!readPin(POINTING_DEVICE_MOTION_PIN)) #endif - mouseReport = pointing_device_driver.get_report(mouseReport); - // Support rotation of the sensor data +#if defined(SPLIT_POINTING_ENABLE) +# if defined(POINTING_DEVICE_COMBINED) + static report_mouse_t sharedReport = {0}; + mouseReport.buttons = mouseReport.buttons | ~sharedReport.buttons; + mouseReport = pointing_device_driver.get_report(mouseReport); + sharedReport = get_targets_pointing(); + mouseReport.x = mouseReport.x | sharedReport.x; + mouseReport.y = mouseReport.y | sharedReport.y; + mouseReport.h = mouseReport.h | sharedReport.h; + mouseReport.v = mouseReport.v | sharedReport.v; + mouseReport.buttons = mouseReport.buttons | sharedReport.buttons; +# elif defined(POINTING_DEVICE_LEFT) + if (is_keyboard_left()) { + mouseReport = pointing_device_driver.get_report(mouseReport); + } else { + mouseReport = get_targets_pointing(); + } +# elif defined(POINTING_DEVICE_RIGHT) + if (!is_keyboard_left()) { + mouseReport = pointing_device_driver.get_report(mouseReport); + } else { + mouseReport = get_targets_pointing(); + } +# else +# error "You need to define the side(s) the pointing device is on. POINTING_DEVICE_COMBINED / POINTING_DEVICE_LEFT / POINTING_DEVICE_RIGHT" +# endif +#else + mouseReport = pointing_device_driver.get_report(mouseReport); +#endif // defined(SPLIT_POINTING_ENABLE) + + // Support rotation of the sensor data #if defined(POINTING_DEVICE_ROTATION_90) || defined(POINTING_DEVICE_ROTATION_180) || defined(POINTING_DEVICE_ROTATION_270) int8_t x = mouseReport.x, y = mouseReport.y; # if defined(POINTING_DEVICE_ROTATION_90) diff --git a/quantum/split_common/transaction_id_define.h b/quantum/split_common/transaction_id_define.h index 535bc21aeaa1..7c4ebe0ee748 100644 --- a/quantum/split_common/transaction_id_define.h +++ b/quantum/split_common/transaction_id_define.h @@ -78,6 +78,10 @@ enum serial_transaction_id { PUT_ST7565, #endif // defined(ST7565_ENABLE) && defined(SPLIT_ST7565_ENABLE) +#if defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE) + GET_POINTING, +#endif // defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE) + #if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) PUT_RPC_INFO, PUT_RPC_REQ_DATA, diff --git a/quantum/split_common/transactions.c b/quantum/split_common/transactions.c index 3ff87710e7e4..d2ca46ce0811 100644 --- a/quantum/split_common/transactions.c +++ b/quantum/split_common/transactions.c @@ -578,6 +578,41 @@ static void st7565_handlers_slave(matrix_row_t master_matrix[], matrix_row_t sla #endif // defined(ST7565_ENABLE) && defined(SPLIT_ST7565_ENABLE) +//////////////////////////////////////////////////// +// POINTING + +#if defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE) + +extern const pointing_device_driver_t pointing_device_driver; + +report_mouse_t get_targets_pointing(void) { + report_mouse_t temp = {0}; + + // Prevent transaction attempts while transport is disconnected + if (!is_transport_connected()) { + return temp; + } + + if (!transport_execute_transaction(GET_POINTING, NULL, 0, &temp, sizeof(report_mouse_t))) { + dprintf("Failed to execute pointing devices transaction."); + } + return temp; +} + +static void pointing_handlers_slave(uint8_t initiator2target_buffer_size, const void *initiator2target_buffer, uint8_t target2initiator_buffer_size, void *target2initiator_buffer) { + report_mouse_t temp = {0}; + temp = pointing_device_driver.get_report(temp); + memcpy(target2initiator_buffer, &temp, sizeof(report_mouse_t)); +} + +# define TRANSACTIONS_POINTING_REGISTRATIONS [GET_POINTING] = trans_target2initiator_initializer_cb(current_pointing_state, pointing_handlers_slave), + +#else // defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE) + +# define TRANSACTIONS_POINTING_REGISTRATIONS + +#endif // defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE) + //////////////////////////////////////////////////// uint8_t dummy; @@ -604,6 +639,7 @@ split_transaction_desc_t split_transaction_table[NUM_TOTAL_TRANSACTIONS] = { TRANSACTIONS_WPM_REGISTRATIONS TRANSACTIONS_OLED_REGISTRATIONS TRANSACTIONS_ST7565_REGISTRATIONS + TRANSACTIONS_POINTING_REGISTRATIONS // clang-format on #if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) diff --git a/quantum/split_common/transactions.h b/quantum/split_common/transactions.h index 53610d6f8e85..ea4f511a1ffa 100644 --- a/quantum/split_common/transactions.h +++ b/quantum/split_common/transactions.h @@ -22,6 +22,7 @@ #include "matrix.h" #include "transaction_id_define.h" #include "transport.h" +#include "report.h" typedef void (*slave_callback_t)(uint8_t initiator2target_buffer_size, const void *initiator2target_buffer, uint8_t target2initiator_buffer_size, void *target2initiator_buffer); @@ -52,3 +53,5 @@ bool transaction_rpc_exec(int8_t transaction_id, uint8_t initiator2target_buffer #define transaction_rpc_send(transaction_id, initiator2target_buffer_size, initiator2target_buffer) transaction_rpc_exec(transaction_id, initiator2target_buffer_size, initiator2target_buffer, 0, NULL) #define transaction_rpc_recv(transaction_id, target2initiator_buffer_size, target2initiator_buffer) transaction_rpc_exec(transaction_id, 0, NULL, target2initiator_buffer_size, target2initiator_buffer) + +report_mouse_t get_targets_pointing(void); diff --git a/quantum/split_common/transport.h b/quantum/split_common/transport.h index 1d4f6ed0cd86..fe7a613f06a6 100644 --- a/quantum/split_common/transport.h +++ b/quantum/split_common/transport.h @@ -106,6 +106,10 @@ typedef struct _split_mods_sync_t { } split_mods_sync_t; #endif // SPLIT_MODS_ENABLE +#if defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE) +#include "pointing_device.h" +#endif // defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE) + #if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) typedef struct _rpc_sync_info_t { int8_t transaction_id; @@ -173,6 +177,10 @@ typedef struct _split_shared_memory_t { uint8_t current_st7565_state; #endif // ST7565_ENABLE(OLED_ENABLE) && defined(SPLIT_ST7565_ENABLE) +#if defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE) + report_mouse_t current_pointing_state; +#endif // defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE) + #if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) rpc_sync_info_t rpc_info; uint8_t rpc_m2s_buffer[RPC_M2S_BUFFER_SIZE]; From f470758c1e3a3b608d53161fb95c8c4af7fa29b8 Mon Sep 17 00:00:00 2001 From: daskygit <32983009+daskygit@users.noreply.github.com> Date: Thu, 25 Nov 2021 22:37:03 +0000 Subject: [PATCH 02/25] formatting --- quantum/split_common/transactions.c | 6 +++--- quantum/split_common/transport.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/quantum/split_common/transactions.c b/quantum/split_common/transactions.c index d2ca46ce0811..e59317056c97 100644 --- a/quantum/split_common/transactions.c +++ b/quantum/split_common/transactions.c @@ -600,9 +600,9 @@ report_mouse_t get_targets_pointing(void) { } static void pointing_handlers_slave(uint8_t initiator2target_buffer_size, const void *initiator2target_buffer, uint8_t target2initiator_buffer_size, void *target2initiator_buffer) { - report_mouse_t temp = {0}; - temp = pointing_device_driver.get_report(temp); - memcpy(target2initiator_buffer, &temp, sizeof(report_mouse_t)); + report_mouse_t temp = {0}; + temp = pointing_device_driver.get_report(temp); + memcpy(target2initiator_buffer, &temp, sizeof(report_mouse_t)); } # define TRANSACTIONS_POINTING_REGISTRATIONS [GET_POINTING] = trans_target2initiator_initializer_cb(current_pointing_state, pointing_handlers_slave), diff --git a/quantum/split_common/transport.h b/quantum/split_common/transport.h index fe7a613f06a6..323a77c0c9f4 100644 --- a/quantum/split_common/transport.h +++ b/quantum/split_common/transport.h @@ -107,7 +107,7 @@ typedef struct _split_mods_sync_t { #endif // SPLIT_MODS_ENABLE #if defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE) -#include "pointing_device.h" +# include "pointing_device.h" #endif // defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE) #if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) From a213a7f5b96419f958576f4b402ac7a44592c3a8 Mon Sep 17 00:00:00 2001 From: daskygit <32983009+daskygit@users.noreply.github.com> Date: Thu, 25 Nov 2021 22:59:02 +0000 Subject: [PATCH 03/25] fix combined buttons --- quantum/pointing_device.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/quantum/pointing_device.c b/quantum/pointing_device.c index 2482e16052aa..25f58b03ca50 100644 --- a/quantum/pointing_device.c +++ b/quantum/pointing_device.c @@ -106,14 +106,16 @@ __attribute__((weak)) void pointing_device_task(void) { #if defined(SPLIT_POINTING_ENABLE) # if defined(POINTING_DEVICE_COMBINED) static report_mouse_t sharedReport = {0}; - mouseReport.buttons = mouseReport.buttons | ~sharedReport.buttons; - mouseReport = pointing_device_driver.get_report(mouseReport); - sharedReport = get_targets_pointing(); - mouseReport.x = mouseReport.x | sharedReport.x; - mouseReport.y = mouseReport.y | sharedReport.y; - mouseReport.h = mouseReport.h | sharedReport.h; - mouseReport.v = mouseReport.v | sharedReport.v; - mouseReport.buttons = mouseReport.buttons | sharedReport.buttons; + static uint8_t oldButtons = 0; + mouseReport.buttons = oldButtons; + mouseReport = pointing_device_driver.get_report(mouseReport); + sharedReport = get_targets_pointing(); + oldButtons = mouseReport.buttons; + mouseReport.x = mouseReport.x | sharedReport.x; + mouseReport.y = mouseReport.y | sharedReport.y; + mouseReport.h = mouseReport.h | sharedReport.h; + mouseReport.v = mouseReport.v | sharedReport.v; + mouseReport.buttons = mouseReport.buttons | sharedReport.buttons; # elif defined(POINTING_DEVICE_LEFT) if (is_keyboard_left()) { mouseReport = pointing_device_driver.get_report(mouseReport); From 1f9ad3e0d9180b4444bce4cb07bf144aefb95f47 Mon Sep 17 00:00:00 2001 From: daskygit <32983009+daskygit@users.noreply.github.com> Date: Mon, 29 Nov 2021 17:53:14 +0000 Subject: [PATCH 04/25] remove pimoroni throttle --- docs/feature_pointing_device.md | 1 - drivers/sensors/pimoroni_trackball.h | 3 --- quantum/pointing_device_drivers.c | 4 +--- 3 files changed, 1 insertion(+), 7 deletions(-) diff --git a/docs/feature_pointing_device.md b/docs/feature_pointing_device.md index 5aef9bea2729..efcff32eccfa 100644 --- a/docs/feature_pointing_device.md +++ b/docs/feature_pointing_device.md @@ -128,7 +128,6 @@ The Pimoroni Trackball module is a I2C based breakout board with an RGB enable t |-------------------------------------|------------------------------------------------------------------------------------|---------| |`PIMORONI_TRACKBALL_ADDRESS` | (Required) Sets the I2C Address for the Pimoroni Trackball. | `0x0A` | |`PIMORONI_TRACKBALL_TIMEOUT` | (Optional) The timeout for i2c communication with the trackpad in milliseconds. | `100` | -|`PIMORONI_TRACKBALL_INTERVAL_MS` | (Optional) The update/read interval for the sensor in milliseconds. | `8` | |`PIMORONI_TRACKBALL_SCALE` | (Optional) The multiplier used to generate reports from the sensor. | `5` | |`PIMORONI_TRACKBALL_DEBOUNCE_CYCLES` | (Optional) The number of scan cycles used for debouncing on the ball press. | `20` | |`PIMORONI_TRACKBALL_ERROR_COUNT` | (Optional) Specifies the number of read/write errors until the sensor is disabled. | `10` | diff --git a/drivers/sensors/pimoroni_trackball.h b/drivers/sensors/pimoroni_trackball.h index 59ee8724ba66..3960b30ecf72 100644 --- a/drivers/sensors/pimoroni_trackball.h +++ b/drivers/sensors/pimoroni_trackball.h @@ -23,9 +23,6 @@ #ifndef PIMORONI_TRACKBALL_ADDRESS # define PIMORONI_TRACKBALL_ADDRESS 0x0A #endif -#ifndef PIMORONI_TRACKBALL_INTERVAL_MS -# define PIMORONI_TRACKBALL_INTERVAL_MS 8 -#endif #ifndef PIMORONI_TRACKBALL_SCALE # define PIMORONI_TRACKBALL_SCALE 5 #endif diff --git a/quantum/pointing_device_drivers.c b/quantum/pointing_device_drivers.c index 9ad5e76ba634..c51a756ed85d 100644 --- a/quantum/pointing_device_drivers.c +++ b/quantum/pointing_device_drivers.c @@ -166,13 +166,12 @@ const pointing_device_driver_t pointing_device_driver = { #elif defined(POINTING_DEVICE_DRIVER_pimoroni_trackball) report_mouse_t pimorono_trackball_get_report(report_mouse_t mouse_report) { - static fast_timer_t throttle = 0; static uint16_t debounce = 0; static uint8_t error_count = 0; pimoroni_data_t pimoroni_data = {0}; static int16_t x_offset = 0, y_offset = 0; - if (error_count < PIMORONI_TRACKBALL_ERROR_COUNT && timer_elapsed_fast(throttle) >= PIMORONI_TRACKBALL_INTERVAL_MS) { + if (error_count < PIMORONI_TRACKBALL_ERROR_COUNT) { i2c_status_t status = read_pimoroni_trackball(&pimoroni_data); if (status == I2C_STATUS_SUCCESS) { @@ -195,7 +194,6 @@ report_mouse_t pimorono_trackball_get_report(report_mouse_t mouse_report) { } else { error_count++; } - throttle = timer_read_fast(); } return mouse_report; } From 74b77289eeb830afdd61696b2307735f64059c2e Mon Sep 17 00:00:00 2001 From: daskygit <32983009+daskygit@users.noreply.github.com> Date: Mon, 29 Nov 2021 19:04:02 +0000 Subject: [PATCH 05/25] sync pointing on a throttle loop with checksum --- quantum/pointing_device.c | 30 +++++++------ quantum/pointing_device.h | 1 + quantum/split_common/transaction_id_define.h | 3 +- quantum/split_common/transactions.c | 46 ++++++++++++-------- quantum/split_common/transport.h | 6 ++- 5 files changed, 52 insertions(+), 34 deletions(-) diff --git a/quantum/pointing_device.c b/quantum/pointing_device.c index 25f58b03ca50..b5934334b1b6 100644 --- a/quantum/pointing_device.c +++ b/quantum/pointing_device.c @@ -18,6 +18,7 @@ #include "pointing_device.h" #include +#include "timer.h" #ifdef MOUSEKEY_ENABLE # include "mousekey.h" #endif @@ -27,7 +28,10 @@ #if defined(SPLIT_POINTING_ENABLE) # include "transactions.h" # include "keyboard.h" -# include "timer.h" + +report_mouse_t sharedReport = {}; + +void pointing_device_set_shared_report(report_mouse_t report) { sharedReport = report; } #endif static report_mouse_t mouseReport = {}; @@ -83,9 +87,9 @@ __attribute__((weak)) void pointing_device_task(void) { }; #endif -#if defined(POINTING_DEVICE_TASK_THROTTLE) +#if defined(POINTING_DEVICE_TASK_THROTTLE_MS) static uint32_t last_exec = 0; - if (timer_elapsed32(last_exec) < 1) { + if (timer_elapsed32(last_exec) < POINTING_DEVICE_TASK_THROTTLE_MS) { return; } last_exec = timer_read32(); @@ -105,17 +109,15 @@ __attribute__((weak)) void pointing_device_task(void) { #if defined(SPLIT_POINTING_ENABLE) # if defined(POINTING_DEVICE_COMBINED) - static report_mouse_t sharedReport = {0}; - static uint8_t oldButtons = 0; - mouseReport.buttons = oldButtons; - mouseReport = pointing_device_driver.get_report(mouseReport); - sharedReport = get_targets_pointing(); - oldButtons = mouseReport.buttons; - mouseReport.x = mouseReport.x | sharedReport.x; - mouseReport.y = mouseReport.y | sharedReport.y; - mouseReport.h = mouseReport.h | sharedReport.h; - mouseReport.v = mouseReport.v | sharedReport.v; - mouseReport.buttons = mouseReport.buttons | sharedReport.buttons; + static uint8_t oldButtons = 0; + mouseReport.buttons = oldButtons; + mouseReport = pointing_device_driver.get_report(mouseReport); + oldButtons = mouseReport.buttons; + mouseReport.x = mouseReport.x | sharedReport.x; + mouseReport.y = mouseReport.y | sharedReport.y; + mouseReport.h = mouseReport.h | sharedReport.h; + mouseReport.v = mouseReport.v | sharedReport.v; + mouseReport.buttons = mouseReport.buttons | sharedReport.buttons; # elif defined(POINTING_DEVICE_LEFT) if (is_keyboard_left()) { mouseReport = pointing_device_driver.get_report(mouseReport); diff --git a/quantum/pointing_device.h b/quantum/pointing_device.h index 5106c26660e7..648bd8316741 100644 --- a/quantum/pointing_device.h +++ b/quantum/pointing_device.h @@ -77,6 +77,7 @@ void pointing_device_task(void); void pointing_device_send(void); report_mouse_t pointing_device_get_report(void); void pointing_device_set_report(report_mouse_t newMouseReport); +void pointing_device_set_shared_report(report_mouse_t report); bool has_mouse_report_changed(report_mouse_t new, report_mouse_t old); uint16_t pointing_device_get_cpi(void); void pointing_device_set_cpi(uint16_t cpi); diff --git a/quantum/split_common/transaction_id_define.h b/quantum/split_common/transaction_id_define.h index 7c4ebe0ee748..172a7f9a2249 100644 --- a/quantum/split_common/transaction_id_define.h +++ b/quantum/split_common/transaction_id_define.h @@ -79,7 +79,8 @@ enum serial_transaction_id { #endif // defined(ST7565_ENABLE) && defined(SPLIT_ST7565_ENABLE) #if defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE) - GET_POINTING, + GET_POINTING_CHECKSUM, + GET_POINTING_DATA, #endif // defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE) #if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) diff --git a/quantum/split_common/transactions.c b/quantum/split_common/transactions.c index e59317056c97..c4d6e9b3929c 100644 --- a/quantum/split_common/transactions.c +++ b/quantum/split_common/transactions.c @@ -583,32 +583,40 @@ static void st7565_handlers_slave(matrix_row_t master_matrix[], matrix_row_t sla #if defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE) -extern const pointing_device_driver_t pointing_device_driver; - -report_mouse_t get_targets_pointing(void) { - report_mouse_t temp = {0}; +static bool pointing_handlers_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { + static uint32_t last_update = 0; + report_mouse_t temp_state; + bool okay = read_if_checksum_mismatch(GET_POINTING_CHECKSUM, GET_POINTING_DATA, &last_update, &temp_state, &split_shmem->pointing.report, sizeof(temp_state)); + if (okay) pointing_device_set_shared_report(temp_state); + return okay; +} - // Prevent transaction attempts while transport is disconnected - if (!is_transport_connected()) { - return temp; - } +extern const pointing_device_driver_t pointing_device_driver; - if (!transport_execute_transaction(GET_POINTING, NULL, 0, &temp, sizeof(report_mouse_t))) { - dprintf("Failed to execute pointing devices transaction."); +static void pointing_handlers_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { + report_mouse_t temp_report; +# ifdef POINTING_DEVICE_TASK_THROTTLE_MS + static uint32_t last_exec = 0; + if (timer_elapsed32(last_exec) < POINTING_DEVICE_TASK_THROTTLE_MS) { + return; } - return temp; -} - -static void pointing_handlers_slave(uint8_t initiator2target_buffer_size, const void *initiator2target_buffer, uint8_t target2initiator_buffer_size, void *target2initiator_buffer) { - report_mouse_t temp = {0}; - temp = pointing_device_driver.get_report(temp); - memcpy(target2initiator_buffer, &temp, sizeof(report_mouse_t)); + last_exec = timer_read32(); +# endif + memset(&temp_report, 0, sizeof(temp_report)); + temp_report = pointing_device_driver.get_report(temp_report); + memcpy(&split_shmem->pointing.report, &temp_report, sizeof(temp_report)); + // Now update the checksum given that the pointing has been written to + split_shmem->pointing.checksum = crc8(&temp_report, sizeof(temp_report)); } -# define TRANSACTIONS_POINTING_REGISTRATIONS [GET_POINTING] = trans_target2initiator_initializer_cb(current_pointing_state, pointing_handlers_slave), +# define TRANSACTIONS_POINTING_MASTER() TRANSACTION_HANDLER_MASTER(pointing) +# define TRANSACTIONS_POINTING_SLAVE() TRANSACTION_HANDLER_SLAVE(pointing) +# define TRANSACTIONS_POINTING_REGISTRATIONS [GET_POINTING_CHECKSUM] = trans_target2initiator_initializer(pointing.checksum), [GET_POINTING_DATA] = trans_target2initiator_initializer(pointing.report), #else // defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE) +# define TRANSACTIONS_POINTING_MASTER() +# define TRANSACTIONS_POINTING_SLAVE() # define TRANSACTIONS_POINTING_REGISTRATIONS #endif // defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE) @@ -665,6 +673,7 @@ bool transactions_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix TRANSACTIONS_WPM_MASTER(); TRANSACTIONS_OLED_MASTER(); TRANSACTIONS_ST7565_MASTER(); + TRANSACTIONS_POINTING_MASTER(); return true; } @@ -683,6 +692,7 @@ void transactions_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[ TRANSACTIONS_WPM_SLAVE(); TRANSACTIONS_OLED_SLAVE(); TRANSACTIONS_ST7565_SLAVE(); + TRANSACTIONS_POINTING_SLAVE(); } #if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) diff --git a/quantum/split_common/transport.h b/quantum/split_common/transport.h index 323a77c0c9f4..b7a7b9681671 100644 --- a/quantum/split_common/transport.h +++ b/quantum/split_common/transport.h @@ -108,6 +108,10 @@ typedef struct _split_mods_sync_t { #if defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE) # include "pointing_device.h" +typedef struct _split_slave_pointing_sync_t { + uint8_t checksum; + report_mouse_t report; +} split_slave_pointing_sync_t; #endif // defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE) #if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) @@ -178,7 +182,7 @@ typedef struct _split_shared_memory_t { #endif // ST7565_ENABLE(OLED_ENABLE) && defined(SPLIT_ST7565_ENABLE) #if defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE) - report_mouse_t current_pointing_state; + split_slave_pointing_sync_t pointing; #endif // defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE) #if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) From 56efb00fc5bcb88c4621d70459a8761eb6eb2879 Mon Sep 17 00:00:00 2001 From: Dasky <32983009+daskygit@users.noreply.github.com> Date: Mon, 29 Nov 2021 19:20:26 +0000 Subject: [PATCH 06/25] no longer used --- quantum/split_common/transactions.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/quantum/split_common/transactions.h b/quantum/split_common/transactions.h index ea4f511a1ffa..53610d6f8e85 100644 --- a/quantum/split_common/transactions.h +++ b/quantum/split_common/transactions.h @@ -22,7 +22,6 @@ #include "matrix.h" #include "transaction_id_define.h" #include "transport.h" -#include "report.h" typedef void (*slave_callback_t)(uint8_t initiator2target_buffer_size, const void *initiator2target_buffer, uint8_t target2initiator_buffer_size, void *target2initiator_buffer); @@ -53,5 +52,3 @@ bool transaction_rpc_exec(int8_t transaction_id, uint8_t initiator2target_buffer #define transaction_rpc_send(transaction_id, initiator2target_buffer_size, initiator2target_buffer) transaction_rpc_exec(transaction_id, initiator2target_buffer_size, initiator2target_buffer, 0, NULL) #define transaction_rpc_recv(transaction_id, target2initiator_buffer_size, target2initiator_buffer) transaction_rpc_exec(transaction_id, 0, NULL, target2initiator_buffer_size, target2initiator_buffer) - -report_mouse_t get_targets_pointing(void); From 08fbde223562be747d84c35aa8912368fa11c0c7 Mon Sep 17 00:00:00 2001 From: Dasky <32983009+daskygit@users.noreply.github.com> Date: Mon, 29 Nov 2021 21:57:47 +0000 Subject: [PATCH 07/25] doh Co-authored-by: Drashna Jaelre --- quantum/pointing_device.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/quantum/pointing_device.c b/quantum/pointing_device.c index b5934334b1b6..82db563c4862 100644 --- a/quantum/pointing_device.c +++ b/quantum/pointing_device.c @@ -122,13 +122,13 @@ __attribute__((weak)) void pointing_device_task(void) { if (is_keyboard_left()) { mouseReport = pointing_device_driver.get_report(mouseReport); } else { - mouseReport = get_targets_pointing(); + mouseReport = sharedReport; } # elif defined(POINTING_DEVICE_RIGHT) if (!is_keyboard_left()) { mouseReport = pointing_device_driver.get_report(mouseReport); } else { - mouseReport = get_targets_pointing(); + mouseReport = sharedReport; } # else # error "You need to define the side(s) the pointing device is on. POINTING_DEVICE_COMBINED / POINTING_DEVICE_LEFT / POINTING_DEVICE_RIGHT" From f622f25c15d48fab773f1c2e2bb967e3053c83b8 Mon Sep 17 00:00:00 2001 From: daskygit <32983009+daskygit@users.noreply.github.com> Date: Mon, 29 Nov 2021 22:51:53 +0000 Subject: [PATCH 08/25] switch pimoroni to a cpi equivalent --- drivers/sensors/pimoroni_trackball.c | 3 +++ drivers/sensors/pimoroni_trackball.h | 4 ++-- quantum/pointing_device_drivers.c | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/sensors/pimoroni_trackball.c b/drivers/sensors/pimoroni_trackball.c index 7d390056ead4..5b6711460287 100644 --- a/drivers/sensors/pimoroni_trackball.c +++ b/drivers/sensors/pimoroni_trackball.c @@ -33,6 +33,9 @@ static uint16_t precision = 128; +uint16_t pimoroni_trackball_get_cpi(void) { return (precision * 125); } +void pimoroni_trackball_set_cpi(uint16_t cpi) { precision = (cpi / 125); } + float pimoroni_trackball_get_precision(void) { return ((float)precision / 128); } void pimoroni_trackball_set_precision(float floatprecision) { precision = (floatprecision * 128); } diff --git a/drivers/sensors/pimoroni_trackball.h b/drivers/sensors/pimoroni_trackball.h index 3960b30ecf72..e3400375f6b6 100644 --- a/drivers/sensors/pimoroni_trackball.h +++ b/drivers/sensors/pimoroni_trackball.h @@ -53,6 +53,6 @@ void pimironi_trackball_device_init(void); void pimoroni_trackball_set_rgbw(uint8_t red, uint8_t green, uint8_t blue, uint8_t white); int16_t pimoroni_trackball_get_offsets(uint8_t negative_dir, uint8_t positive_dir, uint8_t scale); void pimoroni_trackball_adapt_values(int8_t* mouse, int16_t* offset); -float pimoroni_trackball_get_precision(void); -void pimoroni_trackball_set_precision(float precision); +uint16_t pimoroni_trackball_get_cpi(void); +void pimoroni_trackball_set_cpi(uint16_t cpi); i2c_status_t read_pimoroni_trackball(pimoroni_data_t* data); diff --git a/quantum/pointing_device_drivers.c b/quantum/pointing_device_drivers.c index c51a756ed85d..24592bfa5447 100644 --- a/quantum/pointing_device_drivers.c +++ b/quantum/pointing_device_drivers.c @@ -202,8 +202,8 @@ report_mouse_t pimorono_trackball_get_report(report_mouse_t mouse_report) { const pointing_device_driver_t pointing_device_driver = { .init = pimironi_trackball_device_init, .get_report = pimorono_trackball_get_report, - .set_cpi = NULL, - .get_cpi = NULL + .set_cpi = pimoroni_trackball_set_cpi, + .get_cpi = pimoroni_trackball_get_cpi }; // clang-format on #elif defined(POINTING_DEVICE_DRIVER_pmw3360) From 2e55a742d2e0adc46994bd8fcdfbbfc024815b9f Mon Sep 17 00:00:00 2001 From: daskygit <32983009+daskygit@users.noreply.github.com> Date: Tue, 30 Nov 2021 01:35:23 +0000 Subject: [PATCH 09/25] add cpi support --- quantum/pointing_device.c | 50 ++++++++++++++++++-- quantum/pointing_device.h | 2 + quantum/split_common/transaction_id_define.h | 1 + quantum/split_common/transactions.c | 17 ++++++- quantum/split_common/transport.h | 1 + 5 files changed, 66 insertions(+), 5 deletions(-) diff --git a/quantum/pointing_device.c b/quantum/pointing_device.c index 82db563c4862..fdde5c8351bd 100644 --- a/quantum/pointing_device.c +++ b/quantum/pointing_device.c @@ -30,9 +30,20 @@ # include "keyboard.h" report_mouse_t sharedReport = {}; +uint16_t sharedCpi = 0; -void pointing_device_set_shared_report(report_mouse_t report) { sharedReport = report; } -#endif +void pointing_device_set_shared_report(report_mouse_t report) { sharedReport = report; } +uint16_t pointing_device_get_shared_cpi(void) { return sharedCpi; } + +# if defined(POINTING_DEVICE_LEFT) +# define POINTING_DEVICE_THIS_SIDE is_keyboard_left() +# elif defined(POINTING_DEVICE_RIGHT) +# define POINTING_DEVICE_THIS_SIDE !is_keyboard_left() +# elif defined(POINTING_DEVICE_COMBINED) +# define POINTING_DEVICE_THIS_SIDE true +# endif + +#endif // defined(SPLIT_POINTING_ENABLE) static report_mouse_t mouseReport = {}; @@ -175,6 +186,37 @@ report_mouse_t pointing_device_get_report(void) { return mouseReport; } void pointing_device_set_report(report_mouse_t newMouseReport) { mouseReport = newMouseReport; } -uint16_t pointing_device_get_cpi(void) { return pointing_device_driver.get_cpi(); } +uint16_t pointing_device_get_cpi(void) { +#if defined(SPLIT_POINTING_ENABLE) + if (POINTING_DEVICE_THIS_SIDE) { + return pointing_device_driver.get_cpi(); + } else { + return sharedCpi; + } +#else + return pointing_device_driver.get_cpi(); +#endif +} -void pointing_device_set_cpi(uint16_t cpi) { pointing_device_driver.set_cpi(cpi); } +void pointing_device_set_cpi(uint16_t cpi) { +#if defined(SPLIT_POINTING_ENABLE) + if (POINTING_DEVICE_THIS_SIDE) { + pointing_device_driver.set_cpi(cpi); + } else { + sharedCpi = cpi; + } +#else + pointing_device_driver.set_cpi(cpi); +#endif +} + +#if defined(SPLIT_POINTING_ENABLE) && defined(POINTING_DEVICE_COMBINED) +void pointing_device_set_cpi_on_side(bool left, uint16_t cpi) { + bool local = (is_keyboard_left() & left) ? true : false; + if (local) { + pointing_device_driver.set_cpi(cpi); + } else { + sharedCpi = cpi; + } +} +#endif diff --git a/quantum/pointing_device.h b/quantum/pointing_device.h index 648bd8316741..fde74d739985 100644 --- a/quantum/pointing_device.h +++ b/quantum/pointing_device.h @@ -78,9 +78,11 @@ void pointing_device_send(void); report_mouse_t pointing_device_get_report(void); void pointing_device_set_report(report_mouse_t newMouseReport); void pointing_device_set_shared_report(report_mouse_t report); +uint16_t pointing_device_get_shared_cpi(void); bool has_mouse_report_changed(report_mouse_t new, report_mouse_t old); uint16_t pointing_device_get_cpi(void); void pointing_device_set_cpi(uint16_t cpi); +void pointing_device_set_cpi_on_side(bool left, uint16_t cpi); void pointing_device_init_kb(void); void pointing_device_init_user(void); diff --git a/quantum/split_common/transaction_id_define.h b/quantum/split_common/transaction_id_define.h index 172a7f9a2249..aa71c3621e7a 100644 --- a/quantum/split_common/transaction_id_define.h +++ b/quantum/split_common/transaction_id_define.h @@ -81,6 +81,7 @@ enum serial_transaction_id { #if defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE) GET_POINTING_CHECKSUM, GET_POINTING_DATA, + PUT_POINTING_CPI, #endif // defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE) #if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) diff --git a/quantum/split_common/transactions.c b/quantum/split_common/transactions.c index c4d6e9b3929c..6b258f6b537c 100644 --- a/quantum/split_common/transactions.c +++ b/quantum/split_common/transactions.c @@ -585,9 +585,19 @@ static void st7565_handlers_slave(matrix_row_t master_matrix[], matrix_row_t sla static bool pointing_handlers_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { static uint32_t last_update = 0; + static uint16_t last_cpi = 0; report_mouse_t temp_state; + uint16_t temp_cpi; bool okay = read_if_checksum_mismatch(GET_POINTING_CHECKSUM, GET_POINTING_DATA, &last_update, &temp_state, &split_shmem->pointing.report, sizeof(temp_state)); if (okay) pointing_device_set_shared_report(temp_state); + temp_cpi = pointing_device_get_shared_cpi(); + if (temp_cpi&& memcmp(&last_cpi, &temp_cpi, sizeof(temp_cpi)) != 0) { + memcpy(&split_shmem->pointing.cpi, &temp_cpi, sizeof(temp_cpi)); + okay = transport_write(PUT_POINTING_CPI, &split_shmem->pointing.cpi, sizeof(split_shmem->pointing.cpi)); + if (okay) { + last_cpi = temp_cpi; + } + } return okay; } @@ -595,6 +605,7 @@ extern const pointing_device_driver_t pointing_device_driver; static void pointing_handlers_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { report_mouse_t temp_report; + uint16_t temp_cpi; # ifdef POINTING_DEVICE_TASK_THROTTLE_MS static uint32_t last_exec = 0; if (timer_elapsed32(last_exec) < POINTING_DEVICE_TASK_THROTTLE_MS) { @@ -602,6 +613,10 @@ static void pointing_handlers_slave(matrix_row_t master_matrix[], matrix_row_t s } last_exec = timer_read32(); # endif + temp_cpi = pointing_device_driver.get_cpi(); + if (split_shmem->pointing.cpi && memcmp(&split_shmem->pointing.cpi, &temp_cpi, sizeof(temp_cpi)) != 0) { + pointing_device_driver.set_cpi(split_shmem->pointing.cpi); + } memset(&temp_report, 0, sizeof(temp_report)); temp_report = pointing_device_driver.get_report(temp_report); memcpy(&split_shmem->pointing.report, &temp_report, sizeof(temp_report)); @@ -611,7 +626,7 @@ static void pointing_handlers_slave(matrix_row_t master_matrix[], matrix_row_t s # define TRANSACTIONS_POINTING_MASTER() TRANSACTION_HANDLER_MASTER(pointing) # define TRANSACTIONS_POINTING_SLAVE() TRANSACTION_HANDLER_SLAVE(pointing) -# define TRANSACTIONS_POINTING_REGISTRATIONS [GET_POINTING_CHECKSUM] = trans_target2initiator_initializer(pointing.checksum), [GET_POINTING_DATA] = trans_target2initiator_initializer(pointing.report), +# define TRANSACTIONS_POINTING_REGISTRATIONS [GET_POINTING_CHECKSUM] = trans_target2initiator_initializer(pointing.checksum), [GET_POINTING_DATA] = trans_target2initiator_initializer(pointing.report), [PUT_POINTING_CPI] = trans_initiator2target_initializer(pointing.cpi), #else // defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE) diff --git a/quantum/split_common/transport.h b/quantum/split_common/transport.h index b7a7b9681671..31b804908b94 100644 --- a/quantum/split_common/transport.h +++ b/quantum/split_common/transport.h @@ -111,6 +111,7 @@ typedef struct _split_mods_sync_t { typedef struct _split_slave_pointing_sync_t { uint8_t checksum; report_mouse_t report; + uint16_t cpi; } split_slave_pointing_sync_t; #endif // defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE) From f48ddd148413bd2eab9d06cacfeebf0d8f0c60a0 Mon Sep 17 00:00:00 2001 From: daskygit <32983009+daskygit@users.noreply.github.com> Date: Wed, 1 Dec 2021 13:33:50 +0000 Subject: [PATCH 10/25] allow user modification of seperate mouse reports --- quantum/pointing_device.c | 21 ++++++++++++++++----- quantum/pointing_device.h | 14 +++++++++++--- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/quantum/pointing_device.c b/quantum/pointing_device.c index fdde5c8351bd..a4aa1df78cc0 100644 --- a/quantum/pointing_device.c +++ b/quantum/pointing_device.c @@ -124,11 +124,6 @@ __attribute__((weak)) void pointing_device_task(void) { mouseReport.buttons = oldButtons; mouseReport = pointing_device_driver.get_report(mouseReport); oldButtons = mouseReport.buttons; - mouseReport.x = mouseReport.x | sharedReport.x; - mouseReport.y = mouseReport.y | sharedReport.y; - mouseReport.h = mouseReport.h | sharedReport.h; - mouseReport.v = mouseReport.v | sharedReport.v; - mouseReport.buttons = mouseReport.buttons | sharedReport.buttons; # elif defined(POINTING_DEVICE_LEFT) if (is_keyboard_left()) { mouseReport = pointing_device_driver.get_report(mouseReport); @@ -173,7 +168,11 @@ __attribute__((weak)) void pointing_device_task(void) { #endif // allow kb to intercept and modify report +#if defined(SPLIT_POINTING_ENABLE) && defined (POINTING_DEVICE_COMBINED) + mouseReport = is_keyboard_left() ? pointing_device_task_combined_kb(mouseReport, sharedReport) : pointing_device_task_combined_kb(sharedReport, mouseReport); +#else mouseReport = pointing_device_task_kb(mouseReport); +#endif // combine with mouse report to ensure that the combined is sent correctly #ifdef MOUSEKEY_ENABLE report_mouse_t mousekey_report = mousekey_get_report(); @@ -219,4 +218,16 @@ void pointing_device_set_cpi_on_side(bool left, uint16_t cpi) { sharedCpi = cpi; } } +report_mouse_t pointing_device_combine_reports(report_mouse_t left_report, report_mouse_t right_report) { + left_report.x |= right_report.x; + left_report.y |= right_report.y; + left_report.h |= right_report.h; + left_report.v |= right_report.v; + left_report.buttons |= right_report.buttons; + return left_report; +} + +__attribute__((weak)) report_mouse_t pointing_device_task_combined_kb(report_mouse_t left_report, report_mouse_t right_report) { return pointing_device_task_combined_user(left_report, right_report); } +__attribute__((weak)) report_mouse_t pointing_device_task_combined_user(report_mouse_t left_report, report_mouse_t right_report) { return pointing_device_combine_reports(left_report, right_report); } + #endif diff --git a/quantum/pointing_device.h b/quantum/pointing_device.h index fde74d739985..4c77042248c0 100644 --- a/quantum/pointing_device.h +++ b/quantum/pointing_device.h @@ -77,15 +77,23 @@ void pointing_device_task(void); void pointing_device_send(void); report_mouse_t pointing_device_get_report(void); void pointing_device_set_report(report_mouse_t newMouseReport); -void pointing_device_set_shared_report(report_mouse_t report); -uint16_t pointing_device_get_shared_cpi(void); bool has_mouse_report_changed(report_mouse_t new, report_mouse_t old); uint16_t pointing_device_get_cpi(void); void pointing_device_set_cpi(uint16_t cpi); -void pointing_device_set_cpi_on_side(bool left, uint16_t cpi); void pointing_device_init_kb(void); void pointing_device_init_user(void); report_mouse_t pointing_device_task_kb(report_mouse_t mouse_report); report_mouse_t pointing_device_task_user(report_mouse_t mouse_report); uint8_t pointing_device_handle_buttons(uint8_t buttons, bool pressed, pointing_device_buttons_t button); + +#if defined(SPLIT_POINTING_ENABLE) +void pointing_device_set_shared_report(report_mouse_t report); +uint16_t pointing_device_get_shared_cpi(void); +# if defined(POINTING_DEVICE_COMBINED) +void pointing_device_set_cpi_on_side(bool left, uint16_t cpi); +report_mouse_t pointing_device_combine_reports(report_mouse_t left_report, report_mouse_t right_report); +report_mouse_t pointing_device_task_combined_kb(report_mouse_t left_report, report_mouse_t right_report); +report_mouse_t pointing_device_task_combined_user(report_mouse_t left_report, report_mouse_t right_report); +# endif //defined(POINTING_DEVICE_COMBINED) +#endif //defined(SPLIT_POINTING_ENABLE) From 1a07aee19562d955627e3d6674cf9bb8d884b192 Mon Sep 17 00:00:00 2001 From: daskygit <32983009+daskygit@users.noreply.github.com> Date: Wed, 1 Dec 2021 15:31:11 +0000 Subject: [PATCH 11/25] a little tidy up --- quantum/pointing_device.c | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/quantum/pointing_device.c b/quantum/pointing_device.c index a4aa1df78cc0..ee5a2c59bc4a 100644 --- a/quantum/pointing_device.c +++ b/quantum/pointing_device.c @@ -124,18 +124,8 @@ __attribute__((weak)) void pointing_device_task(void) { mouseReport.buttons = oldButtons; mouseReport = pointing_device_driver.get_report(mouseReport); oldButtons = mouseReport.buttons; -# elif defined(POINTING_DEVICE_LEFT) - if (is_keyboard_left()) { - mouseReport = pointing_device_driver.get_report(mouseReport); - } else { - mouseReport = sharedReport; - } -# elif defined(POINTING_DEVICE_RIGHT) - if (!is_keyboard_left()) { - mouseReport = pointing_device_driver.get_report(mouseReport); - } else { - mouseReport = sharedReport; - } +# elif defined(POINTING_DEVICE_LEFT) || defined(POINTING_DEVICE_RIGHT) + mouseReport = POINTING_DEVICE_THIS_SIDE ? pointing_device_driver.get_report(mouseReport) : mouseReport = sharedReport; # else # error "You need to define the side(s) the pointing device is on. POINTING_DEVICE_COMBINED / POINTING_DEVICE_LEFT / POINTING_DEVICE_RIGHT" # endif @@ -168,7 +158,7 @@ __attribute__((weak)) void pointing_device_task(void) { #endif // allow kb to intercept and modify report -#if defined(SPLIT_POINTING_ENABLE) && defined (POINTING_DEVICE_COMBINED) +#if defined(SPLIT_POINTING_ENABLE) && defined(POINTING_DEVICE_COMBINED) mouseReport = is_keyboard_left() ? pointing_device_task_combined_kb(mouseReport, sharedReport) : pointing_device_task_combined_kb(sharedReport, mouseReport); #else mouseReport = pointing_device_task_kb(mouseReport); @@ -187,11 +177,7 @@ void pointing_device_set_report(report_mouse_t newMouseReport) { mouseReport = n uint16_t pointing_device_get_cpi(void) { #if defined(SPLIT_POINTING_ENABLE) - if (POINTING_DEVICE_THIS_SIDE) { - return pointing_device_driver.get_cpi(); - } else { - return sharedCpi; - } + return POINTING_DEVICE_THIS_SIDE ? pointing_device_driver.get_cpi() : sharedCpi; #else return pointing_device_driver.get_cpi(); #endif @@ -218,11 +204,12 @@ void pointing_device_set_cpi_on_side(bool left, uint16_t cpi) { sharedCpi = cpi; } } + report_mouse_t pointing_device_combine_reports(report_mouse_t left_report, report_mouse_t right_report) { - left_report.x |= right_report.x; - left_report.y |= right_report.y; - left_report.h |= right_report.h; - left_report.v |= right_report.v; + left_report.x |= right_report.x; + left_report.y |= right_report.y; + left_report.h |= right_report.h; + left_report.v |= right_report.v; left_report.buttons |= right_report.buttons; return left_report; } From 170e8c2657dbf413e2fdf89c936d0ad8a0e4b47b Mon Sep 17 00:00:00 2001 From: daskygit <32983009+daskygit@users.noreply.github.com> Date: Wed, 1 Dec 2021 19:59:51 +0000 Subject: [PATCH 12/25] add *_RIGHT defines. --- quantum/pointing_device.c | 93 +++++++++++++++++++++++++++------------ quantum/pointing_device.h | 2 + 2 files changed, 67 insertions(+), 28 deletions(-) diff --git a/quantum/pointing_device.c b/quantum/pointing_device.c index ee5a2c59bc4a..66689e800721 100644 --- a/quantum/pointing_device.c +++ b/quantum/pointing_device.c @@ -90,6 +90,33 @@ __attribute__((weak)) void pointing_device_send(void) { memcpy(&old_report, &mouseReport, sizeof(mouseReport)); } +report_mouse_t pointing_device_adjust_by_defines(report_mouse_t mouse_report) { + // Support rotation of the sensor data +#if defined(POINTING_DEVICE_ROTATION_90) || defined(POINTING_DEVICE_ROTATION_180) || defined(POINTING_DEVICE_ROTATION_270) + int8_t x = mouse_report.x, y = mouse_report.y; +# if defined(POINTING_DEVICE_ROTATION_90) + mouse_report.x = y; + mouse_report.y = -x; +# elif defined(POINTING_DEVICE_ROTATION_180) + mouse_report.x = -x; + mouse_report.y = -y; +# elif defined(POINTING_DEVICE_ROTATION_270) + mouse_report.x = -y; + mouse_report.y = x; +# else +# error "How the heck did you get here?!" +# endif +#endif + // Support Inverting the X and Y Axises +#if defined(POINTING_DEVICE_INVERT_X) + mouse_report.x = -mouse_report.x; +#endif +#if defined(POINTING_DEVICE_INVERT_Y) + mouse_report.y = -mouse_report.y; +#endif + return mouse_report; +} + __attribute__((weak)) void pointing_device_task(void) { #if defined(SPLIT_POINTING_ENABLE) // Don't poll the target side pointing device. @@ -124,8 +151,8 @@ __attribute__((weak)) void pointing_device_task(void) { mouseReport.buttons = oldButtons; mouseReport = pointing_device_driver.get_report(mouseReport); oldButtons = mouseReport.buttons; -# elif defined(POINTING_DEVICE_LEFT) || defined(POINTING_DEVICE_RIGHT) - mouseReport = POINTING_DEVICE_THIS_SIDE ? pointing_device_driver.get_report(mouseReport) : mouseReport = sharedReport; + # elif defined(POINTING_DEVICE_LEFT) || defined(POINTING_DEVICE_RIGHT) + mouseReport = POINTING_DEVICE_THIS_SIDE ? pointing_device_driver.get_report(mouseReport) : sharedReport; # else # error "You need to define the side(s) the pointing device is on. POINTING_DEVICE_COMBINED / POINTING_DEVICE_LEFT / POINTING_DEVICE_RIGHT" # endif @@ -133,34 +160,18 @@ __attribute__((weak)) void pointing_device_task(void) { mouseReport = pointing_device_driver.get_report(mouseReport); #endif // defined(SPLIT_POINTING_ENABLE) - // Support rotation of the sensor data -#if defined(POINTING_DEVICE_ROTATION_90) || defined(POINTING_DEVICE_ROTATION_180) || defined(POINTING_DEVICE_ROTATION_270) - int8_t x = mouseReport.x, y = mouseReport.y; -# if defined(POINTING_DEVICE_ROTATION_90) - mouseReport.x = y; - mouseReport.y = -x; -# elif defined(POINTING_DEVICE_ROTATION_180) - mouseReport.x = -x; - mouseReport.y = -y; -# elif defined(POINTING_DEVICE_ROTATION_270) - mouseReport.x = -y; - mouseReport.y = x; -# else -# error "How the heck did you get here?!" -# endif -#endif - // Support Inverting the X and Y Axises -#if defined(POINTING_DEVICE_INVERT_X) - mouseReport.x = -mouseReport.x; -#endif -#if defined(POINTING_DEVICE_INVERT_Y) - mouseReport.y = -mouseReport.y; -#endif - // allow kb to intercept and modify report #if defined(SPLIT_POINTING_ENABLE) && defined(POINTING_DEVICE_COMBINED) - mouseReport = is_keyboard_left() ? pointing_device_task_combined_kb(mouseReport, sharedReport) : pointing_device_task_combined_kb(sharedReport, mouseReport); + if (is_keyboard_left()) { + mouseReport = pointing_device_adjust_by_defines(mouseReport); + sharedReport = pointing_device_adjust_by_defines_right(sharedReport); + } else { + mouseReport = pointing_device_adjust_by_defines_right(mouseReport); + sharedReport = pointing_device_adjust_by_defines(sharedReport); + } + mouseReport = is_keyboard_left() ? pointing_device_task_combined_kb(mouseReport, sharedReport) : pointing_device_task_combined_kb(sharedReport, mouseReport); #else + mouseReport = pointing_device_adjust_by_defines(mouseReport); mouseReport = pointing_device_task_kb(mouseReport); #endif // combine with mouse report to ensure that the combined is sent correctly @@ -214,7 +225,33 @@ report_mouse_t pointing_device_combine_reports(report_mouse_t left_report, repor return left_report; } +report_mouse_t pointing_device_adjust_by_defines_right(report_mouse_t mouse_report) { + // Support rotation of the sensor data +#if defined(POINTING_DEVICE_ROTATION_90_RIGHT) || defined(POINTING_DEVICE_ROTATION_RIGHT) || defined(POINTING_DEVICE_ROTATION_RIGHT) + int8_t x = mouse_report.x, y = mouse_report.y; +# if defined(POINTING_DEVICE_ROTATION_90_RIGHT) + mouse_report.x = y; + mouse_report.y = -x; +# elif defined(POINTING_DEVICE_ROTATION_180_RIGHT) + mouse_report.x = -x; + mouse_report.y = -y; +# elif defined(POINTING_DEVICE_ROTATION_270_RIGHT) + mouse_report.x = -y; + mouse_report.y = x; +# else +# error "How the heck did you get here?!" +# endif +#endif + // Support Inverting the X and Y Axises +#if defined(POINTING_DEVICE_INVERT_X_RIGHT) + mouse_report.x = -mouse_report.x; +#endif +#if defined(POINTING_DEVICE_INVERT_Y_RIGHT) + mouse_report.y = -mouse_report.y; +#endif + return mouse_report; +} + __attribute__((weak)) report_mouse_t pointing_device_task_combined_kb(report_mouse_t left_report, report_mouse_t right_report) { return pointing_device_task_combined_user(left_report, right_report); } __attribute__((weak)) report_mouse_t pointing_device_task_combined_user(report_mouse_t left_report, report_mouse_t right_report) { return pointing_device_combine_reports(left_report, right_report); } - #endif diff --git a/quantum/pointing_device.h b/quantum/pointing_device.h index 4c77042248c0..78398d8999fc 100644 --- a/quantum/pointing_device.h +++ b/quantum/pointing_device.h @@ -86,6 +86,7 @@ void pointing_device_init_user(void); report_mouse_t pointing_device_task_kb(report_mouse_t mouse_report); report_mouse_t pointing_device_task_user(report_mouse_t mouse_report); uint8_t pointing_device_handle_buttons(uint8_t buttons, bool pressed, pointing_device_buttons_t button); +report_mouse_t pointing_device_adjust_by_defines(report_mouse_t mouse_report); #if defined(SPLIT_POINTING_ENABLE) void pointing_device_set_shared_report(report_mouse_t report); @@ -95,5 +96,6 @@ void pointing_device_set_cpi_on_side(bool left, uint16_t cpi); report_mouse_t pointing_device_combine_reports(report_mouse_t left_report, report_mouse_t right_report); report_mouse_t pointing_device_task_combined_kb(report_mouse_t left_report, report_mouse_t right_report); report_mouse_t pointing_device_task_combined_user(report_mouse_t left_report, report_mouse_t right_report); +report_mouse_t pointing_device_adjust_by_defines_right(report_mouse_t mouse_report); # endif //defined(POINTING_DEVICE_COMBINED) #endif //defined(SPLIT_POINTING_ENABLE) From 72965fc47d240f5da1af04cc24f75252b5a21435 Mon Sep 17 00:00:00 2001 From: daskygit <32983009+daskygit@users.noreply.github.com> Date: Thu, 2 Dec 2021 02:59:40 +0000 Subject: [PATCH 13/25] docs --- docs/feature_pointing_device.md | 114 +++++++++++++++++++++++++++++--- docs/feature_split_keyboard.md | 8 +++ 2 files changed, 112 insertions(+), 10 deletions(-) diff --git a/docs/feature_pointing_device.md b/docs/feature_pointing_device.md index efcff32eccfa..ad35100dcd7a 100644 --- a/docs/feature_pointing_device.md +++ b/docs/feature_pointing_device.md @@ -127,10 +127,10 @@ The Pimoroni Trackball module is a I2C based breakout board with an RGB enable t | Setting | Description | Default | |-------------------------------------|------------------------------------------------------------------------------------|---------| |`PIMORONI_TRACKBALL_ADDRESS` | (Required) Sets the I2C Address for the Pimoroni Trackball. | `0x0A` | -|`PIMORONI_TRACKBALL_TIMEOUT` | (Optional) The timeout for i2c communication with the trackpad in milliseconds. | `100` | +|`PIMORONI_TRACKBALL_TIMEOUT` | (Optional) The timeout for i2c communication with the trackball in milliseconds. | `100` | |`PIMORONI_TRACKBALL_SCALE` | (Optional) The multiplier used to generate reports from the sensor. | `5` | |`PIMORONI_TRACKBALL_DEBOUNCE_CYCLES` | (Optional) The number of scan cycles used for debouncing on the ball press. | `20` | -|`PIMORONI_TRACKBALL_ERROR_COUNT` | (Optional) Specifies the number of read/write errors until the sensor is disabled. | `10` | +|`PIMORONI_TRACKBALL_ERROR_COUNT` | (Optional) Specifies the number of read/write errors until the sensor is disabled. | `10` | ### PMW 3360 Sensor @@ -170,16 +170,36 @@ void pointing_device_driver_set_cpi(uint16_t cpi) {} ## Common Configuration -| Setting | Description | Default | -|-------------------------------|-----------------------------------------------------------------------|---------------| -|`POINTING_DEVICE_ROTATION_90` | (Optional) Rotates the X and Y data by 90 degrees. | _not defined_ | -|`POINTING_DEVICE_ROTATION_180` | (Optional) Rotates the X and Y data by 180 degrees. | _not defined_ | -|`POINTING_DEVICE_ROTATION_270` | (Optional) Rotates the X and Y data by 270 degrees. | _not defined_ | -|`POINTING_DEVICE_INVERT_X` | (Optional) Inverts the X axis report. | _not defined_ | -|`POINTING_DEVICE_INVERT_Y` | (Optional) Inverts the Y axis report. | _not defined_ | -|`POINTING_DEVICE_MOTION_PIN` | (Optional) If supported, will only read from sensor if pin is active. | _not defined_ | +| Setting | Description | Default | +|----------------------------------|-----------------------------------------------------------------------|-------------------| +|`POINTING_DEVICE_ROTATION_90` | (Optional) Rotates the X and Y data by 90 degrees. | _not defined_ | +|`POINTING_DEVICE_ROTATION_180` | (Optional) Rotates the X and Y data by 180 degrees. | _not defined_ | +|`POINTING_DEVICE_ROTATION_270` | (Optional) Rotates the X and Y data by 270 degrees. | _not defined_ | +|`POINTING_DEVICE_INVERT_X` | (Optional) Inverts the X axis report. | _not defined_ | +|`POINTING_DEVICE_INVERT_Y` | (Optional) Inverts the Y axis report. | _not defined_ | +|`POINTING_DEVICE_MOTION_PIN` | (Optional) If supported, will only read from sensor if pin is active. | _not defined_ | +!> When using `SPLIT_POINTING_ENABLE` the `POINTING_DEVICE_MOTION_PIN` functionality is not supported and would recommend `POINTING_DEVICE_TASK_THROTTLE_MS` be set to `1`. Increasing this value will increase transport performance at the cost of possible mouse responsiveness. + +## Split Keyboard Configuration + +The following configuration options are only available when using `SPLIT_POINTING_ENABLE` see [data sync options](feature_split_keyboard.md?id=data-sync-options). The rotation and invert `*_RIGHT` options are only used with `POINTING_DEVICE_COMBINED`. If using `POINTING_DEVICE_LEFT` or `POINTING_DEVICE_RIGHT` use the common configuration above to configure your pointing device. + +| Setting | Description | Default | +|----------------------------------------|-----------------------------------------------------------------------|---------------| +|`POINTING_DEVICE_LEFT` | Pointing device on the left side (Required - pick one only) | _not defined_ | +|`POINTING_DEVICE_RIGHT` | Pointing device on the right side (Required - pick one only) | _not defined_ | +|`POINTING_DEVICE_COMBINED` | Pointing device on both sides (Required - pick one only) | _not defined_ | +|`POINTING_DEVICE_ROTATION_90_RIGHT` | (Optional) Rotates the X and Y data by 90 degrees. | _not defined_ | +|`POINTING_DEVICE_ROTATION_180_RIGHT` | (Optional) Rotates the X and Y data by 180 degrees. | _not defined_ | +|`POINTING_DEVICE_ROTATION_270_RIGHT` | (Optional) Rotates the X and Y data by 270 degrees. | _not defined_ | +|`POINTING_DEVICE_INVERT_X_RIGHT` | (Optional) Inverts the X axis report. | _not defined_ | +|`POINTING_DEVICE_INVERT_Y_RIGHT` | (Optional) Inverts the Y axis report. | _not defined_ | + +!> If there is a `_RIGHT` configuration option or callback, the [common configuration](feature_pointing_device.md?id=common-configuration) option will work for the left. For correct left/right detection you should setup a [handedness option](feature_split_keyboard?id=setting-handedness), `EE_HANDS` is usually a good option for an existing board that doesn't do handedness by hardware. + +aqs ## Callbacks and Functions | Function | Description | @@ -195,6 +215,21 @@ void pointing_device_driver_set_cpi(uint16_t cpi) {} | `pointing_device_set_report(mouse_report)` | Sets the mouse report to the assigned `mouse_report_t` data structured passed to the function. | | `pointing_device_send(void)` | Sends the current mouse report to the host system. Function can be replaced. | | `has_mouse_report_changed(old, new)` | Compares the old and new `mouse_report_t` data and returns true only if it has changed. | +| `pointing_device_adjust_by_defines(mouse_report)` | Applies rotations and invert configurations to a raw mouse report. | + + +## Split Keyboard Callbacks and Functions + +The combined functions below are only available when using `SPLIT_POINTING_ENABLE` and `POINTING_DEVICE_COMBINED`. The 2 callbacks `pointing_device_task_combined_*` replace the single sided equivalents above. See the [combined pointing devices example](feature_pointing_device.md?id=combined-pointing-devices) + +| Function | Description | +|-----------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------| +| `pointing_device_set_shared_report(mouse_report)` | Sets the shared mouse report to the assigned `mouse_report_t` data structured passed to the function. | +| `pointing_device_set_cpi_on_side(bool, uint16_t)` | Sets the CPI/DPI of one side, if supported. Passing `true` will set the left and `false` the right` | +| `pointing_device_combine_reports(left_report, right_report)` | Returns a combined mouse_report of left_report and right_report (as a `mouse_report_t` data structure) | +| `pointing_device_task_combined_kb(left_report, right_report)` | Callback, so keyboard code can intercept and modify the data. Returns a combined mouse report. | +| `pointing_device_task_combined_user(left_report, right_report)` | Callback, so user code can intercept and modify. Returns a combined mouse report using `pointing_device_combine_reports` | +| `pointing_device_adjust_by_defines_right(mouse_report)` | Applies right side rotations and invert configurations to a raw mouse report. | # Manipulating Mouse Reports @@ -241,3 +276,62 @@ case MS_SPECIAL: ``` Recall that the mouse report is set to zero (except the buttons) whenever it is sent, so the scrolling would only occur once in each case. + +## Split Examples + +The following examples make use the `SPLIT_POINTING_ENABLE` functionality and show how to manipulate the mouse report for a scrolling mode. + +### Single Pointing Device + +The following example will work with either `POINTING_DEVICE_LEFT` or `POINTING_DEVICE_RIGHT` and implements a custom key code to toggle scrolling mode. + +```c + +static bool scrolling_mode = false; + +layer_state_t layer_state_set_user(layer_state_t state) { + switch (get_highest_layer(state)) { + case _RAISE: // If we're on the _RAISE layer enable scrolling mode + scrolling_mode = true; + pointing_device_set_cpi(2000); + break; + default: + if (scrolling_mode) { // check if we were scrolling before and set disable if so + scrolling_mode = false; + pointing_device_set_cpi(8000); + } + break; + } + return state; +} + +report_mouse_t pointing_device_task_user(report_mouse_t mouse_report) { + if (scrolling_mode) { + mouse_report.h = mouse_report.x; + mouse_report.v = mouse_report.y; + mouse_report.x = 0; + mouse_report.y = 0; + } + return mouse_report; +} + +``` + +### Combined Pointing Devices + +The following example requires `POINTING_DEVICE_COMBINED` and sets the left side pointing device to scroll only. + +```c +void keyboard_post_init_user(void) { + pointing_device_set_cpi_on_side(true, 1000); //Set cpi on left side to a low value for slower scrolling. + pointing_device_set_cpi_on_side(false, 8000); //Set cpi on right side to a reasonable value for mousing. +} + +report_mouse_t pointing_device_task_combined_user(report_mouse_t left_report, report_mouse_t right_report) { + left_report.h = left_report.x; + left_report.v = left_report.y; + left_report.x = 0; + left_report.y = 0; + return pointing_device_combine_reports(left_report, right_report); +} +``` diff --git a/docs/feature_split_keyboard.md b/docs/feature_split_keyboard.md index c8ba18beeb74..b51593308ef0 100644 --- a/docs/feature_split_keyboard.md +++ b/docs/feature_split_keyboard.md @@ -266,6 +266,14 @@ This enables transmitting the current OLED on/off status to the slave side of th This enables transmitting the current ST7565 on/off status to the slave side of the split keyboard. The purpose of this feature is to support state (on/off state only) syncing. +```c +#define SPLIT_POINTING_ENABLE +``` + +This enables transmitting the pointing device status to the master side of the split keyboard. The purpose of this feature is to enable use pointing devices on the slave side. + +!> There is additional required configuration for `SPLIT_POINTING_ENABLE` outlined in the [pointing device documentation](feature_pointing_device.md?id=split-keyboard-configuration). + ### Custom data sync between sides :id=custom-data-sync QMK's split transport allows for arbitrary data transactions at both the keyboard and user levels. This is modelled on a remote procedure call, with the master invoking a function on the slave side, with the ability to send data from master to slave, process it slave side, and send data back from slave to master. From 445208390af12ba5dff82bfa944f93e6e72c9ab7 Mon Sep 17 00:00:00 2001 From: daskygit <32983009+daskygit@users.noreply.github.com> Date: Thu, 2 Dec 2021 22:03:44 +0000 Subject: [PATCH 14/25] doxygen comments --- quantum/pointing_device.c | 245 +++++++++++++++++++++++++++++++------- 1 file changed, 205 insertions(+), 40 deletions(-) diff --git a/quantum/pointing_device.c b/quantum/pointing_device.c index 66689e800721..7e8ca2d7b95e 100644 --- a/quantum/pointing_device.c +++ b/quantum/pointing_device.c @@ -32,7 +32,24 @@ report_mouse_t sharedReport = {}; uint16_t sharedCpi = 0; -void pointing_device_set_shared_report(report_mouse_t report) { sharedReport = report; } +/** + * @brief Sets the shared mouse report used be pointing device task + * + * NOTE : Only available when using SPLIT_POINTING_ENABLE + * + * @param[in] report report_mouse_t + */ +void pointing_device_set_shared_report(report_mouse_t report) { sharedReport = report; } + +/** + * @brief Gets current pointing device CPI if supported + * + * Gets current cpi of the shared report and returns it as uint16_t + * + * NOTE : Only available when using SPLIT_POINTING_ENABLE + * + * @return cpi value as uint16_t + */ uint16_t pointing_device_get_shared_cpi(void) { return sharedCpi; } # if defined(POINTING_DEVICE_LEFT) @@ -49,13 +66,57 @@ static report_mouse_t mouseReport = {}; extern const pointing_device_driver_t pointing_device_driver; +/** + * @brief Compares 2 mouse reports for difference and returns result + * + * @param[in] new report_mouse_t + * @param[in] old report_mouse_t + * @return bool result + */ __attribute__((weak)) bool has_mouse_report_changed(report_mouse_t new, report_mouse_t old) { return memcmp(&new, &old, sizeof(new)); } -__attribute__((weak)) void pointing_device_init_kb(void) {} -__attribute__((weak)) void pointing_device_init_user(void) {} +/** + * @brief Keyboard level code pointing device initialisation + * + */ +__attribute__((weak)) void pointing_device_init_kb(void) {} + +/** + * @brief User level code pointing device initialisation + * + */ +__attribute__((weak)) void pointing_device_init_user(void) {} + +/** + * @brief Weak function allowing for keyboard level mouse report modification + * + * Takes report_mouse_t struct allowing modification at keyboard level then returns report_mouse_t. + * + * @param[in] mouse_report report_mouse_t + * @return report_mouse_t + */ __attribute__((weak)) report_mouse_t pointing_device_task_kb(report_mouse_t mouse_report) { return pointing_device_task_user(mouse_report); } + +/** + * @brief Weak function allowing for user level mouse report modification + * + * Takes report_mouse_t struct allowing modification at user level then returns report_mouse_t. + * + * @param[in] mouse_report report_mouse_t + * @return report_mouse_t + */ __attribute__((weak)) report_mouse_t pointing_device_task_user(report_mouse_t mouse_report) { return mouse_report; } +/** + * @brief Handles pointing device buttons + * + * Returns modified button bitmask using bool pressed and selected pointing_device_buttons_t button in uint8_t buttons bitmask. + * + * @param buttons[in] uint8_t bitmask + * @param pressed[in] bool + * @param button[in] pointing_device_buttons_t value + * @return Modified uint8_t bitmask buttons + */ __attribute__((weak)) uint8_t pointing_device_handle_buttons(uint8_t buttons, bool pressed, pointing_device_buttons_t button) { if (pressed) { buttons |= 1 << (button); @@ -65,6 +126,11 @@ __attribute__((weak)) uint8_t pointing_device_handle_buttons(uint8_t buttons, bo return buttons; } +/** + * @brief Initialises pointing device + * + * Initialises pointing device, perform driver init and optional keyboard/user level code. + */ __attribute__((weak)) void pointing_device_init(void) { pointing_device_driver.init(); #ifdef POINTING_DEVICE_MOTION_PIN @@ -74,6 +140,12 @@ __attribute__((weak)) void pointing_device_init(void) { pointing_device_init_user(); } +/** + * @brief Sends processed mouse report to host + * + * This sends the mouse report generated by pointing_device_task if changed since the last report. Once send zeros mouse report except buttons. + * + */ __attribute__((weak)) void pointing_device_send(void) { static report_mouse_t old_report = {}; @@ -90,33 +162,48 @@ __attribute__((weak)) void pointing_device_send(void) { memcpy(&old_report, &mouseReport, sizeof(mouseReport)); } +/** + * @brief Adjust mouse report by any optional common pointing configuration defines + * + * This applies rotation or inversion to the mouse report as selected by the pointing device common configuration defines. + * + * @param mouse_report[in] takes a report_mouse_t to be adjusted + * @return report_mouse_t with adjusted values + */ report_mouse_t pointing_device_adjust_by_defines(report_mouse_t mouse_report) { - // Support rotation of the sensor data + // Support rotation of the sensor data #if defined(POINTING_DEVICE_ROTATION_90) || defined(POINTING_DEVICE_ROTATION_180) || defined(POINTING_DEVICE_ROTATION_270) - int8_t x = mouse_report.x, y = mouse_report.y; + int8_t x = mouse_report.x, y = mouse_report.y; # if defined(POINTING_DEVICE_ROTATION_90) - mouse_report.x = y; - mouse_report.y = -x; + mouse_report.x = y; + mouse_report.y = -x; # elif defined(POINTING_DEVICE_ROTATION_180) - mouse_report.x = -x; - mouse_report.y = -y; + mouse_report.x = -x; + mouse_report.y = -y; # elif defined(POINTING_DEVICE_ROTATION_270) - mouse_report.x = -y; - mouse_report.y = x; + mouse_report.x = -y; + mouse_report.y = x; # else # error "How the heck did you get here?!" # endif #endif - // Support Inverting the X and Y Axises + // Support Inverting the X and Y Axises #if defined(POINTING_DEVICE_INVERT_X) - mouse_report.x = -mouse_report.x; + mouse_report.x = -mouse_report.x; #endif #if defined(POINTING_DEVICE_INVERT_Y) - mouse_report.y = -mouse_report.y; + mouse_report.y = -mouse_report.y; #endif return mouse_report; } +/** + * @brief Retrieves and processes pointing device data. + * + * This function is part of the keyboard loop and retrieves the mouse report from the pointing device driver. + * It applies any optional configuration e.g. rotation or axis inversion and then initiates a send. + * + */ __attribute__((weak)) void pointing_device_task(void) { #if defined(SPLIT_POINTING_ENABLE) // Don't poll the target side pointing device. @@ -151,8 +238,8 @@ __attribute__((weak)) void pointing_device_task(void) { mouseReport.buttons = oldButtons; mouseReport = pointing_device_driver.get_report(mouseReport); oldButtons = mouseReport.buttons; - # elif defined(POINTING_DEVICE_LEFT) || defined(POINTING_DEVICE_RIGHT) - mouseReport = POINTING_DEVICE_THIS_SIDE ? pointing_device_driver.get_report(mouseReport) : sharedReport; +# elif defined(POINTING_DEVICE_LEFT) || defined(POINTING_DEVICE_RIGHT) + mouseReport = POINTING_DEVICE_THIS_SIDE ? pointing_device_driver.get_report(mouseReport) : sharedReport; # else # error "You need to define the side(s) the pointing device is on. POINTING_DEVICE_COMBINED / POINTING_DEVICE_LEFT / POINTING_DEVICE_RIGHT" # endif @@ -169,9 +256,9 @@ __attribute__((weak)) void pointing_device_task(void) { mouseReport = pointing_device_adjust_by_defines_right(mouseReport); sharedReport = pointing_device_adjust_by_defines(sharedReport); } - mouseReport = is_keyboard_left() ? pointing_device_task_combined_kb(mouseReport, sharedReport) : pointing_device_task_combined_kb(sharedReport, mouseReport); + mouseReport = is_keyboard_left() ? pointing_device_task_combined_kb(mouseReport, sharedReport) : pointing_device_task_combined_kb(sharedReport, mouseReport); #else - mouseReport = pointing_device_adjust_by_defines(mouseReport); + mouseReport = pointing_device_adjust_by_defines(mouseReport); mouseReport = pointing_device_task_kb(mouseReport); #endif // combine with mouse report to ensure that the combined is sent correctly @@ -182,10 +269,27 @@ __attribute__((weak)) void pointing_device_task(void) { pointing_device_send(); } +/** + * @brief Gets current mouse report used by pointing device task + * + * @return report_mouse_t + */ report_mouse_t pointing_device_get_report(void) { return mouseReport; } +/** + * @brief Sets mouse report used be pointing device task + * + * @param[in] newMouseReport + */ void pointing_device_set_report(report_mouse_t newMouseReport) { mouseReport = newMouseReport; } +/** + * @brief Gets current pointing device CPI if supported + * + * Gets current cpi from pointing device driver if supported and returns it as uint16_t + * + * @return cpi value as uint16_t + */ uint16_t pointing_device_get_cpi(void) { #if defined(SPLIT_POINTING_ENABLE) return POINTING_DEVICE_THIS_SIDE ? pointing_device_driver.get_cpi() : sharedCpi; @@ -194,6 +298,13 @@ uint16_t pointing_device_get_cpi(void) { #endif } +/** + * @brief Set pointing device CPI if supported + * + * Takes a uint16_t value to set pointing device cpi if supported by driver. + * + * @param[in] cpi uint16_t value. + */ void pointing_device_set_cpi(uint16_t cpi) { #if defined(SPLIT_POINTING_ENABLE) if (POINTING_DEVICE_THIS_SIDE) { @@ -207,6 +318,16 @@ void pointing_device_set_cpi(uint16_t cpi) { } #if defined(SPLIT_POINTING_ENABLE) && defined(POINTING_DEVICE_COMBINED) +/** + * @brief Set pointing device CPI if supported + * + * Takes a bool and uint16_t and allows setting cpi for a single side when using 2 pointing devices with a split keyboard. + * + * NOTE: Only available when using SPLIT_POINTING_ENABLE and POINTING_DEVICE_COMBINED + * + * @param[in] left true = left, false = right. + * @param[in] cpi uint16_t value. + */ void pointing_device_set_cpi_on_side(bool left, uint16_t cpi) { bool local = (is_keyboard_left() & left) ? true : false; if (local) { @@ -216,6 +337,17 @@ void pointing_device_set_cpi_on_side(bool left, uint16_t cpi) { } } +/** + * @brief combines 2 mouse reports and returns 2 + * + * Takes 2 report_mouse_t structs, performs an inclusive or ignoring report_id then returns the resulting report_mouse_t struct. + * + * NOTE: Only available when using SPLIT_POINTING_ENABLE and POINTING_DEVICE_COMBINED + * + * @param[in] left_report left report_mouse_t + * @param[in] right_report right report_mouse_t + * @return combined report_mouse_t of left_report and right_report + */ report_mouse_t pointing_device_combine_reports(report_mouse_t left_report, report_mouse_t right_report) { left_report.x |= right_report.x; left_report.y |= right_report.y; @@ -225,33 +357,66 @@ report_mouse_t pointing_device_combine_reports(report_mouse_t left_report, repor return left_report; } +/** + * @brief Adjust mouse report by any optional right pointing configuration defines + * + * This applies rotation or inversion to the mouse report as selected by the pointing device common configuration defines. + * + * NOTE: Only available when using SPLIT_POINTING_ENABLE and POINTING_DEVICE_COMBINED + * + * @param[in] mouse_report report_mouse_t to be adjusted + * @return report_mouse_t with adjusted values + */ report_mouse_t pointing_device_adjust_by_defines_right(report_mouse_t mouse_report) { - // Support rotation of the sensor data -#if defined(POINTING_DEVICE_ROTATION_90_RIGHT) || defined(POINTING_DEVICE_ROTATION_RIGHT) || defined(POINTING_DEVICE_ROTATION_RIGHT) - int8_t x = mouse_report.x, y = mouse_report.y; -# if defined(POINTING_DEVICE_ROTATION_90_RIGHT) - mouse_report.x = y; - mouse_report.y = -x; -# elif defined(POINTING_DEVICE_ROTATION_180_RIGHT) - mouse_report.x = -x; - mouse_report.y = -y; -# elif defined(POINTING_DEVICE_ROTATION_270_RIGHT) - mouse_report.x = -y; - mouse_report.y = x; -# else -# error "How the heck did you get here?!" + // Support rotation of the sensor data +# if defined(POINTING_DEVICE_ROTATION_90_RIGHT) || defined(POINTING_DEVICE_ROTATION_RIGHT) || defined(POINTING_DEVICE_ROTATION_RIGHT) + int8_t x = mouse_report.x, y = mouse_report.y; +# if defined(POINTING_DEVICE_ROTATION_90_RIGHT) + mouse_report.x = y; + mouse_report.y = -x; +# elif defined(POINTING_DEVICE_ROTATION_180_RIGHT) + mouse_report.x = -x; + mouse_report.y = -y; +# elif defined(POINTING_DEVICE_ROTATION_270_RIGHT) + mouse_report.x = -y; + mouse_report.y = x; +# else +# error "How the heck did you get here?!" +# endif +# endif + // Support Inverting the X and Y Axises +# if defined(POINTING_DEVICE_INVERT_X_RIGHT) + mouse_report.x = -mouse_report.x; +# endif +# if defined(POINTING_DEVICE_INVERT_Y_RIGHT) + mouse_report.y = -mouse_report.y; # endif -#endif - // Support Inverting the X and Y Axises -#if defined(POINTING_DEVICE_INVERT_X_RIGHT) - mouse_report.x = -mouse_report.x; -#endif -#if defined(POINTING_DEVICE_INVERT_Y_RIGHT) - mouse_report.y = -mouse_report.y; -#endif return mouse_report; } +/** + * @brief Weak function allowing for keyboard level mouse report modification + * + * Takes 2 report_mouse_t structs allowing individual modification of sides at keyboard level then returns pointing_device_task_combined_user. + * + * NOTE: Only available when using SPLIT_POINTING_ENABLE and POINTING_DEVICE_COMBINED + * + * @param[in] left_report report_mouse_t + * @param[in] right_report report_mouse_t + * @return pointing_device_task_combined_user(left_report, right_report) by default + */ __attribute__((weak)) report_mouse_t pointing_device_task_combined_kb(report_mouse_t left_report, report_mouse_t right_report) { return pointing_device_task_combined_user(left_report, right_report); } + +/** + * @brief Weak function allowing for user level mouse report modification + * + * Takes 2 report_mouse_t structs allowing individual modification of sides at user level then returns pointing_device_combine_reports. + * + * NOTE: Only available when using SPLIT_POINTING_ENABLE and POINTING_DEVICE_COMBINED + * + * @param[in] left_report report_mouse_t + * @param[in] right_report report_mouse_t + * @return pointing_device_combine_reports(left_report, right_report) by default + */ __attribute__((weak)) report_mouse_t pointing_device_task_combined_user(report_mouse_t left_report, report_mouse_t right_report) { return pointing_device_combine_reports(left_report, right_report); } #endif From a1bd6e3733417a34d45bf2579421f718a7a32513 Mon Sep 17 00:00:00 2001 From: daskygit <32983009+daskygit@users.noreply.github.com> Date: Fri, 3 Dec 2021 20:08:53 +0000 Subject: [PATCH 15/25] basic changelog --- docs/ChangeLog/20220226/PR15304.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 docs/ChangeLog/20220226/PR15304.md diff --git a/docs/ChangeLog/20220226/PR15304.md b/docs/ChangeLog/20220226/PR15304.md new file mode 100644 index 000000000000..3cdb40db1099 --- /dev/null +++ b/docs/ChangeLog/20220226/PR15304.md @@ -0,0 +1,13 @@ +### Split Common core now supports Pointing Devices ([#15304](https://github.com/qmk/qmk_firmware/pull/15304)) + +Pointing devices can now be shared across a split keyboard with support for a single pointing device or a pointing device on each side. + +This feature can be enabled with `#define SPLIT_POINTING_ENABLE` and one of the following options: + +| Setting | Description | +|---------------------------|------------------------------------| +|`POINTING_DEVICE_LEFT` | Pointing device on the left side | +|`POINTING_DEVICE_RIGHT` | Pointing device on the right side | +|`POINTING_DEVICE_COMBINED` | Pointing device on both sides | + +See the [Pointing Device](../feature_pointing_device.md) documentation for further configuration options. From 9aefeced490d4bf683a0fd3782dea777193980a5 Mon Sep 17 00:00:00 2001 From: daskygit <32983009+daskygit@users.noreply.github.com> Date: Fri, 3 Dec 2021 20:47:10 +0000 Subject: [PATCH 16/25] clean up pimoroni --- drivers/sensors/pimoroni_trackball.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/drivers/sensors/pimoroni_trackball.c b/drivers/sensors/pimoroni_trackball.c index 5b6711460287..e40807098057 100644 --- a/drivers/sensors/pimoroni_trackball.c +++ b/drivers/sensors/pimoroni_trackball.c @@ -34,10 +34,23 @@ static uint16_t precision = 128; uint16_t pimoroni_trackball_get_cpi(void) { return (precision * 125); } -void pimoroni_trackball_set_cpi(uint16_t cpi) { precision = (cpi / 125); } - -float pimoroni_trackball_get_precision(void) { return ((float)precision / 128); } -void pimoroni_trackball_set_precision(float floatprecision) { precision = (floatprecision * 128); } +/** + * @brief Sets the scaling value for pimoroni trackball + * + * Sets a scaling value for pimoroni trackball to allow runtime adjustment. This isn't used by the sensor and is an + * approximation so the functions are consistent across drivers. + * + * NOTE: This rounds down to the nearest number divisable by 125 that's a positive integer, values below 125 are clamped to 125. + * + * @param cpi uint16_t + */ +void pimoroni_trackball_set_cpi(uint16_t cpi) { + if (cpi < 249) { + precision = 1; + } else { + precision = (cpi - (cpi % 125)) / 125; + } +} void pimoroni_trackball_set_rgbw(uint8_t r, uint8_t g, uint8_t b, uint8_t w) { uint8_t data[4] = {r, g, b, w}; From 2c3c64b8bf93d3fcb7e1e0ebd7288e30159e0ab7 Mon Sep 17 00:00:00 2001 From: daskygit <32983009+daskygit@users.noreply.github.com> Date: Sat, 4 Dec 2021 11:34:30 +0000 Subject: [PATCH 17/25] small doc fixes --- docs/feature_pointing_device.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/feature_pointing_device.md b/docs/feature_pointing_device.md index ad35100dcd7a..2a0a1d84d518 100644 --- a/docs/feature_pointing_device.md +++ b/docs/feature_pointing_device.md @@ -199,7 +199,7 @@ The following configuration options are only available when using `SPLIT_POINTIN !> If there is a `_RIGHT` configuration option or callback, the [common configuration](feature_pointing_device.md?id=common-configuration) option will work for the left. For correct left/right detection you should setup a [handedness option](feature_split_keyboard?id=setting-handedness), `EE_HANDS` is usually a good option for an existing board that doesn't do handedness by hardware. -aqs + ## Callbacks and Functions | Function | Description | @@ -283,7 +283,7 @@ The following examples make use the `SPLIT_POINTING_ENABLE` functionality and sh ### Single Pointing Device -The following example will work with either `POINTING_DEVICE_LEFT` or `POINTING_DEVICE_RIGHT` and implements a custom key code to toggle scrolling mode. +The following example will work with either `POINTING_DEVICE_LEFT` or `POINTING_DEVICE_RIGHT` and enables scrolling mode while on a particular layer. ```c From 587aa744b3589c723d7ebd1a6a0f4b375d9229fb Mon Sep 17 00:00:00 2001 From: Dasky <32983009+daskygit@users.noreply.github.com> Date: Sat, 4 Dec 2021 16:46:38 +0000 Subject: [PATCH 18/25] Update docs/feature_pointing_device.md Co-authored-by: Drashna Jaelre --- docs/feature_pointing_device.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/feature_pointing_device.md b/docs/feature_pointing_device.md index 2a0a1d84d518..f8de92f3b401 100644 --- a/docs/feature_pointing_device.md +++ b/docs/feature_pointing_device.md @@ -178,6 +178,7 @@ void pointing_device_driver_set_cpi(uint16_t cpi) {} |`POINTING_DEVICE_INVERT_X` | (Optional) Inverts the X axis report. | _not defined_ | |`POINTING_DEVICE_INVERT_Y` | (Optional) Inverts the Y axis report. | _not defined_ | |`POINTING_DEVICE_MOTION_PIN` | (Optional) If supported, will only read from sensor if pin is active. | _not defined_ | +|`POINTING_DEVICE_TASK_THROTTLE_MS` | (Optional) Limits the frequency that the sensor is polled for motion. | _not defined_ | !> When using `SPLIT_POINTING_ENABLE` the `POINTING_DEVICE_MOTION_PIN` functionality is not supported and would recommend `POINTING_DEVICE_TASK_THROTTLE_MS` be set to `1`. Increasing this value will increase transport performance at the cost of possible mouse responsiveness. From 98a2e7e42b603d8b0dfc3a36e49fc35d52fc86f8 Mon Sep 17 00:00:00 2001 From: daskygit <32983009+daskygit@users.noreply.github.com> Date: Sat, 4 Dec 2021 22:04:33 +0000 Subject: [PATCH 19/25] performance tweak if side has usb --- quantum/split_common/transactions.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/quantum/split_common/transactions.c b/quantum/split_common/transactions.c index 6b258f6b537c..9622acb377ae 100644 --- a/quantum/split_common/transactions.c +++ b/quantum/split_common/transactions.c @@ -584,6 +584,15 @@ static void st7565_handlers_slave(matrix_row_t master_matrix[], matrix_row_t sla #if defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE) static bool pointing_handlers_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { +# if defined(POINTING_DEVICE_LEFT) + if (is_keyboard_left()) { + return true; + } +# elif defined(POINTING_DEVICE_RIGHT) + if (!is_keyboard_left()) { + return true; + } +# endif static uint32_t last_update = 0; static uint16_t last_cpi = 0; report_mouse_t temp_state; @@ -591,7 +600,7 @@ static bool pointing_handlers_master(matrix_row_t master_matrix[], matrix_row_t bool okay = read_if_checksum_mismatch(GET_POINTING_CHECKSUM, GET_POINTING_DATA, &last_update, &temp_state, &split_shmem->pointing.report, sizeof(temp_state)); if (okay) pointing_device_set_shared_report(temp_state); temp_cpi = pointing_device_get_shared_cpi(); - if (temp_cpi&& memcmp(&last_cpi, &temp_cpi, sizeof(temp_cpi)) != 0) { + if (temp_cpi && memcmp(&last_cpi, &temp_cpi, sizeof(temp_cpi)) != 0) { memcpy(&split_shmem->pointing.cpi, &temp_cpi, sizeof(temp_cpi)); okay = transport_write(PUT_POINTING_CPI, &split_shmem->pointing.cpi, sizeof(split_shmem->pointing.cpi)); if (okay) { @@ -604,6 +613,15 @@ static bool pointing_handlers_master(matrix_row_t master_matrix[], matrix_row_t extern const pointing_device_driver_t pointing_device_driver; static void pointing_handlers_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { +# if defined(POINTING_DEVICE_LEFT) + if (!is_keyboard_left()) { + return; + } +# elif defined(POINTING_DEVICE_RIGHT) + if (is_keyboard_left()) { + return; + } +# endif report_mouse_t temp_report; uint16_t temp_cpi; # ifdef POINTING_DEVICE_TASK_THROTTLE_MS From 5c4fac59a8336c4a780e2665df389330f27e45e4 Mon Sep 17 00:00:00 2001 From: daskygit <32983009+daskygit@users.noreply.github.com> Date: Thu, 16 Dec 2021 15:26:51 +0000 Subject: [PATCH 20/25] Don't run init funtions on wrong side --- quantum/pointing_device.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/quantum/pointing_device.c b/quantum/pointing_device.c index 7e8ca2d7b95e..42c7c00ce8ec 100644 --- a/quantum/pointing_device.c +++ b/quantum/pointing_device.c @@ -132,6 +132,11 @@ __attribute__((weak)) uint8_t pointing_device_handle_buttons(uint8_t buttons, bo * Initialises pointing device, perform driver init and optional keyboard/user level code. */ __attribute__((weak)) void pointing_device_init(void) { +#if defined(SPLIT_POINTING_ENABLE) + if (!(POINTING_DEVICE_THIS_SIDE)) { + return; + } +#endif pointing_device_driver.init(); #ifdef POINTING_DEVICE_MOTION_PIN setPinInputHigh(POINTING_DEVICE_MOTION_PIN); From dea87e86865b9b0d7afa9428d398c7f6a48ce0fd Mon Sep 17 00:00:00 2001 From: daskygit <32983009+daskygit@users.noreply.github.com> Date: Thu, 23 Dec 2021 18:20:17 +0000 Subject: [PATCH 21/25] renamed some variables for consistency --- quantum/pointing_device.c | 66 +++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/quantum/pointing_device.c b/quantum/pointing_device.c index 42c7c00ce8ec..b6311fc245e4 100644 --- a/quantum/pointing_device.c +++ b/quantum/pointing_device.c @@ -29,17 +29,17 @@ # include "transactions.h" # include "keyboard.h" -report_mouse_t sharedReport = {}; -uint16_t sharedCpi = 0; +report_mouse_t shared_mouse_report = {}; +uint16_t shared_cpi = 0; /** * @brief Sets the shared mouse report used be pointing device task * * NOTE : Only available when using SPLIT_POINTING_ENABLE * - * @param[in] report report_mouse_t + * @param[in] new_mouse_report report_mouse_t */ -void pointing_device_set_shared_report(report_mouse_t report) { sharedReport = report; } +void pointing_device_set_shared_report(report_mouse_t new_mouse_report) { shared_mouse_report = new_mouse_report; } /** * @brief Gets current pointing device CPI if supported @@ -50,7 +50,7 @@ void pointing_device_set_shared_report(report_mouse_t report) { sharedReport = r * * @return cpi value as uint16_t */ -uint16_t pointing_device_get_shared_cpi(void) { return sharedCpi; } +uint16_t pointing_device_get_shared_cpi(void) { return shared_cpi; } # if defined(POINTING_DEVICE_LEFT) # define POINTING_DEVICE_THIS_SIDE is_keyboard_left() @@ -62,7 +62,7 @@ uint16_t pointing_device_get_shared_cpi(void) { return sharedCpi; } #endif // defined(SPLIT_POINTING_ENABLE) -static report_mouse_t mouseReport = {}; +static report_mouse_t local_mouse_report = {}; extern const pointing_device_driver_t pointing_device_driver; @@ -155,16 +155,16 @@ __attribute__((weak)) void pointing_device_send(void) { static report_mouse_t old_report = {}; // If you need to do other things, like debugging, this is the place to do it. - if (has_mouse_report_changed(mouseReport, old_report)) { - host_mouse_send(&mouseReport); + if (has_mouse_report_changed(local_mouse_report, old_report)) { + host_mouse_send(&local_mouse_report); } // send it and 0 it out except for buttons, so those stay until they are explicity over-ridden using update_pointing_device - mouseReport.x = 0; - mouseReport.y = 0; - mouseReport.v = 0; - mouseReport.h = 0; + local_mouse_report.x = 0; + local_mouse_report.y = 0; + local_mouse_report.v = 0; + local_mouse_report.h = 0; - memcpy(&old_report, &mouseReport, sizeof(mouseReport)); + memcpy(&old_report, &local_mouse_report, sizeof(local_mouse_report)); } /** @@ -239,37 +239,37 @@ __attribute__((weak)) void pointing_device_task(void) { #if defined(SPLIT_POINTING_ENABLE) # if defined(POINTING_DEVICE_COMBINED) - static uint8_t oldButtons = 0; - mouseReport.buttons = oldButtons; - mouseReport = pointing_device_driver.get_report(mouseReport); - oldButtons = mouseReport.buttons; + static uint8_t old_buttons = 0; + local_mouse_report.buttons = old_buttons; + local_mouse_report = pointing_device_driver.get_report(local_mouse_report); + old_buttons = local_mouse_report.buttons; # elif defined(POINTING_DEVICE_LEFT) || defined(POINTING_DEVICE_RIGHT) - mouseReport = POINTING_DEVICE_THIS_SIDE ? pointing_device_driver.get_report(mouseReport) : sharedReport; + local_mouse_report = POINTING_DEVICE_THIS_SIDE ? pointing_device_driver.get_report(local_mouse_report) : shared_mouse_report; # else # error "You need to define the side(s) the pointing device is on. POINTING_DEVICE_COMBINED / POINTING_DEVICE_LEFT / POINTING_DEVICE_RIGHT" # endif #else - mouseReport = pointing_device_driver.get_report(mouseReport); + local_mouse_report = pointing_device_driver.get_report(local_mouse_report); #endif // defined(SPLIT_POINTING_ENABLE) // allow kb to intercept and modify report #if defined(SPLIT_POINTING_ENABLE) && defined(POINTING_DEVICE_COMBINED) if (is_keyboard_left()) { - mouseReport = pointing_device_adjust_by_defines(mouseReport); - sharedReport = pointing_device_adjust_by_defines_right(sharedReport); + local_mouse_report = pointing_device_adjust_by_defines(local_mouse_report); + shared_mouse_report = pointing_device_adjust_by_defines_right(shared_mouse_report); } else { - mouseReport = pointing_device_adjust_by_defines_right(mouseReport); - sharedReport = pointing_device_adjust_by_defines(sharedReport); + local_mouse_report = pointing_device_adjust_by_defines_right(local_mouse_report); + shared_mouse_report = pointing_device_adjust_by_defines(shared_mouse_report); } - mouseReport = is_keyboard_left() ? pointing_device_task_combined_kb(mouseReport, sharedReport) : pointing_device_task_combined_kb(sharedReport, mouseReport); + local_mouse_report = is_keyboard_left() ? pointing_device_task_combined_kb(local_mouse_report, shared_mouse_report) : pointing_device_task_combined_kb(shared_mouse_report, local_mouse_report); #else - mouseReport = pointing_device_adjust_by_defines(mouseReport); - mouseReport = pointing_device_task_kb(mouseReport); + local_mouse_report = pointing_device_adjust_by_defines(local_mouse_report); + local_mouse_report = pointing_device_task_kb(local_mouse_report); #endif // combine with mouse report to ensure that the combined is sent correctly #ifdef MOUSEKEY_ENABLE report_mouse_t mousekey_report = mousekey_get_report(); - mouseReport.buttons = mouseReport.buttons | mousekey_report.buttons; + local_mouse_report.buttons = local_mouse_report.buttons | mousekey_report.buttons; #endif pointing_device_send(); } @@ -279,14 +279,14 @@ __attribute__((weak)) void pointing_device_task(void) { * * @return report_mouse_t */ -report_mouse_t pointing_device_get_report(void) { return mouseReport; } +report_mouse_t pointing_device_get_report(void) { return local_mouse_report; } /** * @brief Sets mouse report used be pointing device task * - * @param[in] newMouseReport + * @param[in] new_mouse_report */ -void pointing_device_set_report(report_mouse_t newMouseReport) { mouseReport = newMouseReport; } +void pointing_device_set_report(report_mouse_t new_mouse_report) { local_mouse_report = new_mouse_report; } /** * @brief Gets current pointing device CPI if supported @@ -297,7 +297,7 @@ void pointing_device_set_report(report_mouse_t newMouseReport) { mouseReport = n */ uint16_t pointing_device_get_cpi(void) { #if defined(SPLIT_POINTING_ENABLE) - return POINTING_DEVICE_THIS_SIDE ? pointing_device_driver.get_cpi() : sharedCpi; + return POINTING_DEVICE_THIS_SIDE ? pointing_device_driver.get_cpi() : shared_cpi; #else return pointing_device_driver.get_cpi(); #endif @@ -315,7 +315,7 @@ void pointing_device_set_cpi(uint16_t cpi) { if (POINTING_DEVICE_THIS_SIDE) { pointing_device_driver.set_cpi(cpi); } else { - sharedCpi = cpi; + shared_cpi = cpi; } #else pointing_device_driver.set_cpi(cpi); @@ -338,7 +338,7 @@ void pointing_device_set_cpi_on_side(bool left, uint16_t cpi) { if (local) { pointing_device_driver.set_cpi(cpi); } else { - sharedCpi = cpi; + shared_cpi = cpi; } } From a7d009ca096075283db99674d0d4de6e6eadd76e Mon Sep 17 00:00:00 2001 From: daskygit <32983009+daskygit@users.noreply.github.com> Date: Thu, 23 Dec 2021 18:30:54 +0000 Subject: [PATCH 22/25] fix pimoroni typos --- drivers/sensors/pimoroni_trackball.c | 2 +- drivers/sensors/pimoroni_trackball.h | 2 +- quantum/pointing_device_drivers.c | 14 +++++++------- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/sensors/pimoroni_trackball.c b/drivers/sensors/pimoroni_trackball.c index e40807098057..2867e763bc70 100644 --- a/drivers/sensors/pimoroni_trackball.c +++ b/drivers/sensors/pimoroni_trackball.c @@ -76,7 +76,7 @@ i2c_status_t read_pimoroni_trackball(pimoroni_data_t* data) { return status; } -__attribute__((weak)) void pimironi_trackball_device_init(void) { +__attribute__((weak)) void pimoroni_trackball_device_init(void) { i2c_init(); pimoroni_trackball_set_rgbw(0x00, 0x00, 0x00, 0x00); } diff --git a/drivers/sensors/pimoroni_trackball.h b/drivers/sensors/pimoroni_trackball.h index e3400375f6b6..e20ee748a75b 100644 --- a/drivers/sensors/pimoroni_trackball.h +++ b/drivers/sensors/pimoroni_trackball.h @@ -49,7 +49,7 @@ typedef struct { uint8_t click; } pimoroni_data_t; -void pimironi_trackball_device_init(void); +void pimoroni_trackball_device_init(void); void pimoroni_trackball_set_rgbw(uint8_t red, uint8_t green, uint8_t blue, uint8_t white); int16_t pimoroni_trackball_get_offsets(uint8_t negative_dir, uint8_t positive_dir, uint8_t scale); void pimoroni_trackball_adapt_values(int8_t* mouse, int16_t* offset); diff --git a/quantum/pointing_device_drivers.c b/quantum/pointing_device_drivers.c index 24592bfa5447..0852a0bea7a5 100644 --- a/quantum/pointing_device_drivers.c +++ b/quantum/pointing_device_drivers.c @@ -165,11 +165,11 @@ const pointing_device_driver_t pointing_device_driver = { // clang-format on #elif defined(POINTING_DEVICE_DRIVER_pimoroni_trackball) -report_mouse_t pimorono_trackball_get_report(report_mouse_t mouse_report) { - static uint16_t debounce = 0; - static uint8_t error_count = 0; - pimoroni_data_t pimoroni_data = {0}; - static int16_t x_offset = 0, y_offset = 0; +report_mouse_t pimoroni_trackball_get_report(report_mouse_t mouse_report) { + static uint16_t debounce = 0; + static uint8_t error_count = 0; + pimoroni_data_t pimoroni_data = {0}; + static int16_t x_offset = 0, y_offset = 0; if (error_count < PIMORONI_TRACKBALL_ERROR_COUNT) { i2c_status_t status = read_pimoroni_trackball(&pimoroni_data); @@ -200,8 +200,8 @@ report_mouse_t pimorono_trackball_get_report(report_mouse_t mouse_report) { // clang-format off const pointing_device_driver_t pointing_device_driver = { - .init = pimironi_trackball_device_init, - .get_report = pimorono_trackball_get_report, + .init = pimoroni_trackball_device_init, + .get_report = pimoroni_trackball_get_report, .set_cpi = pimoroni_trackball_set_cpi, .get_cpi = pimoroni_trackball_get_cpi }; From 5a0475f85e43bddffd9bc761a027c45eb8800138 Mon Sep 17 00:00:00 2001 From: daskygit <32983009+daskygit@users.noreply.github.com> Date: Sun, 26 Dec 2021 02:28:50 +0000 Subject: [PATCH 23/25] Clamp instead of OR --- quantum/pointing_device.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/quantum/pointing_device.c b/quantum/pointing_device.c index b6311fc245e4..752b77ce0de0 100644 --- a/quantum/pointing_device.c +++ b/quantum/pointing_device.c @@ -342,10 +342,26 @@ void pointing_device_set_cpi_on_side(bool left, uint16_t cpi) { } } +/** + * @brief clamps int16_t to int8_t + * + * @param[in] int16_t value + * @return int8_t clamped value + */ +static inline int8_t pointing_device_movement_clamp(int16_t value) { + if (value < INT8_MIN) { + return INT8_MIN; + } else if (value > INT8_MAX) { + return INT8_MAX; + } else { + return value; + } +} + /** * @brief combines 2 mouse reports and returns 2 * - * Takes 2 report_mouse_t structs, performs an inclusive or ignoring report_id then returns the resulting report_mouse_t struct. + * Combines 2 report_mouse_t structs, clamping movement values to int8_t and ignores report_id then returns the resulting report_mouse_t struct. * * NOTE: Only available when using SPLIT_POINTING_ENABLE and POINTING_DEVICE_COMBINED * @@ -354,10 +370,10 @@ void pointing_device_set_cpi_on_side(bool left, uint16_t cpi) { * @return combined report_mouse_t of left_report and right_report */ report_mouse_t pointing_device_combine_reports(report_mouse_t left_report, report_mouse_t right_report) { - left_report.x |= right_report.x; - left_report.y |= right_report.y; - left_report.h |= right_report.h; - left_report.v |= right_report.v; + left_report.x = pointing_device_movement_clamp(left_report.x + right_report.x); + left_report.y = pointing_device_movement_clamp(left_report.y + right_report.y); + left_report.h = pointing_device_movement_clamp(left_report.h + right_report.h); + left_report.v = pointing_device_movement_clamp(left_report.v + right_report.v); left_report.buttons |= right_report.buttons; return left_report; } From 0d1312d825ed237b73296272f091513136712fcd Mon Sep 17 00:00:00 2001 From: Nick Brassel Date: Mon, 27 Dec 2021 12:02:30 +1100 Subject: [PATCH 24/25] Promote combined values to uint16_t --- quantum/pointing_device.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/quantum/pointing_device.c b/quantum/pointing_device.c index 752b77ce0de0..791e817141ca 100644 --- a/quantum/pointing_device.c +++ b/quantum/pointing_device.c @@ -370,10 +370,10 @@ static inline int8_t pointing_device_movement_clamp(int16_t value) { * @return combined report_mouse_t of left_report and right_report */ report_mouse_t pointing_device_combine_reports(report_mouse_t left_report, report_mouse_t right_report) { - left_report.x = pointing_device_movement_clamp(left_report.x + right_report.x); - left_report.y = pointing_device_movement_clamp(left_report.y + right_report.y); - left_report.h = pointing_device_movement_clamp(left_report.h + right_report.h); - left_report.v = pointing_device_movement_clamp(left_report.v + right_report.v); + left_report.x = pointing_device_movement_clamp((uint16_t)left_report.x + right_report.x); + left_report.y = pointing_device_movement_clamp((uint16_t)left_report.y + right_report.y); + left_report.h = pointing_device_movement_clamp((uint16_t)left_report.h + right_report.h); + left_report.v = pointing_device_movement_clamp((uint16_t)left_report.v + right_report.v); left_report.buttons |= right_report.buttons; return left_report; } From 430c59d29e5f7fc5f6ea572d2ee1c509f8aa78f5 Mon Sep 17 00:00:00 2001 From: Nick Brassel Date: Mon, 27 Dec 2021 12:03:56 +1100 Subject: [PATCH 25/25] Update pointing_device.c --- quantum/pointing_device.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/quantum/pointing_device.c b/quantum/pointing_device.c index 791e817141ca..23d93fa15fe0 100644 --- a/quantum/pointing_device.c +++ b/quantum/pointing_device.c @@ -370,10 +370,10 @@ static inline int8_t pointing_device_movement_clamp(int16_t value) { * @return combined report_mouse_t of left_report and right_report */ report_mouse_t pointing_device_combine_reports(report_mouse_t left_report, report_mouse_t right_report) { - left_report.x = pointing_device_movement_clamp((uint16_t)left_report.x + right_report.x); - left_report.y = pointing_device_movement_clamp((uint16_t)left_report.y + right_report.y); - left_report.h = pointing_device_movement_clamp((uint16_t)left_report.h + right_report.h); - left_report.v = pointing_device_movement_clamp((uint16_t)left_report.v + right_report.v); + left_report.x = pointing_device_movement_clamp((int16_t)left_report.x + right_report.x); + left_report.y = pointing_device_movement_clamp((int16_t)left_report.y + right_report.y); + left_report.h = pointing_device_movement_clamp((int16_t)left_report.h + right_report.h); + left_report.v = pointing_device_movement_clamp((int16_t)left_report.v + right_report.v); left_report.buttons |= right_report.buttons; return left_report; }