aboutsummaryrefslogtreecommitdiff
path: root/quantum/pointing_device
diff options
context:
space:
mode:
Diffstat (limited to 'quantum/pointing_device')
-rw-r--r--quantum/pointing_device/pointing_device.c86
-rw-r--r--quantum/pointing_device/pointing_device.h42
2 files changed, 97 insertions, 31 deletions
diff --git a/quantum/pointing_device/pointing_device.c b/quantum/pointing_device/pointing_device.c
index cac2875fc8..fe88d5a1af 100644
--- a/quantum/pointing_device/pointing_device.c
+++ b/quantum/pointing_device/pointing_device.c
@@ -25,6 +25,10 @@
# include "mousekey.h"
#endif
+#ifdef POINTING_DEVICE_HIRES_SCROLL_ENABLE
+# include "usb_descriptor_common.h"
+#endif
+
#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
@@ -76,14 +80,21 @@ uint16_t pointing_device_get_shared_cpi(void) {
#endif // defined(SPLIT_POINTING_ENABLE)
-static report_mouse_t local_mouse_report = {};
-static bool pointing_device_force_send = false;
+static report_mouse_t local_mouse_report = {};
+static bool pointing_device_force_send = false;
+static pointing_device_status_t pointing_device_status = POINTING_DEVICE_STATUS_UNKNOWN;
+
+#ifdef POINTING_DEVICE_HIRES_SCROLL_ENABLE
+static uint16_t hires_scroll_resolution;
+#endif
#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)) bool pointing_device_driver_init(void) {
+ return false;
+}
__attribute__((weak)) report_mouse_t pointing_device_driver_get_report(report_mouse_t mouse_report) {
return mouse_report;
}
@@ -102,6 +113,11 @@ const pointing_device_driver_t custom_pointing_device_driver = {
const pointing_device_driver_t *pointing_device_driver = &POINTING_DEVICE_DRIVER(POINTING_DEVICE_DRIVER_NAME);
+__attribute__((weak)) void pointing_device_init_modules(void) {}
+__attribute__((weak)) report_mouse_t pointing_device_task_modules(report_mouse_t mouse_report) {
+ return mouse_report;
+}
+
/**
* @brief Keyboard level code pointing device initialisation
*
@@ -167,7 +183,11 @@ __attribute__((weak)) void pointing_device_init(void) {
if ((POINTING_DEVICE_THIS_SIDE))
#endif
{
- pointing_device_driver->init();
+ if (pointing_device_driver->init()) {
+ pointing_device_status = POINTING_DEVICE_STATUS_SUCCESS;
+ } else {
+ pointing_device_status = POINTING_DEVICE_STATUS_INIT_FAILED;
+ }
#ifdef POINTING_DEVICE_MOTION_PIN
# ifdef POINTING_DEVICE_MOTION_PIN_ACTIVE_LOW
gpio_set_pin_input_high(POINTING_DEVICE_MOTION_PIN);
@@ -176,12 +196,41 @@ __attribute__((weak)) void pointing_device_init(void) {
# endif
#endif
}
+#ifdef POINTING_DEVICE_HIRES_SCROLL_ENABLE
+ hires_scroll_resolution = POINTING_DEVICE_HIRES_SCROLL_MULTIPLIER;
+ for (int i = 0; i < POINTING_DEVICE_HIRES_SCROLL_EXPONENT; i++) {
+ hires_scroll_resolution *= 10;
+ }
+#endif
+ pointing_device_init_modules();
pointing_device_init_kb();
pointing_device_init_user();
}
/**
+ * @brief Gets status of pointing device
+ *
+ * Returns current pointing device status
+ * @return pointing_device_status_t
+ */
+__attribute__((weak)) pointing_device_status_t pointing_device_get_status(void) {
+#ifdef SPLIT_POINTING_ENABLE
+ // Assume target side is always good, split transaction checksum should stop additional reports being generated.
+ return POINTING_DEVICE_THIS_SIDE ? pointing_device_status : POINTING_DEVICE_STATUS_SUCCESS;
+#else
+ return pointing_device_status;
+#endif
+}
+
+/**
+ * @brief Sets status of pointing device
+ */
+void pointing_device_set_status(pointing_device_status_t status) {
+ pointing_device_status = status;
+}
+
+/**
* @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.
@@ -262,6 +311,10 @@ __attribute__((weak)) bool pointing_device_task(void) {
last_exec = timer_read32();
#endif
+ if (pointing_device_get_status() != POINTING_DEVICE_STATUS_SUCCESS) {
+ return false;
+ }
+
// Gather report info
#ifdef POINTING_DEVICE_MOTION_PIN
# if defined(SPLIT_POINTING_ENABLE)
@@ -306,8 +359,9 @@ __attribute__((weak)) bool pointing_device_task(void) {
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
local_mouse_report = pointing_device_adjust_by_defines(local_mouse_report);
- local_mouse_report = pointing_device_task_kb(local_mouse_report);
#endif
+ local_mouse_report = pointing_device_task_modules(local_mouse_report);
+ local_mouse_report = pointing_device_task_kb(local_mouse_report);
// automatic mouse layer function
#ifdef POINTING_DEVICE_AUTO_MOUSE_ENABLE
pointing_device_task_auto_mouse(local_mouse_report);
@@ -404,10 +458,10 @@ void pointing_device_set_cpi_on_side(bool left, uint16_t cpi) {
* @return mouse_hv_report_t clamped value
*/
static inline mouse_hv_report_t pointing_device_hv_clamp(hv_clamp_range_t value) {
- if (value < HV_REPORT_MIN) {
- return HV_REPORT_MIN;
- } else if (value > HV_REPORT_MAX) {
- return HV_REPORT_MAX;
+ if (value < MOUSE_REPORT_HV_MIN) {
+ return MOUSE_REPORT_HV_MIN;
+ } else if (value > MOUSE_REPORT_HV_MAX) {
+ return MOUSE_REPORT_HV_MAX;
} else {
return value;
}
@@ -420,10 +474,10 @@ static inline mouse_hv_report_t pointing_device_hv_clamp(hv_clamp_range_t value)
* @return mouse_xy_report_t clamped value
*/
static inline mouse_xy_report_t pointing_device_xy_clamp(xy_clamp_range_t value) {
- if (value < XY_REPORT_MIN) {
- return XY_REPORT_MIN;
- } else if (value > XY_REPORT_MAX) {
- return XY_REPORT_MAX;
+ if (value < MOUSE_REPORT_XY_MIN) {
+ return MOUSE_REPORT_XY_MIN;
+ } else if (value > MOUSE_REPORT_XY_MAX) {
+ return MOUSE_REPORT_XY_MAX;
} else {
return value;
}
@@ -523,3 +577,9 @@ __attribute__((weak)) void pointing_device_keycode_handler(uint16_t keycode, boo
pointing_device_send();
}
}
+
+#ifdef POINTING_DEVICE_HIRES_SCROLL_ENABLE
+uint16_t pointing_device_get_hires_scroll_resolution(void) {
+ return hires_scroll_resolution;
+}
+#endif \ No newline at end of file
diff --git a/quantum/pointing_device/pointing_device.h b/quantum/pointing_device/pointing_device.h
index 72188c977d..5dfb9ce196 100644
--- a/quantum/pointing_device/pointing_device.h
+++ b/quantum/pointing_device/pointing_device.h
@@ -17,12 +17,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#pragma once
+#include <stdbool.h>
#include <stdint.h>
#include "host.h"
#include "report.h"
typedef struct {
- void (*init)(void);
+ bool (*init)(void);
report_mouse_t (*get_report)(report_mouse_t mouse_report);
void (*set_cpi)(uint16_t);
uint16_t (*get_cpi)(void);
@@ -74,7 +75,7 @@ typedef struct {
# include "drivers/sensors/pmw33xx_common.h"
# define POINTING_DEVICE_MOTION_PIN_ACTIVE_LOW
#else
-void pointing_device_driver_init(void);
+bool pointing_device_driver_init(void);
report_mouse_t pointing_device_driver_get_report(report_mouse_t mouse_report);
uint16_t pointing_device_driver_get_cpi(void);
void pointing_device_driver_set_cpi(uint16_t cpi);
@@ -91,36 +92,37 @@ typedef enum {
POINTING_DEVICE_BUTTON8,
} pointing_device_buttons_t;
+typedef enum {
+ POINTING_DEVICE_STATUS_UNKNOWN,
+ POINTING_DEVICE_STATUS_INIT_FAILED,
+ POINTING_DEVICE_STATUS_FAILED,
+ POINTING_DEVICE_STATUS_SUCCESS,
+} pointing_device_status_t;
+
#ifdef MOUSE_EXTENDED_REPORT
-# define XY_REPORT_MIN INT16_MIN
-# define XY_REPORT_MAX INT16_MAX
typedef int32_t xy_clamp_range_t;
#else
-# define XY_REPORT_MIN INT8_MIN
-# define XY_REPORT_MAX INT8_MAX
typedef int16_t xy_clamp_range_t;
#endif
#ifdef WHEEL_EXTENDED_REPORT
-# define HV_REPORT_MIN INT16_MIN
-# define HV_REPORT_MAX INT16_MAX
typedef int32_t hv_clamp_range_t;
#else
-# define HV_REPORT_MIN INT8_MIN
-# define HV_REPORT_MAX INT8_MAX
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)))
+#define CONSTRAIN_HID_XY(amt) ((amt) < MOUSE_REPORT_XY_MIN ? MOUSE_REPORT_XY_MIN : ((amt) > MOUSE_REPORT_XY_MAX ? MOUSE_REPORT_XY_MAX : (amt)))
-void pointing_device_init(void);
-bool pointing_device_task(void);
-bool pointing_device_send(void);
-report_mouse_t pointing_device_get_report(void);
-void pointing_device_set_report(report_mouse_t mouse_report);
-uint16_t pointing_device_get_cpi(void);
-void pointing_device_set_cpi(uint16_t cpi);
+void pointing_device_init(void);
+bool pointing_device_task(void);
+bool pointing_device_send(void);
+report_mouse_t pointing_device_get_report(void);
+void pointing_device_set_report(report_mouse_t mouse_report);
+uint16_t pointing_device_get_cpi(void);
+void pointing_device_set_cpi(uint16_t cpi);
+pointing_device_status_t pointing_device_get_status(void);
+void pointing_device_set_status(pointing_device_status_t status);
void pointing_device_init_kb(void);
void pointing_device_init_user(void);
@@ -130,6 +132,10 @@ uint8_t pointing_device_handle_buttons(uint8_t buttons, bool pressed, poi
report_mouse_t pointing_device_adjust_by_defines(report_mouse_t mouse_report);
void pointing_device_keycode_handler(uint16_t keycode, bool pressed);
+#ifdef POINTING_DEVICE_HIRES_SCROLL_ENABLE
+uint16_t pointing_device_get_hires_scroll_resolution(void);
+#endif
+
#if defined(SPLIT_POINTING_ENABLE)
void pointing_device_set_shared_report(report_mouse_t report);
uint16_t pointing_device_get_shared_cpi(void);