summaryrefslogtreecommitdiffstats
path: root/tmk_core/common
diff options
context:
space:
mode:
Diffstat (limited to 'tmk_core/common')
-rw-r--r--tmk_core/common/action.c26
-rw-r--r--tmk_core/common/avr/bootloader.c10
-rw-r--r--tmk_core/common/avr/suspend.c5
-rw-r--r--tmk_core/common/chibios/suspend.c7
-rw-r--r--tmk_core/common/keyboard.c37
-rw-r--r--tmk_core/common/keyboard.h9
-rw-r--r--tmk_core/common/keycode.h14
-rw-r--r--tmk_core/common/mousekey.c446
-rw-r--r--tmk_core/common/mousekey.h142
-rw-r--r--tmk_core/common/print.h10
-rw-r--r--tmk_core/common/report.h5
-rw-r--r--tmk_core/common/suspend.h4
-rw-r--r--tmk_core/common/sync_timer.c58
-rw-r--r--tmk_core/common/sync_timer.h54
-rw-r--r--tmk_core/common/uart.c172
-rw-r--r--tmk_core/common/uart.h8
-rw-r--r--tmk_core/common/wait.h79
17 files changed, 283 insertions, 803 deletions
diff --git a/tmk_core/common/action.c b/tmk_core/common/action.c
index a7432bae59..ef01a71776 100644
--- a/tmk_core/common/action.c
+++ b/tmk_core/common/action.c
@@ -443,6 +443,15 @@ void process_action(keyrecord_t *record, action_t action) {
case KC_MS_BTN5:
register_button(true, MOUSE_BTN5);
break;
+ case KC_MS_BTN6:
+ register_button(true, MOUSE_BTN6);
+ break;
+ case KC_MS_BTN7:
+ register_button(true, MOUSE_BTN7);
+ break;
+ case KC_MS_BTN8:
+ register_button(true, MOUSE_BTN8);
+ break;
# endif
default:
mousekey_send();
@@ -469,6 +478,15 @@ void process_action(keyrecord_t *record, action_t action) {
case KC_MS_BTN5:
register_button(false, MOUSE_BTN5);
break;
+ case KC_MS_BTN6:
+ register_button(false, MOUSE_BTN6);
+ break;
+ case KC_MS_BTN7:
+ register_button(false, MOUSE_BTN7);
+ break;
+ case KC_MS_BTN8:
+ register_button(false, MOUSE_BTN8);
+ break;
# endif
default:
mousekey_send();
@@ -1017,6 +1035,10 @@ void clear_keyboard_but_mods(void) {
* FIXME: Needs documentation.
*/
void clear_keyboard_but_mods_and_keys() {
+#ifdef EXTRAKEY_ENABLE
+ host_system_send(0);
+ host_consumer_send(0);
+#endif
clear_weak_mods();
clear_macro_mods();
send_keyboard_report();
@@ -1024,10 +1046,6 @@ void clear_keyboard_but_mods_and_keys() {
mousekey_clear();
mousekey_send();
#endif
-#ifdef EXTRAKEY_ENABLE
- host_system_send(0);
- host_consumer_send(0);
-#endif
}
/** \brief Utilities for actions. (FIXME: Needs better description)
diff --git a/tmk_core/common/avr/bootloader.c b/tmk_core/common/avr/bootloader.c
index a1db55da93..4e3a27022d 100644
--- a/tmk_core/common/avr/bootloader.c
+++ b/tmk_core/common/avr/bootloader.c
@@ -77,7 +77,7 @@ uint32_t reset_key __attribute__((section(".noinit,\"aw\",@nobits;")));
*
* FIXME: needs doc
*/
-void bootloader_jump(void) {
+__attribute__((weak)) void bootloader_jump(void) {
#if !defined(BOOTLOADER_SIZE)
uint8_t high_fuse = boot_lock_fuse_bits_get(GET_HIGH_FUSE_BITS);
@@ -237,13 +237,13 @@ void bootloader_jump(void) {
"bootloader_startup_loop%=: \n\t"
"rjmp bootloader_startup_loop%= \n\t"
:
- : [mcucsrio] "I"(_SFR_IO_ADDR(MCUCSR)),
+ : [ mcucsrio ] "I"(_SFR_IO_ADDR(MCUCSR)),
# if (FLASHEND > 131071)
- [ramendhi] "M"(((RAMEND - 2) >> 8) & 0xff), [ramendlo] "M"(((RAMEND - 2) >> 0) & 0xff), [bootaddrhi] "M"((((FLASH_SIZE - BOOTLOADER_SIZE) >> 1) >> 16) & 0xff),
+ [ ramendhi ] "M"(((RAMEND - 2) >> 8) & 0xff), [ ramendlo ] "M"(((RAMEND - 2) >> 0) & 0xff), [ bootaddrhi ] "M"((((FLASH_SIZE - BOOTLOADER_SIZE) >> 1) >> 16) & 0xff),
# else
- [ramendhi] "M"(((RAMEND - 1) >> 8) & 0xff), [ramendlo] "M"(((RAMEND - 1) >> 0) & 0xff),
+ [ ramendhi ] "M"(((RAMEND - 1) >> 8) & 0xff), [ ramendlo ] "M"(((RAMEND - 1) >> 0) & 0xff),
# endif
- [bootaddrme] "M"((((FLASH_SIZE - BOOTLOADER_SIZE) >> 1) >> 8) & 0xff), [bootaddrlo] "M"((((FLASH_SIZE - BOOTLOADER_SIZE) >> 1) >> 0) & 0xff));
+ [ bootaddrme ] "M"((((FLASH_SIZE - BOOTLOADER_SIZE) >> 1) >> 8) & 0xff), [ bootaddrlo ] "M"((((FLASH_SIZE - BOOTLOADER_SIZE) >> 1) >> 0) & 0xff));
#else // Assume remaining boards are DFU, even if the flag isn't set
diff --git a/tmk_core/common/avr/suspend.c b/tmk_core/common/avr/suspend.c
index 86c3df040a..b784a0835d 100644
--- a/tmk_core/common/avr/suspend.c
+++ b/tmk_core/common/avr/suspend.c
@@ -97,13 +97,11 @@ static void power_down(uint8_t wdto) {
led_set(leds_off);
# ifdef AUDIO_ENABLE
- // This sometimes disables the start-up noise, so it's been disabled
- // stop_all_notes();
+ stop_all_notes();
# endif /* AUDIO_ENABLE */
# if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE)
rgblight_suspend();
# endif
- suspend_power_down_kb();
// TODO: more power saving
// See PicoPower application note
@@ -157,6 +155,7 @@ __attribute__((weak)) void suspend_wakeup_init_user(void) {}
* FIXME: needs doc
*/
__attribute__((weak)) void suspend_wakeup_init_kb(void) { suspend_wakeup_init_user(); }
+
/** \brief run immediately after wakeup
*
* FIXME: needs doc
diff --git a/tmk_core/common/chibios/suspend.c b/tmk_core/common/chibios/suspend.c
index 796056019f..49e20641fb 100644
--- a/tmk_core/common/chibios/suspend.c
+++ b/tmk_core/common/chibios/suspend.c
@@ -12,6 +12,10 @@
#include "led.h"
#include "wait.h"
+#ifdef AUDIO_ENABLE
+# include "audio.h"
+#endif /* AUDIO_ENABLE */
+
#ifdef BACKLIGHT_ENABLE
# include "backlight.h"
#endif
@@ -65,6 +69,9 @@ void suspend_power_down(void) {
#if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE)
rgblight_suspend();
#endif
+#ifdef AUDIO_ENABLE
+ stop_all_notes();
+#endif /* AUDIO_ENABLE */
suspend_power_down_kb();
// on AVR, this enables the watchdog for 15ms (max), and goes to
diff --git a/tmk_core/common/keyboard.c b/tmk_core/common/keyboard.c
index 7120cdacdf..40989ca4c6 100644
--- a/tmk_core/common/keyboard.c
+++ b/tmk_core/common/keyboard.c
@@ -23,6 +23,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "led.h"
#include "keycode.h"
#include "timer.h"
+#include "sync_timer.h"
#include "print.h"
#include "debug.h"
#include "command.h"
@@ -96,6 +97,20 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
# include "dip_switch.h"
#endif
+static uint32_t last_input_modification_time = 0;
+uint32_t last_input_activity_time(void) { return last_input_modification_time; }
+uint32_t last_input_activity_elapsed(void) { return timer_elapsed32(last_input_modification_time); }
+
+static uint32_t last_matrix_modification_time = 0;
+uint32_t last_matrix_activity_time(void) { return last_matrix_modification_time; }
+uint32_t last_matrix_activity_elapsed(void) { return timer_elapsed32(last_matrix_modification_time); }
+void last_matrix_activity_trigger(void) { last_matrix_modification_time = last_input_modification_time = timer_read32(); }
+
+static uint32_t last_encoder_modification_time = 0;
+uint32_t last_encoder_activity_time(void) { return last_encoder_modification_time; }
+uint32_t last_encoder_activity_elapsed(void) { return timer_elapsed32(last_encoder_modification_time); }
+void last_encoder_activity_trigger(void) { last_encoder_modification_time = last_input_modification_time = timer_read32(); }
+
// Only enable this if console is enabled to print to
#if defined(DEBUG_MATRIX_SCAN_RATE)
static uint32_t matrix_timer = 0;
@@ -260,6 +275,7 @@ __attribute__((weak)) void housekeeping_task_user(void) {}
*/
void keyboard_init(void) {
timer_init();
+ sync_timer_init();
matrix_init();
#ifdef VIA_ENABLE
via_init();
@@ -337,15 +353,15 @@ void keyboard_task(void) {
#ifdef QMK_KEYS_PER_SCAN
uint8_t keys_processed = 0;
#endif
+#ifdef ENCODER_ENABLE
+ bool encoders_changed = false;
+#endif
housekeeping_task_kb();
housekeeping_task_user();
-#if defined(OLED_DRIVER_ENABLE) && !defined(OLED_DISABLE_TIMEOUT)
- uint8_t ret = matrix_scan();
-#else
- matrix_scan();
-#endif
+ uint8_t matrix_changed = matrix_scan();
+ if (matrix_changed) last_matrix_activity_trigger();
if (should_process_keypress()) {
for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
@@ -401,7 +417,8 @@ MATRIX_LOOP_END:
#endif
#ifdef ENCODER_ENABLE
- encoder_read();
+ encoders_changed = encoder_read();
+ if (encoders_changed) last_encoder_activity_trigger();
#endif
#ifdef QWIIC_ENABLE
@@ -411,8 +428,12 @@ MATRIX_LOOP_END:
#ifdef OLED_DRIVER_ENABLE
oled_task();
# ifndef OLED_DISABLE_TIMEOUT
- // Wake up oled if user is using those fabulous keys!
- if (ret) oled_on();
+ // Wake up oled if user is using those fabulous keys or spinning those encoders!
+# ifdef ENCODER_ENABLE
+ if (matrix_changed || encoders_changed) oled_on();
+# else
+ if (matrix_changed) oled_on();
+# endif
# endif
#endif
diff --git a/tmk_core/common/keyboard.h b/tmk_core/common/keyboard.h
index 70e8f7e2c7..eaf74bac58 100644
--- a/tmk_core/common/keyboard.h
+++ b/tmk_core/common/keyboard.h
@@ -73,6 +73,15 @@ void keyboard_post_init_user(void);
void housekeeping_task_kb(void);
void housekeeping_task_user(void);
+uint32_t last_input_activity_time(void); // Timestamp of the last matrix or encoder activity
+uint32_t last_input_activity_elapsed(void); // Number of milliseconds since the last matrix or encoder activity
+
+uint32_t last_matrix_activity_time(void); // Timestamp of the last matrix activity
+uint32_t last_matrix_activity_elapsed(void); // Number of milliseconds since the last matrix activity
+
+uint32_t last_encoder_activity_time(void); // Timestamp of the last encoder activity
+uint32_t last_encoder_activity_elapsed(void); // Number of milliseconds since the last encoder activity
+
uint32_t get_matrix_scan_rate(void);
#ifdef __cplusplus
diff --git a/tmk_core/common/keycode.h b/tmk_core/common/keycode.h
index d35e44d8dc..efad92b235 100644
--- a/tmk_core/common/keycode.h
+++ b/tmk_core/common/keycode.h
@@ -39,7 +39,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define IS_MOUSEKEY(code) (KC_MS_UP <= (code) && (code) <= KC_MS_ACCEL2)
#define IS_MOUSEKEY_MOVE(code) (KC_MS_UP <= (code) && (code) <= KC_MS_RIGHT)
-#define IS_MOUSEKEY_BUTTON(code) (KC_MS_BTN1 <= (code) && (code) <= KC_MS_BTN5)
+#define IS_MOUSEKEY_BUTTON(code) (KC_MS_BTN1 <= (code) && (code) <= KC_MS_BTN8)
#define IS_MOUSEKEY_WHEEL(code) (KC_MS_WH_UP <= (code) && (code) <= KC_MS_WH_RIGHT)
#define IS_MOUSEKEY_ACCEL(code) (KC_MS_ACCEL0 <= (code) && (code) <= KC_MS_ACCEL2)
@@ -205,6 +205,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define KC_BTN3 KC_MS_BTN3
#define KC_BTN4 KC_MS_BTN4
#define KC_BTN5 KC_MS_BTN5
+#define KC_BTN6 KC_MS_BTN6
+#define KC_BTN7 KC_MS_BTN7
+#define KC_BTN8 KC_MS_BTN8
#define KC_WH_U KC_MS_WH_UP
#define KC_WH_D KC_MS_WH_DOWN
#define KC_WH_L KC_MS_WH_LEFT
@@ -521,15 +524,18 @@ enum internal_special_keycodes {
enum mouse_keys {
/* Mouse Buttons */
- KC_MS_UP = 0xF0,
+ KC_MS_UP = 0xED,
KC_MS_DOWN,
KC_MS_LEFT,
- KC_MS_RIGHT,
+ KC_MS_RIGHT, // 0xF0
KC_MS_BTN1,
KC_MS_BTN2,
KC_MS_BTN3,
KC_MS_BTN4,
KC_MS_BTN5,
+ KC_MS_BTN6,
+ KC_MS_BTN7,
+ KC_MS_BTN8,
/* Mouse Wheel */
KC_MS_WH_UP,
@@ -540,5 +546,5 @@ enum mouse_keys {
/* Acceleration */
KC_MS_ACCEL0,
KC_MS_ACCEL1,
- KC_MS_ACCEL2
+ KC_MS_ACCEL2 // 0xFF
};
diff --git a/tmk_core/common/mousekey.c b/tmk_core/common/mousekey.c
deleted file mode 100644
index ef18bcf1a8..0000000000
--- a/tmk_core/common/mousekey.c
+++ /dev/null
@@ -1,446 +0,0 @@
-/*
- * Copyright 2011 Jun Wako <wakojun@gmail.com>
- *
- * 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 <stdint.h>
-#include "keycode.h"
-#include "host.h"
-#include "timer.h"
-#include "print.h"
-#include "debug.h"
-#include "mousekey.h"
-
-inline int8_t times_inv_sqrt2(int8_t x) {
- // 181/256 is pretty close to 1/sqrt(2)
- // 0.70703125 0.707106781
- // 1 too small for x=99 and x=198
- // This ends up being a mult and discard lower 8 bits
- return (x * 181) >> 8;
-}
-
-static report_mouse_t mouse_report = {0};
-static void mousekey_debug(void);
-static uint8_t mousekey_accel = 0;
-static uint8_t mousekey_repeat = 0;
-static uint8_t mousekey_wheel_repeat = 0;
-
-#ifndef MK_3_SPEED
-
-static uint16_t last_timer_c = 0;
-static uint16_t last_timer_w = 0;
-
-/*
- * Mouse keys acceleration algorithm
- * http://en.wikipedia.org/wiki/Mouse_keys
- *
- * speed = delta * max_speed * (repeat / time_to_max)**((1000+curve)/1000)
- */
-/* milliseconds between the initial key press and first repeated motion event (0-2550) */
-uint8_t mk_delay = MOUSEKEY_DELAY / 10;
-/* milliseconds between repeated motion events (0-255) */
-uint8_t mk_interval = MOUSEKEY_INTERVAL;
-/* steady speed (in action_delta units) applied each event (0-255) */
-uint8_t mk_max_speed = MOUSEKEY_MAX_SPEED;
-/* number of events (count) accelerating to steady speed (0-255) */
-uint8_t mk_time_to_max = MOUSEKEY_TIME_TO_MAX;
-/* ramp used to reach maximum pointer speed (NOT SUPPORTED) */
-// int8_t mk_curve = 0;
-/* wheel params */
-/* milliseconds between the initial key press and first repeated motion event (0-2550) */
-uint8_t mk_wheel_delay = MOUSEKEY_WHEEL_DELAY / 10;
-/* milliseconds between repeated motion events (0-255) */
-uint8_t mk_wheel_interval = MOUSEKEY_WHEEL_INTERVAL;
-uint8_t mk_wheel_max_speed = MOUSEKEY_WHEEL_MAX_SPEED;
-uint8_t mk_wheel_time_to_max = MOUSEKEY_WHEEL_TIME_TO_MAX;
-
-# ifndef MK_COMBINED
-
-static uint8_t move_unit(void) {
- uint16_t unit;
- if (mousekey_accel & (1 << 0)) {
- unit = (MOUSEKEY_MOVE_DELTA * mk_max_speed) / 4;
- } else if (mousekey_accel & (1 << 1)) {
- unit = (MOUSEKEY_MOVE_DELTA * mk_max_speed) / 2;
- } else if (mousekey_accel & (1 << 2)) {
- unit = (MOUSEKEY_MOVE_DELTA * mk_max_speed);
- } else if (mousekey_repeat == 0) {
- unit = MOUSEKEY_MOVE_DELTA;
- } else if (mousekey_repeat >= mk_time_to_max) {
- unit = MOUSEKEY_MOVE_DELTA * mk_max_speed;
- } else {
- unit = (MOUSEKEY_MOVE_DELTA * mk_max_speed * mousekey_repeat) / mk_time_to_max;
- }
- return (unit > MOUSEKEY_MOVE_MAX ? MOUSEKEY_MOVE_MAX : (unit == 0 ? 1 : unit));
-}
-
-static uint8_t wheel_unit(void) {
- uint16_t unit;
- if (mousekey_accel & (1 << 0)) {
- unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed) / 4;
- } else if (mousekey_accel & (1 << 1)) {
- unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed) / 2;
- } else if (mousekey_accel & (1 << 2)) {
- unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed);
- } else if (mousekey_wheel_repeat == 0) {
- unit = MOUSEKEY_WHEEL_DELTA;
- } else if (mousekey_wheel_repeat >= mk_wheel_time_to_max) {
- unit = MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed;
- } else {
- unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed * mousekey_wheel_repeat) / mk_wheel_time_to_max;
- }
- return (unit > MOUSEKEY_WHEEL_MAX ? MOUSEKEY_WHEEL_MAX : (unit == 0 ? 1 : unit));
-}
-
-# else /* #ifndef MK_COMBINED */
-
-static uint8_t move_unit(void) {
- uint16_t unit;
- if (mousekey_accel & (1 << 0)) {
- unit = 1;
- } else if (mousekey_accel & (1 << 1)) {
- unit = (MOUSEKEY_MOVE_DELTA * mk_max_speed) / 2;
- } else if (mousekey_accel & (1 << 2)) {
- unit = MOUSEKEY_MOVE_MAX;
- } else if (mousekey_repeat == 0) {
- unit = MOUSEKEY_MOVE_DELTA;
- } else if (mousekey_repeat >= mk_time_to_max) {
- unit = MOUSEKEY_MOVE_DELTA * mk_max_speed;
- } else {
- unit = (MOUSEKEY_MOVE_DELTA * mk_max_speed * mousekey_repeat) / mk_time_to_max;
- }
- return (unit > MOUSEKEY_MOVE_MAX ? MOUSEKEY_MOVE_MAX : (unit == 0 ? 1 : unit));
-}
-
-static uint8_t wheel_unit(void) {
- uint16_t unit;
- if (mousekey_accel & (1 << 0)) {
- unit = 1;
- } else if (mousekey_accel & (1 << 1)) {
- unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed) / 2;
- } else if (mousekey_accel & (1 << 2)) {
- unit = MOUSEKEY_WHEEL_MAX;
- } else if (mousekey_repeat == 0) {
- unit = MOUSEKEY_WHEEL_DELTA;
- } else if (mousekey_repeat >= mk_wheel_time_to_max) {
- unit = MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed;
- } else {
- unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed * mousekey_repeat) / mk_wheel_time_to_max;
- }
- return (unit > MOUSEKEY_WHEEL_MAX ? MOUSEKEY_WHEEL_MAX : (unit == 0 ? 1 : unit));
-}
-
-# endif /* #ifndef MK_COMBINED */
-
-void mousekey_task(void) {
- // report cursor and scroll movement independently
- report_mouse_t const tmpmr = mouse_report;
-
- mouse_report.x = 0;
- mouse_report.y = 0;
- mouse_report.v = 0;
- mouse_report.h = 0;
-
- if ((tmpmr.x || tmpmr.y) && timer_elapsed(last_timer_c) > (mousekey_repeat ? mk_interval : mk_delay * 10)) {
- if (mousekey_repeat != UINT8_MAX) mousekey_repeat++;
- if (tmpmr.x != 0) mouse_report.x = move_unit() * ((tmpmr.x > 0) ? 1 : -1);
- if (tmpmr.y != 0) mouse_report.y = move_unit() * ((tmpmr.y > 0) ? 1 : -1);
-
- /* diagonal move [1/sqrt(2)] */
- if (mouse_report.x && mouse_report.y) {
- mouse_report.x = times_inv_sqrt2(mouse_report.x);
- if (mouse_report.x == 0) {
- mouse_report.x = 1;
- }
- mouse_report.y = times_inv_sqrt2(mouse_report.y);
- if (mouse_report.y == 0) {
- mouse_report.y = 1;
- }
- }
- }
- if ((tmpmr.v || tmpmr.h) && timer_elapsed(last_timer_w) > (mousekey_wheel_repeat ? mk_wheel_interval : mk_wheel_delay * 10)) {
- if (mousekey_wheel_repeat != UINT8_MAX) mousekey_wheel_repeat++;
- if (tmpmr.v != 0) mouse_report.v = wheel_unit() * ((tmpmr.v > 0) ? 1 : -1);
- if (tmpmr.h != 0) mouse_report.h = wheel_unit() * ((tmpmr.h > 0) ? 1 : -1);
-
- /* diagonal move [1/sqrt(2)] */
- if (mouse_report.v && mouse_report.h) {
- mouse_report.v = times_inv_sqrt2(mouse_report.v);
- if (mouse_report.v == 0) {
- mouse_report.v = 1;
- }
- mouse_report.h = times_inv_sqrt2(mouse_report.h);
- if (mouse_report.h == 0) {
- mouse_report.h = 1;
- }
- }
- }
-
- if (mouse_report.x || mouse_report.y || mouse_report.v || mouse_report.h) mousekey_send();
- mouse_report = tmpmr;
-}
-
-void mousekey_on(uint8_t code) {
- if (code == KC_MS_UP)
- mouse_report.y = move_unit() * -1;
- else if (code == KC_MS_DOWN)
- mouse_report.y = move_unit();
- else if (code == KC_MS_LEFT)
- mouse_report.x = move_unit() * -1;
- else if (code == KC_MS_RIGHT)
- mouse_report.x = move_unit();
- else if (code == KC_MS_WH_UP)
- mouse_report.v = wheel_unit();
- else if (code == KC_MS_WH_DOWN)
- mouse_report.v = wheel_unit() * -1;
- else if (code == KC_MS_WH_LEFT)
- mouse_report.h = wheel_unit() * -1;
- else if (code == KC_MS_WH_RIGHT)
- mouse_report.h = wheel_unit();
- else if (code == KC_MS_BTN1)
- mouse_report.buttons |= MOUSE_BTN1;
- else if (code == KC_MS_BTN2)
- mouse_report.buttons |= MOUSE_BTN2;
- else if (code == KC_MS_BTN3)
- mouse_report.buttons |= MOUSE_BTN3;
- else if (code == KC_MS_BTN4)
- mouse_report.buttons |= MOUSE_BTN4;
- else if (code == KC_MS_BTN5)
- mouse_report.buttons |= MOUSE_BTN5;
- else if (code == KC_MS_ACCEL0)
- mousekey_accel |= (1 << 0);
- else if (code == KC_MS_ACCEL1)
- mousekey_accel |= (1 << 1);
- else if (code == KC_MS_ACCEL2)
- mousekey_accel |= (1 << 2);
-}
-
-void mousekey_off(uint8_t code) {
- if (code == KC_MS_UP && mouse_report.y < 0)
- mouse_report.y = 0;
- else if (code == KC_MS_DOWN && mouse_report.y > 0)
- mouse_report.y = 0;
- else if (code == KC_MS_LEFT && mouse_report.x < 0)
- mouse_report.x = 0;
- else if (code == KC_MS_RIGHT && mouse_report.x > 0)
- mouse_report.x = 0;
- else if (code == KC_MS_WH_UP && mouse_report.v > 0)
- mouse_report.v = 0;
- else if (code == KC_MS_WH_DOWN && mouse_report.v < 0)
- mouse_report.v = 0;
- else if (code == KC_MS_WH_LEFT && mouse_report.h < 0)
- mouse_report.h = 0;
- else if (code == KC_MS_WH_RIGHT && mouse_report.h > 0)
- mouse_report.h = 0;
- else if (code == KC_MS_BTN1)
- mouse_report.buttons &= ~MOUSE_BTN1;
- else if (code == KC_MS_BTN2)
- mouse_report.buttons &= ~MOUSE_BTN2;
- else if (code == KC_MS_BTN3)
- mouse_report.buttons &= ~MOUSE_BTN3;
- else if (code == KC_MS_BTN4)
- mouse_report.buttons &= ~MOUSE_BTN4;
- else if (code == KC_MS_BTN5)
- mouse_report.buttons &= ~MOUSE_BTN5;
- else if (code == KC_MS_ACCEL0)
- mousekey_accel &= ~(1 << 0);
- else if (code == KC_MS_ACCEL1)
- mousekey_accel &= ~(1 << 1);
- else if (code == KC_MS_ACCEL2)
- mousekey_accel &= ~(1 << 2);
- if (mouse_report.x == 0 && mouse_report.y == 0) mousekey_repeat = 0;
- if (mouse_report.v == 0 && mouse_report.h == 0) mousekey_wheel_repeat = 0;
-}
-
-#else /* #ifndef MK_3_SPEED */
-
-enum { mkspd_unmod, mkspd_0, mkspd_1, mkspd_2, mkspd_COUNT };
-# ifndef MK_MOMENTARY_ACCEL
-static uint8_t mk_speed = mkspd_1;
-# else
-static uint8_t mk_speed = mkspd_unmod;
-static uint8_t mkspd_DEFAULT = mkspd_unmod;
-# endif
-static uint16_t last_timer_c = 0;
-static uint16_t last_timer_w = 0;
-uint16_t c_offsets[mkspd_COUNT] = {MK_C_OFFSET_UNMOD, MK_C_OFFSET_0, MK_C_OFFSET_1, MK_C_OFFSET_2};
-uint16_t c_intervals[mkspd_COUNT] = {MK_C_INTERVAL_UNMOD, MK_C_INTERVAL_0, MK_C_INTERVAL_1, MK_C_INTERVAL_2};
-uint16_t w_offsets[mkspd_COUNT] = {MK_W_OFFSET_UNMOD, MK_W_OFFSET_0, MK_W_OFFSET_1, MK_W_OFFSET_2};
-uint16_t w_intervals[mkspd_COUNT] = {MK_W_INTERVAL_UNMOD, MK_W_INTERVAL_0, MK_W_INTERVAL_1, MK_W_INTERVAL_2};
-
-void mousekey_task(void) {
- // report cursor and scroll movement independently
- report_mouse_t const tmpmr = mouse_report;
- mouse_report.x = 0;
- mouse_report.y = 0;
- mouse_report.v = 0;
- mouse_report.h = 0;
-
- if ((tmpmr.x || tmpmr.y) && timer_elapsed(last_timer_c) > c_intervals[mk_speed]) {
- mouse_report.x = tmpmr.x;
- mouse_report.y = tmpmr.y;
- }
- if ((tmpmr.h || tmpmr.v) && timer_elapsed(last_timer_w) > w_intervals[mk_speed]) {
- mouse_report.v = tmpmr.v;
- mouse_report.h = tmpmr.h;
- }
-
- if (mouse_report.x || mouse_report.y || mouse_report.v || mouse_report.h) mousekey_send();
- mouse_report = tmpmr;
-}
-
-void adjust_speed(void) {
- uint16_t const c_offset = c_offsets[mk_speed];
- uint16_t const w_offset = w_offsets[mk_speed];
- if (mouse_report.x > 0) mouse_report.x = c_offset;
- if (mouse_report.x < 0) mouse_report.x = c_offset * -1;
- if (mouse_report.y > 0) mouse_report.y = c_offset;
- if (mouse_report.y < 0) mouse_report.y = c_offset * -1;
- if (mouse_report.h > 0) mouse_report.h = w_offset;
- if (mouse_report.h < 0) mouse_report.h = w_offset * -1;
- if (mouse_report.v > 0) mouse_report.v = w_offset;
- if (mouse_report.v < 0) mouse_report.v = w_offset * -1;
- // adjust for diagonals
- if (mouse_report.x && mouse_report.y) {
- mouse_report.x = times_inv_sqrt2(mouse_report.x);
- if (mouse_report.x == 0) {
- mouse_report.x = 1;
- }
- mouse_report.y = times_inv_sqrt2(mouse_report.y);
- if (mouse_report.y == 0) {
- mouse_report.y = 1;
- }
- }
- if (mouse_report.h && mouse_report.v) {
- mouse_report.h = times_inv_sqrt2(mouse_report.h);
- mouse_report.v = times_inv_sqrt2(mouse_report.v);
- }
-}
-
-void mousekey_on(uint8_t code) {
- uint16_t const c_offset = c_offsets[mk_speed];
- uint16_t const w_offset = w_offsets[mk_speed];
- uint8_t const old_speed = mk_speed;
- if (code == KC_MS_UP)
- mouse_report.y = c_offset * -1;
- else if (code == KC_MS_DOWN)
- mouse_report.y = c_offset;
- else if (code == KC_MS_LEFT)
- mouse_report.x = c_offset * -1;
- else if (code == KC_MS_RIGHT)
- mouse_report.x = c_offset;
- else if (code == KC_MS_WH_UP)
- mouse_report.v = w_offset;
- else if (code == KC_MS_WH_DOWN)
- mouse_report.v = w_offset * -1;
- else if (code == KC_MS_WH_LEFT)
- mouse_report.h = w_offset * -1;
- else if (code == KC_MS_WH_RIGHT)
- mouse_report.h = w_offset;
- else if (code == KC_MS_BTN1)
- mouse_report.buttons |= MOUSE_BTN1;
- else if (code == KC_MS_BTN2)
- mouse_report.buttons |= MOUSE_BTN2;
- else if (code == KC_MS_BTN3)
- mouse_report.buttons |= MOUSE_BTN3;
- else if (code == KC_MS_BTN4)
- mouse_report.buttons |= MOUSE_BTN4;
- else if (code == KC_MS_BTN5)
- mouse_report.buttons |= MOUSE_BTN5;
- else if (code == KC_MS_ACCEL0)
- mk_speed = mkspd_0;
- else if (code == KC_MS_ACCEL1)
- mk_speed = mkspd_1;
- else if (code == KC_MS_ACCEL2)
- mk_speed = mkspd_2;
- if (mk_speed != old_speed) adjust_speed();
-}
-
-void mousekey_off(uint8_t code) {
-# ifdef MK_MOMENTARY_ACCEL
- uint8_t const old_speed = mk_speed;
-# endif
- if (code == KC_MS_UP && mouse_report.y < 0)
- mouse_report.y = 0;
- else if (code == KC_MS_DOWN && mouse_report.y > 0)
- mouse_report.y = 0;
- else if (code == KC_MS_LEFT && mouse_report.x < 0)
- mouse_report.x = 0;
- else if (code == KC_MS_RIGHT && mouse_report.x > 0)
- mouse_report.x = 0;
- else if (code == KC_MS_WH_UP && mouse_report.v > 0)
- mouse_report.v = 0;
- else if (code == KC_MS_WH_DOWN && mouse_report.v < 0)
- mouse_report.v = 0;
- else if (code == KC_MS_WH_LEFT && mouse_report.h < 0)
- mouse_report.h = 0;
- else if (code == KC_MS_WH_RIGHT && mouse_report.h > 0)
- mouse_report.h = 0;
- else if (code == KC_MS_BTN1)
- mouse_report.buttons &= ~MOUSE_BTN1;
- else if (code == KC_MS_BTN2)
- mouse_report.buttons &= ~MOUSE_BTN2;
- else if (code == KC_MS_BTN3)
- mouse_report.buttons &= ~MOUSE_BTN3;
- else if (code == KC_MS_BTN4)
- mouse_report.buttons &= ~MOUSE_BTN4;
- else if (code == KC_MS_BTN5)
- mouse_report.buttons &= ~MOUSE_BTN5;
-# ifdef MK_MOMENTARY_ACCEL
- else if (code == KC_MS_ACCEL0)
- mk_speed = mkspd_DEFAULT;
- else if (code == KC_MS_ACCEL1)
- mk_speed = mkspd_DEFAULT;
- else if (code == KC_MS_ACCEL2)
- mk_speed = mkspd_DEFAULT;
- if (mk_speed != old_speed) adjust_speed();
-# endif
-}
-
-#endif /* #ifndef MK_3_SPEED */
-
-void mousekey_send(void) {
- mousekey_debug();
- uint16_t time = timer_read();
- if (mouse_report.x || mouse_report.y) last_timer_c = time;
- if (mouse_report.v || mouse_report.h) last_timer_w = time;
- host_mouse_send(&mouse_report);
-}
-
-void mousekey_clear(void) {
- mouse_report = (report_mouse_t){};
- mousekey_repeat = 0;
- mousekey_wheel_repeat = 0;
- mousekey_accel = 0;
-}
-
-static void mousekey_debug(void) {
- if (!debug_mouse) return;
- print("mousekey [btn|x y v h](rep/acl): [");
- phex(mouse_report.buttons);
- print("|");
- print_decs(mouse_report.x);
- print(" ");
- print_decs(mouse_report.y);
- print(" ");
- print_decs(mouse_report.v);
- print(" ");
- print_decs(mouse_report.h);
- print("](");
- print_dec(mousekey_repeat);
- print("/");
- print_dec(mousekey_accel);
- print(")\n");
-}
diff --git a/tmk_core/common/mousekey.h b/tmk_core/common/mousekey.h
deleted file mode 100644
index 300d262f5d..0000000000
--- a/tmk_core/common/mousekey.h
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
-Copyright 2011 Jun Wako <wakojun@gmail.com>
-
-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/>.
-*/
-
-#pragma once
-
-#include <stdbool.h>
-#include "host.h"
-
-#ifndef MK_3_SPEED
-
-/* max value on report descriptor */
-# ifndef MOUSEKEY_MOVE_MAX
-# define MOUSEKEY_MOVE_MAX 127
-# elif MOUSEKEY_MOVE_MAX > 127
-# error MOUSEKEY_MOVE_MAX needs to be smaller than 127
-# endif
-
-# ifndef MOUSEKEY_WHEEL_MAX
-# define MOUSEKEY_WHEEL_MAX 127
-# elif MOUSEKEY_WHEEL_MAX > 127
-# error MOUSEKEY_WHEEL_MAX needs to be smaller than 127
-# endif
-
-# ifndef MOUSEKEY_MOVE_DELTA
-# define MOUSEKEY_MOVE_DELTA 5
-# endif
-# ifndef MOUSEKEY_WHEEL_DELTA
-# define MOUSEKEY_WHEEL_DELTA 1
-# endif
-# ifndef MOUSEKEY_DELAY
-# define MOUSEKEY_DELAY 300
-# endif
-# ifndef MOUSEKEY_INTERVAL
-# define MOUSEKEY_INTERVAL 50
-# endif
-# ifndef MOUSEKEY_MAX_SPEED
-# define MOUSEKEY_MAX_SPEED 10
-# endif
-# ifndef MOUSEKEY_TIME_TO_MAX
-# define MOUSEKEY_TIME_TO_MAX 20
-# endif
-# ifndef MOUSEKEY_WHEEL_DELAY
-# define MOUSEKEY_WHEEL_DELAY 300
-# endif
-# ifndef MOUSEKEY_WHEEL_INTERVAL
-# define MOUSEKEY_WHEEL_INTERVAL 100
-# endif
-# ifndef MOUSEKEY_WHEEL_MAX_SPEED
-# define MOUSEKEY_WHEEL_MAX_SPEED 8
-# endif
-# ifndef MOUSEKEY_WHEEL_TIME_TO_MAX
-# define MOUSEKEY_WHEEL_TIME_TO_MAX 40
-# endif
-
-#else /* #ifndef MK_3_SPEED */
-
-# ifndef MK_C_OFFSET_UNMOD
-# define MK_C_OFFSET_UNMOD 16
-# endif
-# ifndef MK_C_INTERVAL_UNMOD
-# define MK_C_INTERVAL_UNMOD 16
-# endif
-# ifndef MK_C_OFFSET_0
-# define MK_C_OFFSET_0 1
-# endif
-# ifndef MK_C_INTERVAL_0
-# define MK_C_INTERVAL_0 32
-# endif
-# ifndef MK_C_OFFSET_1
-# define MK_C_OFFSET_1 4
-# endif
-# ifndef MK_C_INTERVAL_1
-# define MK_C_INTERVAL_1 16
-# endif
-# ifndef MK_C_OFFSET_2
-# define MK_C_OFFSET_2 32
-# endif
-# ifndef MK_C_INTERVAL_2
-# define MK_C_INTERVAL_2 16
-# endif
-
-# ifndef MK_W_OFFSET_UNMOD
-# define MK_W_OFFSET_UNMOD 1
-# endif
-# ifndef MK_W_INTERVAL_UNMOD
-# define MK_W_INTERVAL_UNMOD 40
-# endif
-# ifndef MK_W_OFFSET_0
-# define MK_W_OFFSET_0 1
-# endif
-# ifndef MK_W_INTERVAL_0