fix(trackpad): fallback mouse sensitivity fixes
Some checks failed
Build firmware / build-firmware (default) (push) Failing after 2s
Build firmware / build-firmware (oryx) (push) Failing after 2s

This commit is contained in:
Florian Didron
2025-12-16 19:27:16 +07:00
parent 9c1fd41b82
commit 9b08d56bac
2 changed files with 27 additions and 22 deletions

View File

@@ -37,11 +37,6 @@ extern uint8_t get_trackpad_input_mode(void);
// Button masks
#define BUTTON_PRIMARY 0x01
// Fallback mouse configuration
#ifndef TRACKPAD_MOUSE_SENSITIVITY
# define TRACKPAD_MOUSE_SENSITIVITY 1.0f
#endif
// Tap-to-click configuration
#ifndef TRACKPAD_TAP_TERM_MS
# define TRACKPAD_TAP_TERM_MS 200 // Maximum duration for a tap (ms)
@@ -78,6 +73,9 @@ static struct {
bool tracking;
uint16_t last_x;
uint16_t last_y;
// Subpixel accumulation for smooth low-sensitivity movement
float dx_accum;
float dy_accum;
// Tap detection - uses settled position like mouse mode
uint32_t touch_start_time;
uint16_t settled_x;
@@ -112,6 +110,8 @@ static void reset_mouse_state(void) {
send_mouse_report(0, 0, 0);
}
mouse_state.tracking = false;
mouse_state.dx_accum = 0.0f;
mouse_state.dy_accum = 0.0f;
mouse_state.touch_start_time = 0;
mouse_state.settled = false;
mouse_state.is_drag = false;
@@ -151,6 +151,9 @@ static void process_fallback_mouse(cgen6_report_t *sensor_report, bool finger_do
mouse_state.tracking = true;
mouse_state.last_x = sensor_report->fingers[0].x;
mouse_state.last_y = sensor_report->fingers[0].y;
// Reset subpixel accumulators for new touch
mouse_state.dx_accum = 0.0f;
mouse_state.dy_accum = 0.0f;
// Start tap detection with settle time approach
mouse_state.touch_start_time = timer_read32();
mouse_state.settled = false;
@@ -192,16 +195,19 @@ static void process_fallback_mouse(cgen6_report_t *sensor_report, bool finger_do
if (raw_dy < -TRACKPAD_MAX_DELTA) raw_dy = -TRACKPAD_MAX_DELTA;
if (raw_dx != 0 || raw_dy != 0) {
// Apply exponential acceleration for smooth cursor feel (like mouse mode)
float acc_dx = (raw_dx < 0) ? -powf(-raw_dx, 1.2f) : powf(raw_dx, 1.2f);
float acc_dy = (raw_dy < 0) ? -powf(-raw_dy, 1.2f) : powf(raw_dy, 1.2f);
// Apply configurable acceleration for cursor feel
float acc_dx = (raw_dx < 0) ? -powf(-raw_dx, TRACKPAD_MOUSE_ACCELERATION) : powf(raw_dx, TRACKPAD_MOUSE_ACCELERATION);
float acc_dy = (raw_dy < 0) ? -powf(-raw_dy, TRACKPAD_MOUSE_ACCELERATION) : powf(raw_dy, TRACKPAD_MOUSE_ACCELERATION);
// Apply sensitivity scaling
acc_dx *= TRACKPAD_MOUSE_SENSITIVITY;
acc_dy *= TRACKPAD_MOUSE_SENSITIVITY;
// Apply sensitivity scaling and accumulate for subpixel precision
mouse_state.dx_accum += acc_dx * TRACKPAD_MOUSE_SENSITIVITY;
mouse_state.dy_accum += acc_dy * TRACKPAD_MOUSE_SENSITIVITY;
dx = clamp_to_int8((int32_t)acc_dx);
dy = clamp_to_int8((int32_t)acc_dy);
// Extract integer portion for reporting, keep fractional for next frame
dx = clamp_to_int8((int32_t)mouse_state.dx_accum);
dy = clamp_to_int8((int32_t)mouse_state.dy_accum);
mouse_state.dx_accum -= dx;
mouse_state.dy_accum -= dy;
}
}

View File

@@ -7,12 +7,15 @@
#include "precision_trackpad_drivers.h"
#include "report.h"
// Trackpad sensitivity multiplier (1.0 = native, >1.0 = more sensitive)
// Higher values make cursor/gestures move faster
// Mouse fallback mode configuration (when host doesn't support PTP)
// TRACKPAD_MOUSE_SENSITIVITY: Movement multiplier (0.5 = slower, 1.0 = normal, 2.0 = faster)
// TRACKPAD_MOUSE_ACCELERATION: Acceleration curve exponent (1.0 = linear, 1.2 = moderate accel)
// Add to your config.h to customize:
// #define NAVIGATOR_TRACKPAD_SENSITIVITY 1.5f
#ifndef NAVIGATOR_TRACKPAD_SENSITIVITY
# define NAVIGATOR_TRACKPAD_SENSITIVITY 1.0f
#ifndef TRACKPAD_MOUSE_SENSITIVITY
# define TRACKPAD_MOUSE_SENSITIVITY 0.3f
#endif
#ifndef TRACKPAD_MOUSE_ACCELERATION
# define TRACKPAD_MOUSE_ACCELERATION 1.1f
#endif
#ifdef PRECISION_TRACKPAD_ENABLE
@@ -22,7 +25,3 @@ extern const precision_trackpad_driver_t navigator_trackpad_precision_trackpad_d
#error "NAVIGATOR_TRACKPAD_PTP_MODE must be defined when using the precision trackpad driver"
#endif
#endif
#ifndef NAVIGATOR_TRACKPAD_SENSITIVITY
# define NAVIGATOR_TRACKPAD_SENSITIVITY 1.3f
#endif