Move pointing device driver code (#24445)

Co-authored-by: Drashna Jaelre <drashna@live.com>
This commit is contained in:
Dasky 2024-10-25 18:11:51 +01:00 committed by GitHub
parent 5c85271e48
commit f5b495e06e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
23 changed files with 544 additions and 546 deletions

View File

@ -129,13 +129,13 @@ ifeq ($(strip $(POINTING_DEVICE_ENABLE)), yes)
MOUSE_ENABLE := yes
VPATH += $(QUANTUM_DIR)/pointing_device
SRC += $(QUANTUM_DIR)/pointing_device/pointing_device.c
SRC += $(QUANTUM_DIR)/pointing_device/pointing_device_drivers.c
SRC += $(QUANTUM_DIR)/pointing_device/pointing_device_auto_mouse.c
ifneq ($(strip $(POINTING_DEVICE_DRIVER)), custom)
SRC += drivers/sensors/$(strip $(POINTING_DEVICE_DRIVER)).c
OPT_DEFS += -DPOINTING_DEVICE_DRIVER_$(strip $(shell echo $(POINTING_DEVICE_DRIVER) | tr '[:lower:]' '[:upper:]'))
endif
OPT_DEFS += -DPOINTING_DEVICE_DRIVER_$(strip $(POINTING_DEVICE_DRIVER))
OPT_DEFS += -DPOINTING_DEVICE_DRIVER_NAME=$(strip $(POINTING_DEVICE_DRIVER))
ifeq ($(strip $(POINTING_DEVICE_DRIVER)), adns9800)
SPI_DRIVER_REQUIRED = yes
else ifeq ($(strip $(POINTING_DEVICE_DRIVER)), analog_joystick)

View File

@ -21,6 +21,7 @@
#include "wait.h"
#include "debug.h"
#include "gpio.h"
#include "pointing_device_internal.h"
// Registers
// clang-format off
@ -45,6 +46,13 @@
#define REG_MOTION_BURST 0x63
// clang-format on
const pointing_device_driver_t adns5050_pointing_device_driver = {
.init = adns5050_init,
.get_report = adns5050_get_report,
.set_cpi = adns5050_set_cpi,
.get_cpi = adns5050_get_cpi,
};
static bool powered_down = false;
void adns5050_init(void) {
@ -226,3 +234,15 @@ void adns5050_power_down(void) {
adns5050_write_reg(REG_MOUSE_CONTROL, 0b10);
}
}
report_mouse_t adns5050_get_report(report_mouse_t mouse_report) {
report_adns5050_t data = adns5050_read_burst();
if (data.dx != 0 || data.dy != 0) {
pd_dprintf("Raw ] X: %d, Y: %d\n", data.dx, data.dy);
mouse_report.x = (mouse_xy_report_t)data.dx;
mouse_report.y = (mouse_xy_report_t)data.dy;
}
return mouse_report;
}

View File

@ -21,6 +21,7 @@
#include <stdbool.h>
#include <stdint.h>
#include "pointing_device.h"
// CPI values
// clang-format off
@ -69,6 +70,8 @@ typedef struct {
int8_t dy;
} report_adns5050_t;
const pointing_device_driver_t adns5050_pointing_device_driver;
// A bunch of functions to implement the ADNS5050-specific serial protocol.
// Note that the "serial.h" driver is insufficient, because it does not
// manually manipulate a serial clock signal.
@ -84,3 +87,4 @@ uint16_t adns5050_get_cpi(void);
int8_t convert_twoscomp(uint8_t data);
bool adns5050_check_signature(void);
void adns5050_power_down(void);
report_mouse_t adns5050_get_report(report_mouse_t mouse_report);

View File

@ -77,6 +77,13 @@
#define MSB1 0x80
// clang-format on
const pointing_device_driver_t adns9800_pointing_device_driver = {
.init = adns9800_init,
.get_report = adns9800_get_report_driver,
.set_cpi = adns9800_set_cpi,
.get_cpi = adns9800_get_cpi,
};
uint16_t __attribute__((weak)) adns9800_srom_get_length(void) {
return 0;
}
@ -236,3 +243,12 @@ report_adns9800_t adns9800_get_report(void) {
return report;
}
report_mouse_t adns9800_get_report_driver(report_mouse_t mouse_report) {
report_adns9800_t sensor_report = adns9800_get_report();
mouse_report.x = CONSTRAIN_HID_XY(sensor_report.x);
mouse_report.y = CONSTRAIN_HID_XY(sensor_report.y);
return mouse_report;
}

View File

@ -17,6 +17,7 @@
#pragma once
#include <stdint.h>
#include "pointing_device.h"
#ifndef ADNS9800_CPI
# define ADNS9800_CPI 1600
@ -60,6 +61,8 @@ typedef struct {
int16_t y;
} report_adns9800_t;
const pointing_device_driver_t adns9800_pointing_device_driver;
void adns9800_init(void);
config_adns9800_t adns9800_get_config(void);
void adns9800_set_config(config_adns9800_t);
@ -67,3 +70,4 @@ uint16_t adns9800_get_cpi(void);
void adns9800_set_cpi(uint16_t cpi);
/* Reads and clears the current delta values on the ADNS sensor */
report_adns9800_t adns9800_get_report(void);
report_mouse_t adns9800_get_report_driver(report_mouse_t mouse_report);

View File

@ -20,6 +20,14 @@
#include "wait.h"
#include "timer.h"
#include <stdlib.h>
#include "pointing_device_internal.h"
const pointing_device_driver_t analog_joystick_pointing_device_driver = {
.init = analog_joystick_init,
.get_report = analog_joystick_get_report,
.set_cpi = NULL,
.get_cpi = NULL,
};
// Set Parameters
#ifndef ANALOG_JOYSTICK_AUTO_AXIS
@ -145,3 +153,16 @@ void analog_joystick_init(void) {
maxAxisValues[1] = yOrigin + 100;
#endif
}
report_mouse_t analog_joystick_get_report(report_mouse_t mouse_report) {
report_analog_joystick_t data = analog_joystick_read();
pd_dprintf("Raw ] X: %d, Y: %d\n", data.x, data.y);
mouse_report.x = data.x;
mouse_report.y = data.y;
mouse_report.buttons = pointing_device_handle_buttons(mouse_report.buttons, data.button, POINTING_DEVICE_BUTTON1);
return mouse_report;
}

View File

@ -18,6 +18,7 @@
#include <stdbool.h>
#include <stdint.h>
#include "pointing_device.h"
#ifndef ANALOG_JOYSTICK_X_AXIS_PIN
# error No pin specified for X Axis
@ -42,6 +43,8 @@
# define ANALOG_JOYSTICK_SPEED_MAX 2
#endif
const pointing_device_driver_t analog_joystick_pointing_device_driver;
typedef struct {
int8_t x;
int8_t y;
@ -49,3 +52,4 @@ typedef struct {
} report_analog_joystick_t;
report_analog_joystick_t analog_joystick_read(void);
void analog_joystick_init(void);
report_mouse_t analog_joystick_get_report(report_mouse_t mouse_report);

View File

@ -98,6 +98,13 @@
#define AZOTEQ_IQS5XX_INCH_TO_RESOLUTION_Y(inch) (DIVIDE_UNSIGNED_ROUND((inch) * (uint32_t)AZOTEQ_IQS5XX_HEIGHT_MM * 10, 254))
#define AZOTEQ_IQS5XX_RESOLUTION_Y_TO_INCH(px) (DIVIDE_UNSIGNED_ROUND((px) * (uint32_t)254, AZOTEQ_IQS5XX_HEIGHT_MM * 10))
const pointing_device_driver_t azoteq_iqs5xx_pointing_device_driver = {
.init = azoteq_iqs5xx_init,
.get_report = azoteq_iqs5xx_get_report,
.set_cpi = azoteq_iqs5xx_set_cpi,
.get_cpi = azoteq_iqs5xx_get_cpi,
};
static uint16_t azoteq_iqs5xx_product_number = AZOTEQ_IQS5XX_UNKNOWN;
static struct {
@ -312,3 +319,105 @@ void azoteq_iqs5xx_setup_resolution(void) {
azoteq_iqs5xx_device_resolution_t.resolution_y = AZOTEQ_IQS5XX_RESOLUTION_Y;
#endif
}
static i2c_status_t azoteq_iqs5xx_init_status = 1;
void azoteq_iqs5xx_init(void) {
i2c_init();
azoteq_iqs5xx_wake();
azoteq_iqs5xx_reset_suspend(true, false, true);
wait_ms(100);
azoteq_iqs5xx_wake();
if (azoteq_iqs5xx_get_product() != AZOTEQ_IQS5XX_UNKNOWN) {
azoteq_iqs5xx_setup_resolution();
azoteq_iqs5xx_init_status = azoteq_iqs5xx_set_report_rate(AZOTEQ_IQS5XX_REPORT_RATE, AZOTEQ_IQS5XX_ACTIVE, false);
azoteq_iqs5xx_init_status |= azoteq_iqs5xx_set_event_mode(false, false);
azoteq_iqs5xx_init_status |= azoteq_iqs5xx_set_reati(true, false);
#if defined(AZOTEQ_IQS5XX_ROTATION_90)
azoteq_iqs5xx_init_status |= azoteq_iqs5xx_set_xy_config(false, true, true, true, false);
#elif defined(AZOTEQ_IQS5XX_ROTATION_180)
azoteq_iqs5xx_init_status |= azoteq_iqs5xx_set_xy_config(true, true, false, true, false);
#elif defined(AZOTEQ_IQS5XX_ROTATION_270)
azoteq_iqs5xx_init_status |= azoteq_iqs5xx_set_xy_config(true, false, true, true, false);
#else
azoteq_iqs5xx_init_status |= azoteq_iqs5xx_set_xy_config(false, false, false, true, false);
#endif
azoteq_iqs5xx_init_status |= azoteq_iqs5xx_set_gesture_config(true);
wait_ms(AZOTEQ_IQS5XX_REPORT_RATE + 1);
}
};
report_mouse_t azoteq_iqs5xx_get_report(report_mouse_t mouse_report) {
report_mouse_t temp_report = {0};
static uint8_t previous_button_state = 0;
static uint8_t read_error_count = 0;
if (azoteq_iqs5xx_init_status == I2C_STATUS_SUCCESS) {
azoteq_iqs5xx_base_data_t base_data = {0};
#if !defined(POINTING_DEVICE_MOTION_PIN)
azoteq_iqs5xx_wake();
#endif
i2c_status_t status = azoteq_iqs5xx_get_base_data(&base_data);
bool ignore_movement = false;
if (status == I2C_STATUS_SUCCESS) {
// pd_dprintf("IQS5XX - previous cycle time: %d \n", base_data.previous_cycle_time);
read_error_count = 0;
if (base_data.gesture_events_0.single_tap || base_data.gesture_events_0.press_and_hold) {
pd_dprintf("IQS5XX - Single tap/hold.\n");
temp_report.buttons = pointing_device_handle_buttons(temp_report.buttons, true, POINTING_DEVICE_BUTTON1);
} else if (base_data.gesture_events_1.two_finger_tap) {
pd_dprintf("IQS5XX - Two finger tap.\n");
temp_report.buttons = pointing_device_handle_buttons(temp_report.buttons, true, POINTING_DEVICE_BUTTON2);
} else if (base_data.gesture_events_0.swipe_x_neg) {
pd_dprintf("IQS5XX - X-.\n");
temp_report.buttons = pointing_device_handle_buttons(temp_report.buttons, true, POINTING_DEVICE_BUTTON4);
ignore_movement = true;
} else if (base_data.gesture_events_0.swipe_x_pos) {
pd_dprintf("IQS5XX - X+.\n");
temp_report.buttons = pointing_device_handle_buttons(temp_report.buttons, true, POINTING_DEVICE_BUTTON5);
ignore_movement = true;
} else if (base_data.gesture_events_0.swipe_y_neg) {
pd_dprintf("IQS5XX - Y-.\n");
temp_report.buttons = pointing_device_handle_buttons(temp_report.buttons, true, POINTING_DEVICE_BUTTON6);
ignore_movement = true;
} else if (base_data.gesture_events_0.swipe_y_pos) {
pd_dprintf("IQS5XX - Y+.\n");
temp_report.buttons = pointing_device_handle_buttons(temp_report.buttons, true, POINTING_DEVICE_BUTTON3);
ignore_movement = true;
} else if (base_data.gesture_events_1.zoom) {
if (AZOTEQ_IQS5XX_COMBINE_H_L_BYTES(base_data.x.h, base_data.x.l) < 0) {
pd_dprintf("IQS5XX - Zoom out.\n");
temp_report.buttons = pointing_device_handle_buttons(temp_report.buttons, true, POINTING_DEVICE_BUTTON7);
} else if (AZOTEQ_IQS5XX_COMBINE_H_L_BYTES(base_data.x.h, base_data.x.l) > 0) {
pd_dprintf("IQS5XX - Zoom in.\n");
temp_report.buttons = pointing_device_handle_buttons(temp_report.buttons, true, POINTING_DEVICE_BUTTON8);
}
} else if (base_data.gesture_events_1.scroll) {
pd_dprintf("IQS5XX - Scroll.\n");
temp_report.h = CONSTRAIN_HID(AZOTEQ_IQS5XX_COMBINE_H_L_BYTES(base_data.x.h, base_data.x.l));
temp_report.v = CONSTRAIN_HID(AZOTEQ_IQS5XX_COMBINE_H_L_BYTES(base_data.y.h, base_data.y.l));
}
if (base_data.number_of_fingers == 1 && !ignore_movement) {
temp_report.x = CONSTRAIN_HID_XY(AZOTEQ_IQS5XX_COMBINE_H_L_BYTES(base_data.x.h, base_data.x.l));
temp_report.y = CONSTRAIN_HID_XY(AZOTEQ_IQS5XX_COMBINE_H_L_BYTES(base_data.y.h, base_data.y.l));
}
previous_button_state = temp_report.buttons;
} else {
if (read_error_count > 10) {
read_error_count = 0;
previous_button_state = 0;
} else {
read_error_count++;
}
temp_report.buttons = previous_button_state;
pd_dprintf("IQS5XX - get report failed: %d \n", status);
}
} else {
pd_dprintf("IQS5XX - Init failed: %d \n", azoteq_iqs5xx_init_status);
}
return temp_report;
}

View File

@ -176,6 +176,8 @@ typedef struct {
# define POINTING_DEVICE_TASK_THROTTLE_MS AZOTEQ_IQS5XX_REPORT_RATE
#endif
const pointing_device_driver_t azoteq_iqs5xx_pointing_device_driver;
void azoteq_iqs5xx_init(void);
i2c_status_t azoteq_iqs5xx_wake(void);
report_mouse_t azoteq_iqs5xx_get_report(report_mouse_t mouse_report);

View File

@ -4,6 +4,7 @@
// refer to documentation: Gen2 and Gen3 (Pinnacle ASIC) at https://www.cirque.com/documentation
#include "cirque_pinnacle.h"
#include "cirque_pinnacle_gestures.h"
#include "wait.h"
#include "timer.h"
@ -350,3 +351,144 @@ pinnacle_data_t cirque_pinnacle_read_data(void) {
result.valid = true;
return result;
}
#ifdef POINTING_DEVICE_GESTURES_CURSOR_GLIDE_ENABLE
static bool cursor_glide_enable = true;
static cursor_glide_context_t glide = {.config = {
.coef = 102, /* Good default friction coef */
.interval = 10, /* 100sps */
.trigger_px = 10, /* Default threshold in case of hover, set to 0 if you'd like */
}};
void cirque_pinnacle_enable_cursor_glide(bool enable) {
cursor_glide_enable = enable;
}
void cirque_pinnacle_configure_cursor_glide(float trigger_px) {
glide.config.trigger_px = trigger_px;
}
#endif
#if CIRQUE_PINNACLE_POSITION_MODE
# ifdef POINTING_DEVICE_AUTO_MOUSE_ENABLE
static bool is_touch_down;
bool auto_mouse_activation(report_mouse_t mouse_report) {
return is_touch_down || mouse_report.x != 0 || mouse_report.y != 0 || mouse_report.h != 0 || mouse_report.v != 0 || mouse_report.buttons;
}
# endif
report_mouse_t cirque_pinnacle_get_report(report_mouse_t mouse_report) {
uint16_t scale = cirque_pinnacle_get_scale();
pinnacle_data_t touchData = cirque_pinnacle_read_data();
mouse_xy_report_t report_x = 0, report_y = 0;
static uint16_t x = 0, y = 0, last_scale = 0;
# if defined(CIRQUE_PINNACLE_TAP_ENABLE)
mouse_report.buttons = pointing_device_handle_buttons(mouse_report.buttons, false, POINTING_DEVICE_BUTTON1);
# endif
# ifdef POINTING_DEVICE_GESTURES_CURSOR_GLIDE_ENABLE
cursor_glide_t glide_report = {0};
if (cursor_glide_enable) {
glide_report = cursor_glide_check(&glide);
}
# endif
if (!touchData.valid) {
# ifdef POINTING_DEVICE_GESTURES_CURSOR_GLIDE_ENABLE
if (cursor_glide_enable && glide_report.valid) {
report_x = glide_report.dx;
report_y = glide_report.dy;
goto mouse_report_update;
}
# endif
return mouse_report;
}
if (touchData.touchDown) {
pd_dprintf("cirque_pinnacle touchData x=%4d y=%4d z=%2d\n", touchData.xValue, touchData.yValue, touchData.zValue);
}
# ifdef POINTING_DEVICE_AUTO_MOUSE_ENABLE
is_touch_down = touchData.touchDown;
# endif
// Scale coordinates to arbitrary X, Y resolution
cirque_pinnacle_scale_data(&touchData, scale, scale);
if (!cirque_pinnacle_gestures(&mouse_report, touchData)) {
if (last_scale && scale == last_scale && x && y && touchData.xValue && touchData.yValue) {
report_x = CONSTRAIN_HID_XY((int16_t)(touchData.xValue - x));
report_y = CONSTRAIN_HID_XY((int16_t)(touchData.yValue - y));
}
x = touchData.xValue;
y = touchData.yValue;
last_scale = scale;
# ifdef POINTING_DEVICE_GESTURES_CURSOR_GLIDE_ENABLE
if (cursor_glide_enable) {
if (touchData.touchDown) {
cursor_glide_update(&glide, report_x, report_y, touchData.zValue);
} else if (!glide_report.valid) {
glide_report = cursor_glide_start(&glide);
if (glide_report.valid) {
report_x = glide_report.dx;
report_y = glide_report.dy;
}
}
}
# endif
}
# ifdef POINTING_DEVICE_GESTURES_CURSOR_GLIDE_ENABLE
mouse_report_update:
# endif
mouse_report.x = report_x;
mouse_report.y = report_y;
return mouse_report;
}
uint16_t cirque_pinnacle_get_cpi(void) {
return CIRQUE_PINNACLE_PX_TO_INCH(cirque_pinnacle_get_scale());
}
void cirque_pinnacle_set_cpi(uint16_t cpi) {
cirque_pinnacle_set_scale(CIRQUE_PINNACLE_INCH_TO_PX(cpi));
}
// clang-format off
const pointing_device_driver_t cirque_pinnacle_pointing_device_driver = {
.init = cirque_pinnacle_init,
.get_report = cirque_pinnacle_get_report,
.set_cpi = cirque_pinnacle_set_cpi,
.get_cpi = cirque_pinnacle_get_cpi
};
// clang-format on
#else
report_mouse_t cirque_pinnacle_get_report(report_mouse_t mouse_report) {
pinnacle_data_t touchData = cirque_pinnacle_read_data();
// Scale coordinates to arbitrary X, Y resolution
cirque_pinnacle_scale_data(&touchData, cirque_pinnacle_get_scale(), cirque_pinnacle_get_scale());
if (touchData.valid) {
mouse_report.buttons = touchData.buttons;
mouse_report.x = CONSTRAIN_HID_XY(touchData.xDelta);
mouse_report.y = CONSTRAIN_HID_XY(touchData.yDelta);
mouse_report.v = touchData.wheelCount;
}
return mouse_report;
}
// clang-format off
const pointing_device_driver_t cirque_pinnacle_pointing_device_driver = {
.init = cirque_pinnacle_init,
.get_report = cirque_pinnacle_get_report,
.set_cpi = cirque_pinnacle_set_scale,
.get_cpi = cirque_pinnacle_get_scale
};
// clang-format on
#endif

View File

@ -6,6 +6,7 @@
#include <stdint.h>
#include <stdbool.h>
#include "pointing_device_internal.h"
#include "pointing_device.h"
#ifndef CIRQUE_PINNACLE_TIMEOUT
# define CIRQUE_PINNACLE_TIMEOUT 20 // I2C timeout in milliseconds
@ -109,6 +110,10 @@ typedef struct {
#endif
} pinnacle_data_t;
#define cirque_pinnacle_i2c_pointing_device_driver cirque_pinnacle_pointing_device_driver
#define cirque_pinnacle_spi_pointing_device_driver cirque_pinnacle_pointing_device_driver
const pointing_device_driver_t cirque_pinnacle_pointing_device_driver;
void cirque_pinnacle_init(void);
void cirque_pinnacle_calibrate(void);
void cirque_pinnacle_cursor_smoothing(bool enable);
@ -116,3 +121,6 @@ pinnacle_data_t cirque_pinnacle_read_data(void);
void cirque_pinnacle_scale_data(pinnacle_data_t* coordinates, uint16_t xResolution, uint16_t yResolution);
uint16_t cirque_pinnacle_get_scale(void);
void cirque_pinnacle_set_scale(uint16_t scale);
uint16_t cirque_pinnacle_get_cpi(void);
void cirque_pinnacle_set_cpi(uint16_t cpi);
report_mouse_t cirque_pinnacle_get_report(report_mouse_t mouse_report);

View File

@ -20,6 +20,7 @@
#include "wait.h"
#include "debug.h"
#include "gpio.h"
#include "pointing_device_internal.h"
#define REG_PID1 0x00
#define REG_PID2 0x01
@ -50,6 +51,13 @@ void paw3204_serial_write(uint8_t reg_addr);
uint8_t paw3204_read_reg(uint8_t reg_addr);
void paw3204_write_reg(uint8_t reg_addr, uint8_t data);
const pointing_device_driver_t paw3204_pointing_device_driver = {
.init = paw3204_init,
.get_report = paw3204_get_report,
.set_cpi = paw3204_set_cpi,
.get_cpi = paw3204_get_cpi,
};
void paw3204_init(void) {
gpio_set_pin_output(PAW3204_SCLK_PIN); // setclockpin to output
gpio_set_pin_input_high(PAW3204_SDIO_PIN); // set datapin input high
@ -170,3 +178,15 @@ uint16_t paw3204_get_cpi(void) {
uint8_t read_pid_paw3204(void) {
return paw3204_read_reg(REG_PID1);
}
report_mouse_t paw3204_get_report(report_mouse_t mouse_report) {
report_paw3204_t data = paw3204_read();
if (data.isMotion) {
pd_dprintf("Raw ] X: %d, Y: %d\n", data.x, data.y);
mouse_report.x = data.x;
mouse_report.y = data.y;
}
return mouse_report;
}

View File

@ -18,6 +18,7 @@
#include <stdint.h>
#include <stdbool.h>
#include "pointing_device.h"
#ifndef PAW3204_SCLK_PIN
# ifdef POINTING_DEVICE_SCLK_PIN
@ -40,6 +41,8 @@ typedef struct {
bool isMotion;
} report_paw3204_t;
const pointing_device_driver_t paw3204_pointing_device_driver;
/**
* @brief Initializes the sensor so it is in a working state and ready to
* be polled for data.
@ -74,3 +77,5 @@ void paw3204_set_cpi(uint16_t cpi);
* @return uint16_t Current CPI value of the sensor
*/
uint16_t paw3204_get_cpi(void);
report_mouse_t paw3204_get_report(report_mouse_t mouse_report);

View File

@ -33,6 +33,13 @@
static uint16_t precision = 128;
const pointing_device_driver_t pimoroni_trackball_pointing_device_driver = {
.init = pimoroni_trackball_device_init,
.get_report = pimoroni_trackball_get_report,
.set_cpi = pimoroni_trackball_set_cpi,
.get_cpi = pimoroni_trackball_get_cpi,
};
uint16_t pimoroni_trackball_get_cpi(void) {
return (precision * 125);
}
@ -61,8 +68,8 @@ void pimoroni_trackball_set_rgbw(uint8_t r, uint8_t g, uint8_t b, uint8_t w) {
pd_dprintf("Trackball RGBW i2c_status_t: %d\n", status);
}
i2c_status_t read_pimoroni_trackball(pimoroni_data_t* data) {
i2c_status_t status = i2c_read_register(PIMORONI_TRACKBALL_ADDRESS << 1, PIMORONI_TRACKBALL_REG_LEFT, (uint8_t*)data, sizeof(*data), PIMORONI_TRACKBALL_TIMEOUT);
i2c_status_t read_pimoroni_trackball(pimoroni_data_t *data) {
i2c_status_t status = i2c_read_register(PIMORONI_TRACKBALL_ADDRESS << 1, PIMORONI_TRACKBALL_REG_LEFT, (uint8_t *)data, sizeof(*data), PIMORONI_TRACKBALL_TIMEOUT);
#ifdef POINTING_DEVICE_DEBUG
static uint16_t d_timer;
@ -92,3 +99,50 @@ int16_t pimoroni_trackball_get_offsets(uint8_t negative_dir, uint8_t positive_di
uint16_t magnitude = (scale * offset * offset * precision) >> 7;
return isnegative ? -(int16_t)(magnitude) : (int16_t)(magnitude);
}
mouse_xy_report_t pimoroni_trackball_adapt_values(xy_clamp_range_t *offset) {
if (*offset > XY_REPORT_MAX) {
*offset -= XY_REPORT_MAX;
return (mouse_xy_report_t)XY_REPORT_MAX;
} else if (*offset < XY_REPORT_MIN) {
*offset += XY_REPORT_MAX;
return (mouse_xy_report_t)XY_REPORT_MIN;
} else {
mouse_xy_report_t temp_return = *offset;
*offset = 0;
return temp_return;
}
}
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 xy_clamp_range_t x_offset = 0, y_offset = 0;
if (error_count < PIMORONI_TRACKBALL_ERROR_COUNT) {
i2c_status_t status = read_pimoroni_trackball(&pimoroni_data);
if (status == I2C_STATUS_SUCCESS) {
error_count = 0;
if (!(pimoroni_data.click & 128)) {
mouse_report.buttons = pointing_device_handle_buttons(mouse_report.buttons, false, POINTING_DEVICE_BUTTON1);
if (!debounce) {
x_offset += pimoroni_trackball_get_offsets(pimoroni_data.right, pimoroni_data.left, PIMORONI_TRACKBALL_SCALE);
y_offset += pimoroni_trackball_get_offsets(pimoroni_data.down, pimoroni_data.up, PIMORONI_TRACKBALL_SCALE);
mouse_report.x = pimoroni_trackball_adapt_values(&x_offset);
mouse_report.y = pimoroni_trackball_adapt_values(&y_offset);
} else {
debounce--;
}
} else {
mouse_report.buttons = pointing_device_handle_buttons(mouse_report.buttons, true, POINTING_DEVICE_BUTTON1);
debounce = PIMORONI_TRACKBALL_DEBOUNCE_CYCLES;
}
} else {
error_count++;
}
}
return mouse_report;
}

View File

@ -19,6 +19,7 @@
#include <stdint.h>
#include "report.h"
#include "i2c_master.h"
#include "pointing_device.h"
#ifndef PIMORONI_TRACKBALL_ADDRESS
# define PIMORONI_TRACKBALL_ADDRESS 0x0A
@ -49,9 +50,12 @@ typedef struct {
uint8_t click;
} pimoroni_data_t;
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);
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);
const pointing_device_driver_t pimoroni_trackball_pointing_device_driver;
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);
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);
report_mouse_t pimoroni_trackball_get_report(report_mouse_t mouse_report);

View File

@ -21,6 +21,14 @@
#include "wait.h"
#include "debug.h"
#include "gpio.h"
#include "pointing_device_internal.h"
const pointing_device_driver_t pmw3320_pointing_device_drivera = {
.init = pmw3320_init,
.get_report = pmw3320_get_report,
.set_cpi = pmw3320_set_cpi,
.get_cpi = pmw3320_get_cpi,
};
void pmw3320_init(void) {
// Initialize sensor serial pins.
@ -190,3 +198,15 @@ bool pmw3320_check_signature(void) {
return (pid == 0x3b && pid2 == 0xc4);
}
report_mouse_t pmw3320_get_report(report_mouse_t mouse_report) {
report_pmw3320_t data = pmw3320_read_burst();
if (data.dx != 0 || data.dy != 0) {
pd_dprintf("Raw ] X: %d, Y: %d\n", data.dx, data.dy);
mouse_report.x = (mouse_xy_report_t)data.dx;
mouse_report.y = (mouse_xy_report_t)data.dy;
}
return mouse_report;
}

View File

@ -21,6 +21,7 @@
#include <stdint.h>
#include <stdbool.h>
#include "pointing_device.h"
#define constrain(amt, low, high) ((amt) < (low) ? (low) : ((amt) > (high) ? (high) : (amt)))
@ -54,6 +55,8 @@ typedef struct {
int8_t dy;
} report_pmw3320_t;
const pointing_device_driver_t pmw3320_pointing_device_driver;
// A bunch of functions to implement the PMW3320-specific serial protocol.
// Mostly taken from ADNS5050 driver.
// Note that the "serial.h" driver is insufficient, because it does not
@ -69,6 +72,7 @@ void pmw3320_set_cpi(uint16_t cpi);
uint16_t pmw3320_get_cpi(void);
int8_t convert_twoscomp(uint8_t data);
bool pmw3320_check_signature(void);
report_mouse_t pmw3320_get_report(report_mouse_t mouse_report);
#if !defined(PMW3320_CPI)
# define PMW3320_CPI 1000

View File

@ -26,6 +26,13 @@ static bool in_burst_right[ARRAY_SIZE(cs_pins_right)] = {0};
bool __attribute__((cold)) pmw33xx_upload_firmware(uint8_t sensor);
bool __attribute__((cold)) pmw33xx_check_signature(uint8_t sensor);
const pointing_device_driver_t pmw33xx_pointing_device_driver = {
.init = pmw33xx_init_wrapper,
.get_report = pmw33xx_get_report,
.set_cpi = pmw33xx_set_cpi_wrapper,
.get_cpi = pmw33xx_get_cpi_wrapper,
};
uint16_t __attribute__((weak)) pmw33xx_srom_get_length(void) {
return 0;
}
@ -228,3 +235,38 @@ pmw33xx_report_t pmw33xx_read_burst(uint8_t sensor) {
return report;
}
void pmw33xx_init_wrapper(void) {
pmw33xx_init(0);
}
void pmw33xx_set_cpi_wrapper(uint16_t cpi) {
pmw33xx_set_cpi(0, cpi);
}
uint16_t pmw33xx_get_cpi_wrapper(void) {
return pmw33xx_get_cpi(0);
}
report_mouse_t pmw33xx_get_report(report_mouse_t mouse_report) {
pmw33xx_report_t report = pmw33xx_read_burst(0);
static bool in_motion = false;
if (report.motion.b.is_lifted) {
return mouse_report;
}
if (!report.motion.b.is_motion) {
in_motion = false;
return mouse_report;
}
if (!in_motion) {
in_motion = true;
pd_dprintf("PWM3360 (0): starting motion\n");
}
mouse_report.x = CONSTRAIN_HID_XY(report.delta_x);
mouse_report.y = CONSTRAIN_HID_XY(report.delta_y);
return mouse_report;
}

View File

@ -14,6 +14,7 @@
#include <stdint.h>
#include "spi_master.h"
#include "util.h"
#include "pointing_device.h"
#if defined(POINTING_DEVICE_DRIVER_pmw3360)
# include "pmw3360.h"
@ -102,6 +103,10 @@ _Static_assert(sizeof((pmw33xx_report_t){0}.motion) == 1, "pmw33xx_report_t.moti
#define CONSTRAIN(amt, low, high) ((amt) < (low) ? (low) : ((amt) > (high) ? (high) : (amt)))
#define pmw3360_pointing_device_driver pmw33xx_pointing_device_driver;
#define pmw3389_pointing_device_driver pmw33xx_pointing_device_driver;
const pointing_device_driver_t pmw33xx_pointing_device_driver;
/**
* @brief Initializes the given sensor so it is in a working state and ready to
* be polled for data.
@ -170,3 +175,8 @@ uint8_t pmw33xx_read(uint8_t sensor, uint8_t reg_addr);
* @return false Write failed, do not proceed operation
*/
bool pmw33xx_write(uint8_t sensor, uint8_t reg_addr, uint8_t data);
void pmw33xx_init_wrapper(void);
void pmw33xx_set_cpi_wrapper(uint16_t cpi);
uint16_t pmw33xx_get_cpi_wrapper(void);
report_mouse_t pmw33xx_get_report(report_mouse_t mouse_report);

View File

@ -79,7 +79,28 @@ uint16_t pointing_device_get_shared_cpi(void) {
static report_mouse_t local_mouse_report = {};
static bool pointing_device_force_send = false;
extern const pointing_device_driver_t pointing_device_driver;
#define POINTING_DEVICE_DRIVER_CONCAT(name) name##_pointing_device_driver
#define POINTING_DEVICE_DRIVER(name) POINTING_DEVICE_DRIVER_CONCAT(name)
#ifdef POINTING_DEVICE_DRIVER_custom
__attribute__((weak)) void pointing_device_driver_init(void) {}
__attribute__((weak)) report_mouse_t pointing_device_driver_get_report(report_mouse_t mouse_report) {
return mouse_report;
}
__attribute__((weak)) uint16_t pointing_device_driver_get_cpi(void) {
return 0;
}
__attribute__((weak)) void pointing_device_driver_set_cpi(uint16_t cpi) {}
const pointing_device_driver_t custom_pointing_device_driver = {
.init = pointing_device_driver_init,
.get_report = pointing_device_driver_get_report,
.get_cpi = pointing_device_driver_get_cpi,
.set_cpi = pointing_device_driver_set_cpi,
};
#endif
const pointing_device_driver_t *pointing_device_driver = &POINTING_DEVICE_DRIVER(POINTING_DEVICE_DRIVER_NAME);
/**
* @brief Keyboard level code pointing device initialisation
@ -146,7 +167,7 @@ __attribute__((weak)) void pointing_device_init(void) {
if ((POINTING_DEVICE_THIS_SIDE))
#endif
{
pointing_device_driver.init();
pointing_device_driver->init();
#ifdef POINTING_DEVICE_MOTION_PIN
# ifdef POINTING_DEVICE_MOTION_PIN_ACTIVE_LOW
gpio_set_pin_input_high(POINTING_DEVICE_MOTION_PIN);
@ -258,15 +279,15 @@ __attribute__((weak)) bool pointing_device_task(void) {
# if defined(POINTING_DEVICE_COMBINED)
static uint8_t old_buttons = 0;
local_mouse_report.buttons = old_buttons;
local_mouse_report = pointing_device_driver.get_report(local_mouse_report);
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)
local_mouse_report = POINTING_DEVICE_THIS_SIDE ? pointing_device_driver.get_report(local_mouse_report) : shared_mouse_report;
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
local_mouse_report = pointing_device_driver.get_report(local_mouse_report);
local_mouse_report = pointing_device_driver->get_report(local_mouse_report);
#endif // defined(SPLIT_POINTING_ENABLE)
#ifdef POINTING_DEVICE_MOTION_PIN
@ -331,9 +352,9 @@ void pointing_device_set_report(report_mouse_t mouse_report) {
*/
uint16_t pointing_device_get_cpi(void) {
#if defined(SPLIT_POINTING_ENABLE)
return POINTING_DEVICE_THIS_SIDE ? pointing_device_driver.get_cpi() : shared_cpi;
return POINTING_DEVICE_THIS_SIDE ? pointing_device_driver->get_cpi() : shared_cpi;
#else
return pointing_device_driver.get_cpi();
return pointing_device_driver->get_cpi();
#endif
}
@ -347,12 +368,12 @@ uint16_t pointing_device_get_cpi(void) {
void pointing_device_set_cpi(uint16_t cpi) {
#if defined(SPLIT_POINTING_ENABLE)
if (POINTING_DEVICE_THIS_SIDE) {
pointing_device_driver.set_cpi(cpi);
pointing_device_driver->set_cpi(cpi);
} else {
shared_cpi = cpi;
}
#else
pointing_device_driver.set_cpi(cpi);
pointing_device_driver->set_cpi(cpi);
#endif
}
@ -370,7 +391,7 @@ void pointing_device_set_cpi(uint16_t cpi) {
void pointing_device_set_cpi_on_side(bool left, uint16_t cpi) {
bool local = (is_keyboard_left() == left);
if (local) {
pointing_device_driver.set_cpi(cpi);
pointing_device_driver->set_cpi(cpi);
} else {
shared_cpi = cpi;
}

View File

@ -21,6 +21,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "host.h"
#include "report.h"
typedef struct {
void (*init)(void);
report_mouse_t (*get_report)(report_mouse_t mouse_report);
void (*set_cpi)(uint16_t);
uint16_t (*get_cpi)(void);
} pointing_device_driver_t;
#ifdef POINTING_DEVICE_AUTO_MOUSE_ENABLE
# include "pointing_device_auto_mouse.h"
#endif
@ -44,7 +51,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
# include "drivers/sensors/azoteq_iqs5xx.h"
#elif defined(POINTING_DEVICE_DRIVER_cirque_pinnacle_i2c) || defined(POINTING_DEVICE_DRIVER_cirque_pinnacle_spi)
# include "drivers/sensors/cirque_pinnacle.h"
# include "drivers/sensors/cirque_pinnacle_gestures.h"
# include "pointing_device_gestures.h"
#elif defined(POINTING_DEVICE_DRIVER_paw3204)
# include "drivers/sensors/paw3204.h"
@ -74,13 +80,6 @@ uint16_t pointing_device_driver_get_cpi(void);
void pointing_device_driver_set_cpi(uint16_t cpi);
#endif
typedef struct {
void (*init)(void);
report_mouse_t (*get_report)(report_mouse_t mouse_report);
void (*set_cpi)(uint16_t);
uint16_t (*get_cpi)(void);
} pointing_device_driver_t;
typedef enum {
POINTING_DEVICE_BUTTON1,
POINTING_DEVICE_BUTTON2,
@ -112,6 +111,9 @@ typedef int32_t hv_clamp_range_t;
typedef int16_t hv_clamp_range_t;
#endif
#define CONSTRAIN_HID(amt) ((amt) < INT8_MIN ? INT8_MIN : ((amt) > INT8_MAX ? INT8_MAX : (amt)))
#define CONSTRAIN_HID_XY(amt) ((amt) < XY_REPORT_MIN ? XY_REPORT_MIN : ((amt) > XY_REPORT_MAX ? XY_REPORT_MAX : (amt)))
void pointing_device_init(void);
bool pointing_device_task(void);
bool pointing_device_send(void);

View File

@ -1,514 +0,0 @@
/* Copyright 2017 Joshua Broekhuijsen <snipeye+qmk@gmail.com>
* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
* Copyright 2021 Dasky (@daskygit)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "pointing_device.h"
#include "pointing_device_internal.h"
#include "debug.h"
#include "wait.h"
#include "timer.h"
#include <stddef.h>
#define CONSTRAIN_HID(amt) ((amt) < INT8_MIN ? INT8_MIN : ((amt) > INT8_MAX ? INT8_MAX : (amt)))
#define CONSTRAIN_HID_XY(amt) ((amt) < XY_REPORT_MIN ? XY_REPORT_MIN : ((amt) > XY_REPORT_MAX ? XY_REPORT_MAX : (amt)))
// get_report functions should probably be moved to their respective drivers.
#if defined(POINTING_DEVICE_DRIVER_adns5050)
report_mouse_t adns5050_get_report(report_mouse_t mouse_report) {
report_adns5050_t data = adns5050_read_burst();
if (data.dx != 0 || data.dy != 0) {
pd_dprintf("Raw ] X: %d, Y: %d\n", data.dx, data.dy);
mouse_report.x = (mouse_xy_report_t)data.dx;
mouse_report.y = (mouse_xy_report_t)data.dy;
}
return mouse_report;
}
// clang-format off
const pointing_device_driver_t pointing_device_driver = {
.init = adns5050_init,
.get_report = adns5050_get_report,
.set_cpi = adns5050_set_cpi,
.get_cpi = adns5050_get_cpi,
};
// clang-format on
#elif defined(POINTING_DEVICE_DRIVER_pmw3320)
report_mouse_t pmw3320_get_report(report_mouse_t mouse_report) {
report_pmw3320_t data = pmw3320_read_burst();
if (data.dx != 0 || data.dy != 0) {
pd_dprintf("Raw ] X: %d, Y: %d\n", data.dx, data.dy);
mouse_report.x = (mouse_xy_report_t)data.dx;
mouse_report.y = (mouse_xy_report_t)data.dy;
}
return mouse_report;
}
// clang-format off
const pointing_device_driver_t pointing_device_driver = {
.init = pmw3320_init,
.get_report = pmw3320_get_report,
.set_cpi = pmw3320_set_cpi,
.get_cpi = pmw3320_get_cpi,
};
// clang-format on
#elif defined(POINTING_DEVICE_DRIVER_adns9800)
report_mouse_t adns9800_get_report_driver(report_mouse_t mouse_report) {
report_adns9800_t sensor_report = adns9800_get_report();
mouse_report.x = CONSTRAIN_HID_XY(sensor_report.x);
mouse_report.y = CONSTRAIN_HID_XY(sensor_report.y);
return mouse_report;
}
// clang-format off
const pointing_device_driver_t pointing_device_driver = {
.init = adns9800_init,
.get_report = adns9800_get_report_driver,
.set_cpi = adns9800_set_cpi,
.get_cpi = adns9800_get_cpi
};
// clang-format on
#elif defined(POINTING_DEVICE_DRIVER_analog_joystick)
report_mouse_t analog_joystick_get_report(report_mouse_t mouse_report) {
report_analog_joystick_t data = analog_joystick_read();
pd_dprintf("Raw ] X: %d, Y: %d\n", data.x, data.y);
mouse_report.x = data.x;
mouse_report.y = data.y;
mouse_report.buttons = pointing_device_handle_buttons(mouse_report.buttons, data.button, POINTING_DEVICE_BUTTON1);
return mouse_report;
}
// clang-format off
const pointing_device_driver_t pointing_device_driver = {
.init = analog_joystick_init,
.get_report = analog_joystick_get_report,
.set_cpi = NULL,
.get_cpi = NULL
};
// clang-format on
#elif defined(POINTING_DEVICE_DRIVER_azoteq_iqs5xx)
static i2c_status_t azoteq_iqs5xx_init_status = 1;
void azoteq_iqs5xx_init(void) {
i2c_init();
azoteq_iqs5xx_wake();
azoteq_iqs5xx_reset_suspend(true, false, true);
wait_ms(100);
azoteq_iqs5xx_wake();
if (azoteq_iqs5xx_get_product() != AZOTEQ_IQS5XX_UNKNOWN) {
azoteq_iqs5xx_setup_resolution();
azoteq_iqs5xx_init_status = azoteq_iqs5xx_set_report_rate(AZOTEQ_IQS5XX_REPORT_RATE, AZOTEQ_IQS5XX_ACTIVE, false);
azoteq_iqs5xx_init_status |= azoteq_iqs5xx_set_event_mode(false, false);
azoteq_iqs5xx_init_status |= azoteq_iqs5xx_set_reati(true, false);
# if defined(AZOTEQ_IQS5XX_ROTATION_90)
azoteq_iqs5xx_init_status |= azoteq_iqs5xx_set_xy_config(false, true, true, true, false);
# elif defined(AZOTEQ_IQS5XX_ROTATION_180)
azoteq_iqs5xx_init_status |= azoteq_iqs5xx_set_xy_config(true, true, false, true, false);
# elif defined(AZOTEQ_IQS5XX_ROTATION_270)
azoteq_iqs5xx_init_status |= azoteq_iqs5xx_set_xy_config(true, false, true, true, false);
# else
azoteq_iqs5xx_init_status |= azoteq_iqs5xx_set_xy_config(false, false, false, true, false);
# endif
azoteq_iqs5xx_init_status |= azoteq_iqs5xx_set_gesture_config(true);
wait_ms(AZOTEQ_IQS5XX_REPORT_RATE + 1);
}
};
report_mouse_t azoteq_iqs5xx_get_report(report_mouse_t mouse_report) {
report_mouse_t temp_report = {0};
static uint8_t previous_button_state = 0;
static uint8_t read_error_count = 0;
if (azoteq_iqs5xx_init_status == I2C_STATUS_SUCCESS) {
azoteq_iqs5xx_base_data_t base_data = {0};
# if !defined(POINTING_DEVICE_MOTION_PIN)
azoteq_iqs5xx_wake();
# endif
i2c_status_t status = azoteq_iqs5xx_get_base_data(&base_data);
bool ignore_movement = false;
if (status == I2C_STATUS_SUCCESS) {
// pd_dprintf("IQS5XX - previous cycle time: %d \n", base_data.previous_cycle_time);
read_error_count = 0;
if (base_data.gesture_events_0.single_tap || base_data.gesture_events_0.press_and_hold) {
pd_dprintf("IQS5XX - Single tap/hold.\n");
temp_report.buttons = pointing_device_handle_buttons(temp_report.buttons, true, POINTING_DEVICE_BUTTON1);
} else if (base_data.gesture_events_1.two_finger_tap) {
pd_dprintf("IQS5XX - Two finger tap.\n");
temp_report.buttons = pointing_device_handle_buttons(temp_report.buttons, true, POINTING_DEVICE_BUTTON2);
} else if (base_data.gesture_events_0.swipe_x_neg) {
pd_dprintf("IQS5XX - X-.\n");
temp_report.buttons = pointing_device_handle_buttons(temp_report.buttons, true, POINTING_DEVICE_BUTTON4);
ignore_movement = true;
} else if (base_data.gesture_events_0.swipe_x_pos) {
pd_dprintf("IQS5XX - X+.\n");
temp_report.buttons = pointing_device_handle_buttons(temp_report.buttons, true, POINTING_DEVICE_BUTTON5);
ignore_movement = true;
} else if (base_data.gesture_events_0.swipe_y_neg) {
pd_dprintf("IQS5XX - Y-.\n");
temp_report.buttons = pointing_device_handle_buttons(temp_report.buttons, true, POINTING_DEVICE_BUTTON6);
ignore_movement = true;
} else if (base_data.gesture_events_0.swipe_y_pos) {
pd_dprintf("IQS5XX - Y+.\n");
temp_report.buttons = pointing_device_handle_buttons(temp_report.buttons, true, POINTING_DEVICE_BUTTON3);
ignore_movement = true;
} else if (base_data.gesture_events_1.zoom) {
if (AZOTEQ_IQS5XX_COMBINE_H_L_BYTES(base_data.x.h, base_data.x.l) < 0) {
pd_dprintf("IQS5XX - Zoom out.\n");
temp_report.buttons = pointing_device_handle_buttons(temp_report.buttons, true, POINTING_DEVICE_BUTTON7);
} else if (AZOTEQ_IQS5XX_COMBINE_H_L_BYTES(base_data.x.h, base_data.x.l) > 0) {
pd_dprintf("IQS5XX - Zoom in.\n");
temp_report.buttons = pointing_device_handle_buttons(temp_report.buttons, true, POINTING_DEVICE_BUTTON8);
}
} else if (base_data.gesture_events_1.scroll) {
pd_dprintf("IQS5XX - Scroll.\n");
temp_report.h = CONSTRAIN_HID(AZOTEQ_IQS5XX_COMBINE_H_L_BYTES(base_data.x.h, base_data.x.l));
temp_report.v = CONSTRAIN_HID(AZOTEQ_IQS5XX_COMBINE_H_L_BYTES(base_data.y.h, base_data.y.l));
}
if (base_data.number_of_fingers == 1 && !ignore_movement) {
temp_report.x = CONSTRAIN_HID_XY(AZOTEQ_IQS5XX_COMBINE_H_L_BYTES(base_data.x.h, base_data.x.l));
temp_report.y = CONSTRAIN_HID_XY(AZOTEQ_IQS5XX_COMBINE_H_L_BYTES(base_data.y.h, base_data.y.l));
}
previous_button_state = temp_report.buttons;
} else {
if (read_error_count > 10) {
read_error_count = 0;
previous_button_state = 0;
} else {
read_error_count++;
}
temp_report.buttons = previous_button_state;
pd_dprintf("IQS5XX - get report failed: %d \n", status);
}
} else {
pd_dprintf("IQS5XX - Init failed: %d \n", azoteq_iqs5xx_init_status);
}
return temp_report;
}
// clang-format off
const pointing_device_driver_t pointing_device_driver = {
.init = azoteq_iqs5xx_init,
.get_report = azoteq_iqs5xx_get_report,
.set_cpi = azoteq_iqs5xx_set_cpi,
.get_cpi = azoteq_iqs5xx_get_cpi
};
// clang-format on
#elif defined(POINTING_DEVICE_DRIVER_cirque_pinnacle_i2c) || defined(POINTING_DEVICE_DRIVER_cirque_pinnacle_spi)
# ifdef POINTING_DEVICE_GESTURES_CURSOR_GLIDE_ENABLE
static bool cursor_glide_enable = true;
static cursor_glide_context_t glide = {.config = {
.coef = 102, /* Good default friction coef */
.interval = 10, /* 100sps */
.trigger_px = 10, /* Default threshold in case of hover, set to 0 if you'd like */
}};
void cirque_pinnacle_enable_cursor_glide(bool enable) {
cursor_glide_enable = enable;
}
void cirque_pinnacle_configure_cursor_glide(float trigger_px) {
glide.config.trigger_px = trigger_px;
}
# endif
# if CIRQUE_PINNACLE_POSITION_MODE
# ifdef POINTING_DEVICE_AUTO_MOUSE_ENABLE
static bool is_touch_down;
bool auto_mouse_activation(report_mouse_t mouse_report) {
return is_touch_down || mouse_report.x != 0 || mouse_report.y != 0 || mouse_report.h != 0 || mouse_report.v != 0 || mouse_report.buttons;
}
# endif
report_mouse_t cirque_pinnacle_get_report(report_mouse_t mouse_report) {
uint16_t scale = cirque_pinnacle_get_scale();
pinnacle_data_t touchData = cirque_pinnacle_read_data();
mouse_xy_report_t report_x = 0, report_y = 0;
static uint16_t x = 0, y = 0, last_scale = 0;
# if defined(CIRQUE_PINNACLE_TAP_ENABLE)
mouse_report.buttons = pointing_device_handle_buttons(mouse_report.buttons, false, POINTING_DEVICE_BUTTON1);
# endif
# ifdef POINTING_DEVICE_GESTURES_CURSOR_GLIDE_ENABLE
cursor_glide_t glide_report = {0};
if (cursor_glide_enable) {
glide_report = cursor_glide_check(&glide);
}
# endif
if (!touchData.valid) {
# ifdef POINTING_DEVICE_GESTURES_CURSOR_GLIDE_ENABLE
if (cursor_glide_enable && glide_report.valid) {
report_x = glide_report.dx;
report_y = glide_report.dy;
goto mouse_report_update;
}
# endif
return mouse_report;
}
if (touchData.touchDown) {
pd_dprintf("cirque_pinnacle touchData x=%4d y=%4d z=%2d\n", touchData.xValue, touchData.yValue, touchData.zValue);
}
# ifdef POINTING_DEVICE_AUTO_MOUSE_ENABLE
is_touch_down = touchData.touchDown;
# endif
// Scale coordinates to arbitrary X, Y resolution
cirque_pinnacle_scale_data(&touchData, scale, scale);
if (!cirque_pinnacle_gestures(&mouse_report, touchData)) {
if (last_scale && scale == last_scale && x && y && touchData.xValue && touchData.yValue) {
report_x = CONSTRAIN_HID_XY((int16_t)(touchData.xValue - x));
report_y = CONSTRAIN_HID_XY((int16_t)(touchData.yValue - y));
}
x = touchData.xValue;
y = touchData.yValue;
last_scale = scale;
# ifdef POINTING_DEVICE_GESTURES_CURSOR_GLIDE_ENABLE
if (cursor_glide_enable) {
if (touchData.touchDown) {
cursor_glide_update(&glide, report_x, report_y, touchData.zValue);
} else if (!glide_report.valid) {
glide_report = cursor_glide_start(&glide);
if (glide_report.valid) {
report_x = glide_report.dx;
report_y = glide_report.dy;
}
}
}
# endif
}
# ifdef POINTING_DEVICE_GESTURES_CURSOR_GLIDE_ENABLE
mouse_report_update:
# endif
mouse_report.x = report_x;
mouse_report.y = report_y;
return mouse_report;
}
uint16_t cirque_pinnacle_get_cpi(void) {
return CIRQUE_PINNACLE_PX_TO_INCH(cirque_pinnacle_get_scale());
}
void cirque_pinnacle_set_cpi(uint16_t cpi) {
cirque_pinnacle_set_scale(CIRQUE_PINNACLE_INCH_TO_PX(cpi));
}
// clang-format off
const pointing_device_driver_t pointing_device_driver = {
.init = cirque_pinnacle_init,
.get_report = cirque_pinnacle_get_report,
.set_cpi = cirque_pinnacle_set_cpi,
.get_cpi = cirque_pinnacle_get_cpi
};
// clang-format on
# else
report_mouse_t cirque_pinnacle_get_report(report_mouse_t mouse_report) {
pinnacle_data_t touchData = cirque_pinnacle_read_data();
// Scale coordinates to arbitrary X, Y resolution
cirque_pinnacle_scale_data(&touchData, cirque_pinnacle_get_scale(), cirque_pinnacle_get_scale());
if (touchData.valid) {
mouse_report.buttons = touchData.buttons;
mouse_report.x = CONSTRAIN_HID_XY(touchData.xDelta);
mouse_report.y = CONSTRAIN_HID_XY(touchData.yDelta);
mouse_report.v = touchData.wheelCount;
}
return mouse_report;
}
// clang-format off
const pointing_device_driver_t pointing_device_driver = {
.init = cirque_pinnacle_init,
.get_report = cirque_pinnacle_get_report,
.set_cpi = cirque_pinnacle_set_scale,
.get_cpi = cirque_pinnacle_get_scale
};
// clang-format on
# endif
#elif defined(POINTING_DEVICE_DRIVER_paw3204)
report_mouse_t paw3204_get_report(report_mouse_t mouse_report) {
report_paw3204_t data = paw3204_read();
if (data.isMotion) {
pd_dprintf("Raw ] X: %d, Y: %d\n", data.x, data.y);
mouse_report.x = data.x;
mouse_report.y = data.y;
}
return mouse_report;
}
const pointing_device_driver_t pointing_device_driver = {
.init = paw3204_init,
.get_report = paw3204_get_report,
.set_cpi = paw3204_set_cpi,
.get_cpi = paw3204_get_cpi,
};
#elif defined(POINTING_DEVICE_DRIVER_pimoroni_trackball)
mouse_xy_report_t pimoroni_trackball_adapt_values(xy_clamp_range_t* offset) {
if (*offset > XY_REPORT_MAX) {
*offset -= XY_REPORT_MAX;
return (mouse_xy_report_t)XY_REPORT_MAX;
} else if (*offset < XY_REPORT_MIN) {
*offset += XY_REPORT_MAX;
return (mouse_xy_report_t)XY_REPORT_MIN;
} else {
mouse_xy_report_t temp_return = *offset;
*offset = 0;
return temp_return;
}
}
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 xy_clamp_range_t x_offset = 0, y_offset = 0;
if (error_count < PIMORONI_TRACKBALL_ERROR_COUNT) {
i2c_status_t status = read_pimoroni_trackball(&pimoroni_data);
if (status == I2C_STATUS_SUCCESS) {
error_count = 0;
if (!(pimoroni_data.click & 128)) {
mouse_report.buttons = pointing_device_handle_buttons(mouse_report.buttons, false, POINTING_DEVICE_BUTTON1);
if (!debounce) {
x_offset += pimoroni_trackball_get_offsets(pimoroni_data.right, pimoroni_data.left, PIMORONI_TRACKBALL_SCALE);
y_offset += pimoroni_trackball_get_offsets(pimoroni_data.down, pimoroni_data.up, PIMORONI_TRACKBALL_SCALE);
mouse_report.x = pimoroni_trackball_adapt_values(&x_offset);
mouse_report.y = pimoroni_trackball_adapt_values(&y_offset);
} else {
debounce--;
}
} else {
mouse_report.buttons = pointing_device_handle_buttons(mouse_report.buttons, true, POINTING_DEVICE_BUTTON1);
debounce = PIMORONI_TRACKBALL_DEBOUNCE_CYCLES;
}
} else {
error_count++;
}
}
return mouse_report;
}
// clang-format off
const pointing_device_driver_t pointing_device_driver = {
.init = pimoroni_trackball_device_init,
.get_report = pimoroni_trackball_get_report,
.set_cpi = pimoroni_trackball_set_cpi,
.get_cpi = pimoroni_trackball_get_cpi
};
// clang-format on
#elif defined(POINTING_DEVICE_DRIVER_pmw3360) || defined(POINTING_DEVICE_DRIVER_pmw3389)
static void pmw33xx_init_wrapper(void) {
pmw33xx_init(0);
}
static void pmw33xx_set_cpi_wrapper(uint16_t cpi) {
pmw33xx_set_cpi(0, cpi);
}
static uint16_t pmw33xx_get_cpi_wrapper(void) {
return pmw33xx_get_cpi(0);
}
report_mouse_t pmw33xx_get_report(report_mouse_t mouse_report) {
pmw33xx_report_t report = pmw33xx_read_burst(0);
static bool in_motion = false;
if (report.motion.b.is_lifted) {
return mouse_report;
}
if (!report.motion.b.is_motion) {
in_motion = false;
return mouse_report;
}
if (!in_motion) {
in_motion = true;
pd_dprintf("PWM3360 (0): starting motion\n");
}
mouse_report.x = CONSTRAIN_HID_XY(report.delta_x);
mouse_report.y = CONSTRAIN_HID_XY(report.delta_y);
return mouse_report;
}
// clang-format off
const pointing_device_driver_t pointing_device_driver = {
.init = pmw33xx_init_wrapper,
.get_report = pmw33xx_get_report,
.set_cpi = pmw33xx_set_cpi_wrapper,
.get_cpi = pmw33xx_get_cpi_wrapper
};
// clang-format on
#else
__attribute__((weak)) void pointing_device_driver_init(void) {}
__attribute__((weak)) report_mouse_t pointing_device_driver_get_report(report_mouse_t mouse_report) {
return mouse_report;
}
__attribute__((weak)) uint16_t pointing_device_driver_get_cpi(void) {
return 0;
}
__attribute__((weak)) void pointing_device_driver_set_cpi(uint16_t cpi) {}
// clang-format off
const pointing_device_driver_t pointing_device_driver = {
.init = pointing_device_driver_init,
.get_report = pointing_device_driver_get_report,
.get_cpi = pointing_device_driver_get_cpi,
.set_cpi = pointing_device_driver_set_cpi
};
// clang-format on
#endif

View File

@ -733,7 +733,7 @@ static bool pointing_handlers_master(matrix_row_t master_matrix[], matrix_row_t
return okay;
}
extern const pointing_device_driver_t pointing_device_driver;
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)
@ -753,18 +753,18 @@ static void pointing_handlers_slave(matrix_row_t master_matrix[], matrix_row_t s
last_exec = timer_read32();
# endif
uint16_t temp_cpi = !pointing_device_driver.get_cpi ? 0 : pointing_device_driver.get_cpi(); // check for NULL
uint16_t temp_cpi = !pointing_device_driver->get_cpi ? 0 : pointing_device_driver->get_cpi(); // check for NULL
split_shared_memory_lock();
split_slave_pointing_sync_t pointing;
memcpy(&pointing, &split_shmem->pointing, sizeof(split_slave_pointing_sync_t));
split_shared_memory_unlock();
if (pointing.cpi && pointing.cpi != temp_cpi && pointing_device_driver.set_cpi) {
pointing_device_driver.set_cpi(pointing.cpi);
if (pointing.cpi && pointing.cpi != temp_cpi && pointing_device_driver->set_cpi) {
pointing_device_driver->set_cpi(pointing.cpi);
}
pointing.report = pointing_device_driver.get_report((report_mouse_t){0});
pointing.report = pointing_device_driver->get_report((report_mouse_t){0});
// Now update the checksum given that the pointing has been written to
pointing.checksum = crc8(&pointing.report, sizeof(report_mouse_t));