2021-11-15 06:03:24 +00:00
|
|
|
/* 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/>.
|
|
|
|
*/
|
|
|
|
|
2017-10-06 17:13:08 +00:00
|
|
|
#include "pointing_device.h"
|
2021-11-15 06:03:24 +00:00
|
|
|
#ifdef MOUSEKEY_ENABLE
|
|
|
|
# include "mousekey.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
|
2017-10-06 17:13:08 +00:00
|
|
|
|
|
|
|
static report_mouse_t mouseReport = {};
|
|
|
|
|
2021-11-15 06:03:24 +00:00
|
|
|
extern const pointing_device_driver_t pointing_device_driver;
|
|
|
|
|
|
|
|
__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) {}
|
|
|
|
__attribute__((weak)) report_mouse_t pointing_device_task_kb(report_mouse_t mouse_report) { return pointing_device_task_user(mouse_report); }
|
|
|
|
__attribute__((weak)) report_mouse_t pointing_device_task_user(report_mouse_t mouse_report) { return mouse_report; }
|
|
|
|
|
|
|
|
__attribute__((weak)) uint8_t pointing_device_handle_buttons(uint8_t buttons, bool pressed, pointing_device_buttons_t button) {
|
|
|
|
if (pressed) {
|
|
|
|
buttons |= 1 << (button);
|
|
|
|
} else {
|
|
|
|
buttons &= ~(1 << (button));
|
|
|
|
}
|
|
|
|
return buttons;
|
|
|
|
}
|
2021-02-04 01:25:05 +00:00
|
|
|
|
2019-08-30 18:19:03 +00:00
|
|
|
__attribute__((weak)) void pointing_device_init(void) {
|
2021-11-15 06:03:24 +00:00
|
|
|
pointing_device_driver.init();
|
|
|
|
#ifdef POINTING_DEVICE_MOTION_PIN
|
|
|
|
setPinInputHigh(POINTING_DEVICE_MOTION_PIN);
|
|
|
|
#endif
|
|
|
|
pointing_device_init_kb();
|
|
|
|
pointing_device_init_user();
|
2017-10-06 17:13:08 +00:00
|
|
|
}
|
|
|
|
|
2019-08-30 18:19:03 +00:00
|
|
|
__attribute__((weak)) void pointing_device_send(void) {
|
2021-02-04 01:25:05 +00:00
|
|
|
static report_mouse_t old_report = {};
|
|
|
|
|
2019-08-30 18:19:03 +00:00
|
|
|
// If you need to do other things, like debugging, this is the place to do it.
|
2021-02-04 01:25:05 +00:00
|
|
|
if (has_mouse_report_changed(mouseReport, old_report)) {
|
|
|
|
host_mouse_send(&mouseReport);
|
|
|
|
}
|
2019-08-30 18:19:03 +00:00
|
|
|
// 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;
|
2021-11-15 06:03:24 +00:00
|
|
|
|
|
|
|
memcpy(&old_report, &mouseReport, sizeof(mouseReport));
|
2017-10-06 17:13:08 +00:00
|
|
|
}
|
|
|
|
|
2019-08-30 18:19:03 +00:00
|
|
|
__attribute__((weak)) void pointing_device_task(void) {
|
2021-11-15 06:03:24 +00:00
|
|
|
// Gather report info
|
|
|
|
#ifdef POINTING_DEVICE_MOTION_PIN
|
|
|
|
if (!readPin(POINTING_DEVICE_MOTION_PIN))
|
|
|
|
#endif
|
|
|
|
mouseReport = pointing_device_driver.get_report(mouseReport);
|
|
|
|
|
|
|
|
// 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
|
|
|
|
mouseReport = pointing_device_task_kb(mouseReport);
|
|
|
|
// 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;
|
|
|
|
#endif
|
2017-10-06 17:13:08 +00:00
|
|
|
pointing_device_send();
|
|
|
|
}
|
|
|
|
|
2019-08-30 18:19:03 +00:00
|
|
|
report_mouse_t pointing_device_get_report(void) { return mouseReport; }
|
2017-10-06 17:13:08 +00:00
|
|
|
|
2020-12-27 17:36:32 +00:00
|
|
|
void pointing_device_set_report(report_mouse_t newMouseReport) { mouseReport = newMouseReport; }
|
2021-11-15 06:03:24 +00:00
|
|
|
|
|
|
|
uint16_t pointing_device_get_cpi(void) { return pointing_device_driver.get_cpi(); }
|
|
|
|
|
|
|
|
void pointing_device_set_cpi(uint16_t cpi) { pointing_device_driver.set_cpi(cpi); }
|