summaryrefslogtreecommitdiffstats
path: root/quantum/pointing_device
diff options
context:
space:
mode:
Diffstat (limited to 'quantum/pointing_device')
-rw-r--r--quantum/pointing_device/pointing_device.c28
-rw-r--r--quantum/pointing_device/pointing_device.h7
-rw-r--r--quantum/pointing_device/pointing_device_auto_mouse.c50
-rw-r--r--quantum/pointing_device/pointing_device_auto_mouse.h10
-rw-r--r--quantum/pointing_device/pointing_device_drivers.c22
5 files changed, 100 insertions, 17 deletions
diff --git a/quantum/pointing_device/pointing_device.c b/quantum/pointing_device/pointing_device.c
index 75bb5f81fc..abb3817b5f 100644
--- a/quantum/pointing_device/pointing_device.c
+++ b/quantum/pointing_device/pointing_device.c
@@ -74,7 +74,8 @@ uint16_t pointing_device_get_shared_cpi(void) {
#endif // defined(SPLIT_POINTING_ENABLE)
-static report_mouse_t local_mouse_report = {};
+static report_mouse_t local_mouse_report = {};
+static bool pointing_device_force_send = false;
extern const pointing_device_driver_t pointing_device_driver;
@@ -163,11 +164,11 @@ __attribute__((weak)) void pointing_device_init(void) {
* 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 = {};
+__attribute__((weak)) bool pointing_device_send(void) {
+ static report_mouse_t old_report = {};
+ bool should_send_report = has_mouse_report_changed(&local_mouse_report, &old_report);
- // If you need to do other things, like debugging, this is the place to do it.
- if (has_mouse_report_changed(&local_mouse_report, &old_report)) {
+ if (should_send_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
@@ -175,6 +176,8 @@ __attribute__((weak)) void pointing_device_send(void) {
memset(&local_mouse_report, 0, sizeof(local_mouse_report));
local_mouse_report.buttons = buttons;
memcpy(&old_report, &local_mouse_report, sizeof(local_mouse_report));
+
+ return should_send_report || buttons;
}
/**
@@ -220,18 +223,18 @@ report_mouse_t pointing_device_adjust_by_defines(report_mouse_t mouse_report) {
* It applies any optional configuration e.g. rotation or axis inversion and then initiates a send.
*
*/
-__attribute__((weak)) void pointing_device_task(void) {
+__attribute__((weak)) bool pointing_device_task(void) {
#if defined(SPLIT_POINTING_ENABLE)
// Don't poll the target side pointing device.
if (!is_keyboard_master()) {
- return;
+ return false;
};
#endif
#if (POINTING_DEVICE_TASK_THROTTLE_MS > 0)
static uint32_t last_exec = 0;
if (timer_elapsed32(last_exec) < POINTING_DEVICE_TASK_THROTTLE_MS) {
- return;
+ return false;
}
last_exec = timer_read32();
#endif
@@ -286,7 +289,11 @@ __attribute__((weak)) void pointing_device_task(void) {
report_mouse_t mousekey_report = mousekey_get_report();
local_mouse_report.buttons = local_mouse_report.buttons | mousekey_report.buttons;
#endif
- pointing_device_send();
+
+ const bool send_report = pointing_device_send() || pointing_device_force_send;
+ pointing_device_force_send = false;
+
+ return send_report;
}
/**
@@ -304,7 +311,8 @@ report_mouse_t pointing_device_get_report(void) {
* @param[in] mouse_report
*/
void pointing_device_set_report(report_mouse_t mouse_report) {
- local_mouse_report = mouse_report;
+ pointing_device_force_send = has_mouse_report_changed(&local_mouse_report, &mouse_report);
+ memcpy(&local_mouse_report, &mouse_report, sizeof(local_mouse_report));
}
/**
diff --git a/quantum/pointing_device/pointing_device.h b/quantum/pointing_device/pointing_device.h
index d430e6cfa4..afd653eaee 100644
--- a/quantum/pointing_device/pointing_device.h
+++ b/quantum/pointing_device/pointing_device.h
@@ -28,6 +28,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#if defined(POINTING_DEVICE_DRIVER_adns5050)
# include "drivers/sensors/adns5050.h"
# define POINTING_DEVICE_MOTION_PIN_ACTIVE_LOW
+#elif defined(POINTING_DEVICE_DRIVER_pmw3320)
+# include "drivers/sensors/pmw3320.h"
+# define POINTING_DEVICE_MOTION_PIN_ACTIVE_LOW
#elif defined(POINTING_DEVICE_DRIVER_adns9800)
# include "spi_master.h"
# include "drivers/sensors/adns9800.h"
@@ -97,8 +100,8 @@ typedef int16_t clamp_range_t;
#endif
void pointing_device_init(void);
-void pointing_device_task(void);
-void pointing_device_send(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);
diff --git a/quantum/pointing_device/pointing_device_auto_mouse.c b/quantum/pointing_device/pointing_device_auto_mouse.c
index 5e78817c7c..b008d18db5 100644
--- a/quantum/pointing_device/pointing_device_auto_mouse.c
+++ b/quantum/pointing_device/pointing_device_auto_mouse.c
@@ -20,7 +20,11 @@
# include "pointing_device_auto_mouse.h"
/* local data structure for tracking auto mouse */
-static auto_mouse_context_t auto_mouse_context = {.config.layer = (uint8_t)AUTO_MOUSE_DEFAULT_LAYER};
+static auto_mouse_context_t auto_mouse_context = {
+ .config.layer = (uint8_t)(AUTO_MOUSE_DEFAULT_LAYER),
+ .config.timeout = (uint16_t)(AUTO_MOUSE_TIME),
+ .config.debounce = (uint8_t)(AUTO_MOUSE_DEBOUNCE),
+};
/* local functions */
static bool is_mouse_record(uint16_t keycode, keyrecord_t* record);
@@ -63,6 +67,24 @@ uint8_t get_auto_mouse_layer(void) {
}
/**
+ * @brief Get the current timeout to turn off mouse layer
+ *
+ * @return uint16_t timeout in ms
+ */
+uint16_t get_auto_mouse_timeout(void) {
+ return auto_mouse_context.config.timeout;
+}
+
+/**
+ * @brief Get the auto mouse debouncing timeout
+ *
+ * @return uint8_t
+ */
+uint8_t get_auto_mouse_debounce(void) {
+ return auto_mouse_context.config.debounce;
+}
+
+/**
* @brief get layer_toggled value
*
* @return bool of current layer_toggled state
@@ -115,6 +137,28 @@ void set_auto_mouse_layer(uint8_t layer) {
}
/**
+ * @brief Changes the timeout for the mouse auto layer to be disabled
+ *
+ * @param timeout
+ */
+void set_auto_mouse_timeout(uint16_t timeout) {
+ if (auto_mouse_context.config.timeout == timeout) return;
+ auto_mouse_context.config.timeout = timeout;
+ auto_mouse_reset();
+}
+
+/**
+ * @brief Set the auto mouse key debounce
+ *
+ * @param debounce
+ */
+void set_auto_mouse_debounce(uint8_t debounce) {
+ if (auto_mouse_context.config.debounce == debounce) return;
+ auto_mouse_context.config.debounce = debounce;
+ auto_mouse_reset();
+}
+
+/**
* @brief toggle mouse layer setting
*
* Change state of local layer_toggled bool meant to track when the mouse layer is toggled on by other means
@@ -181,7 +225,7 @@ __attribute__((weak)) bool auto_mouse_activation(report_mouse_t mouse_report) {
*/
void pointing_device_task_auto_mouse(report_mouse_t mouse_report) {
// skip if disabled, delay timer running, or debounce
- if (!(AUTO_MOUSE_ENABLED) || timer_elapsed(auto_mouse_context.timer.active) <= AUTO_MOUSE_DEBOUNCE || timer_elapsed(auto_mouse_context.timer.delay) <= AUTO_MOUSE_DELAY) {
+ if (!(AUTO_MOUSE_ENABLED) || timer_elapsed(auto_mouse_context.timer.active) <= auto_mouse_context.config.debounce || timer_elapsed(auto_mouse_context.timer.delay) <= AUTO_MOUSE_DELAY) {
return;
}
// update activation and reset debounce
@@ -192,7 +236,7 @@ void pointing_device_task_auto_mouse(report_mouse_t mouse_report) {
if (!layer_state_is((AUTO_MOUSE_TARGET_LAYER))) {
layer_on((AUTO_MOUSE_TARGET_LAYER));
}
- } else if (layer_state_is((AUTO_MOUSE_TARGET_LAYER)) && timer_elapsed(auto_mouse_context.timer.active) > AUTO_MOUSE_TIME) {
+ } else if (layer_state_is((AUTO_MOUSE_TARGET_LAYER)) && timer_elapsed(auto_mouse_context.timer.active) > auto_mouse_context.config.timeout) {
layer_off((AUTO_MOUSE_TARGET_LAYER));
auto_mouse_context.timer.active = 0;
}
diff --git a/quantum/pointing_device/pointing_device_auto_mouse.h b/quantum/pointing_device/pointing_device_auto_mouse.h
index 0f26af79e6..7db63bc6b8 100644
--- a/quantum/pointing_device/pointing_device_auto_mouse.h
+++ b/quantum/pointing_device/pointing_device_auto_mouse.h
@@ -43,8 +43,10 @@
/* data structure */
typedef struct {
struct {
- bool is_enabled;
- uint8_t layer;
+ bool is_enabled;
+ uint8_t layer;
+ uint16_t timeout;
+ uint8_t debounce;
} config;
struct {
uint16_t active;
@@ -62,6 +64,10 @@ void set_auto_mouse_enable(bool enable); // enabl
bool get_auto_mouse_enable(void); // get auto_mouse_enable
void set_auto_mouse_layer(uint8_t layer); // set target layer by index
uint8_t get_auto_mouse_layer(void); // get target layer index
+void set_auto_mouse_timeout(uint16_t timeout); // set layer timeout
+uint16_t get_auto_mouse_timeout(void); // get layer timeout
+void set_auto_mouse_debounce(uint8_t debounce); // set debounce
+uint8_t get_auto_mouse_debounce(void); // get debounce
void auto_mouse_layer_off(void); // disable target layer if appropriate (DO NOT USE in layer_state_set stack!!)
layer_state_t remove_auto_mouse_layer(layer_state_t state, bool force); // remove auto mouse target layer from state if appropriate (can be forced)
diff --git a/quantum/pointing_device/pointing_device_drivers.c b/quantum/pointing_device/pointing_device_drivers.c
index d6f29c062e..9a4315f76f 100644
--- a/quantum/pointing_device/pointing_device_drivers.c
+++ b/quantum/pointing_device/pointing_device_drivers.c
@@ -50,6 +50,28 @@ const pointing_device_driver_t pointing_device_driver = {
};
// 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) {