aboutsummaryrefslogtreecommitdiff
path: root/tmk_core/common
diff options
context:
space:
mode:
authorstein3 <stein3@gmail.com>2020-10-06 07:15:41 -0700
committerstein3 <stein3@gmail.com>2020-10-06 07:15:41 -0700
commit2e402741a89c5eec8cf30c966ce6f36d6ec9249b (patch)
tree3592e8c5e6bd19943ae55db7fc02a5f755afbb51 /tmk_core/common
parent3e5e4f74272c610bb9fa737f674f8e65ed6100ca (diff)
parent2013f6313430b977e557e482d30daa279a46e75d (diff)
downloadqmk_firmware-2e402741a89c5eec8cf30c966ce6f36d6ec9249b.tar.gz
qmk_firmware-2e402741a89c5eec8cf30c966ce6f36d6ec9249b.zip
Merge branch 'master' into meteor
Diffstat (limited to 'tmk_core/common')
-rw-r--r--tmk_core/common/action.h2
-rw-r--r--tmk_core/common/action_layer.h13
-rw-r--r--tmk_core/common/bootmagic.c2
-rw-r--r--tmk_core/common/chibios/bootloader.c74
-rw-r--r--tmk_core/common/chibios/suspend.c16
-rw-r--r--tmk_core/common/command.c2
-rw-r--r--tmk_core/common/keyboard.c7
-rw-r--r--tmk_core/common/magic.c3
-rw-r--r--tmk_core/common/mousekey.c91
-rw-r--r--tmk_core/common/progmem.h1
-rw-r--r--tmk_core/common/report.h20
11 files changed, 158 insertions, 73 deletions
diff --git a/tmk_core/common/action.h b/tmk_core/common/action.h
index c82c9c81b..345c030c9 100644
--- a/tmk_core/common/action.h
+++ b/tmk_core/common/action.h
@@ -29,7 +29,7 @@ extern "C" {
29#endif 29#endif
30 30
31/* Disable macro and function features when LTO is enabled, since they break */ 31/* Disable macro and function features when LTO is enabled, since they break */
32#ifdef LINK_TIME_OPTIMIZATION_ENABLE 32#ifdef LTO_ENABLE
33# ifndef NO_ACTION_MACRO 33# ifndef NO_ACTION_MACRO
34# define NO_ACTION_MACRO 34# define NO_ACTION_MACRO
35# endif 35# endif
diff --git a/tmk_core/common/action_layer.h b/tmk_core/common/action_layer.h
index 16922c1ff..f9f686112 100644
--- a/tmk_core/common/action_layer.h
+++ b/tmk_core/common/action_layer.h
@@ -82,9 +82,11 @@ void layer_on(uint8_t layer);
82void layer_off(uint8_t layer); 82void layer_off(uint8_t layer);
83void layer_invert(uint8_t layer); 83void layer_invert(uint8_t layer);
84/* bitwise operation */ 84/* bitwise operation */
85void layer_or(layer_state_t state); 85void layer_or(layer_state_t state);
86void layer_and(layer_state_t state); 86void layer_and(layer_state_t state);
87void layer_xor(layer_state_t state); 87void layer_xor(layer_state_t state);
88layer_state_t layer_state_set_user(layer_state_t state);
89layer_state_t layer_state_set_kb(layer_state_t state);
88#else 90#else
89# define layer_state 0 91# define layer_state 0
90 92
@@ -101,11 +103,10 @@ void layer_xor(layer_state_t state);
101# define layer_or(state) (void)state 103# define layer_or(state) (void)state
102# define layer_and(state) (void)state 104# define layer_and(state) (void)state
103# define layer_xor(state) (void)state 105# define layer_xor(state) (void)state
106# define layer_state_set_kb(state) (void)state
107# define layer_state_set_user(state) (void)state
104#endif 108#endif
105 109
106layer_state_t layer_state_set_user(layer_state_t state);
107layer_state_t layer_state_set_kb(layer_state_t state);
108
109/* pressed actions cache */ 110/* pressed actions cache */
110#if !defined(NO_ACTION_LAYER) && !defined(STRICT_LAYER_RELEASE) 111#if !defined(NO_ACTION_LAYER) && !defined(STRICT_LAYER_RELEASE)
111 112
diff --git a/tmk_core/common/bootmagic.c b/tmk_core/common/bootmagic.c
index bb2aa0db8..c1b3adf94 100644
--- a/tmk_core/common/bootmagic.c
+++ b/tmk_core/common/bootmagic.c
@@ -122,6 +122,8 @@ void bootmagic(void) {
122 default_layer = eeconfig_read_default_layer(); 122 default_layer = eeconfig_read_default_layer();
123 default_layer_set((layer_state_t)default_layer); 123 default_layer_set((layer_state_t)default_layer);
124 } 124 }
125 /* Also initialize layer state to trigger callback functions for layer_state */
126 layer_state_set_kb((layer_state_t)layer_state);
125 127
126 /* EE_HANDS handedness */ 128 /* EE_HANDS handedness */
127 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_EE_HANDS_LEFT)) { 129 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_EE_HANDS_LEFT)) {
diff --git a/tmk_core/common/chibios/bootloader.c b/tmk_core/common/chibios/bootloader.c
index 4cf5dae7e..7b2cf5c43 100644
--- a/tmk_core/common/chibios/bootloader.c
+++ b/tmk_core/common/chibios/bootloader.c
@@ -2,29 +2,67 @@
2 2
3#include "ch.h" 3#include "ch.h"
4#include "hal.h" 4#include "hal.h"
5 5#include "wait.h"
6#ifdef STM32_BOOTLOADER_ADDRESS
7/* STM32 */
8 6
9/* This code should be checked whether it runs correctly on platforms */ 7/* This code should be checked whether it runs correctly on platforms */
10# define SYMVAL(sym) (uint32_t)(((uint8_t *)&(sym)) - ((uint8_t *)0)) 8#define SYMVAL(sym) (uint32_t)(((uint8_t *)&(sym)) - ((uint8_t *)0))
9#define BOOTLOADER_MAGIC 0xDEADBEEF
10#define MAGIC_ADDR (unsigned long *)(SYMVAL(__ram0_end__) - 4)
11
12#ifndef STM32_BOOTLOADER_DUAL_BANK
13# define STM32_BOOTLOADER_DUAL_BANK FALSE
14#endif
15
16#if STM32_BOOTLOADER_DUAL_BANK
17
18// Need pin definitions
19# include "config_common.h"
20
21# ifndef STM32_BOOTLOADER_DUAL_BANK_GPIO
22# error "No STM32_BOOTLOADER_DUAL_BANK_GPIO defined, don't know which pin to toggle"
23# endif
24
25# ifndef STM32_BOOTLOADER_DUAL_BANK_POLARITY
26# define STM32_BOOTLOADER_DUAL_BANK_POLARITY 0
27# endif
28
29# ifndef STM32_BOOTLOADER_DUAL_BANK_DELAY
30# define STM32_BOOTLOADER_DUAL_BANK_DELAY 100000
31# endif
32
33extern uint32_t __ram0_end__;
34
35void bootloader_jump(void) {
36 // For STM32 MCUs with dual-bank flash, and we're incapable of jumping to the bootloader. The first valid flash
37 // bank is executed unconditionally after a reset, so it doesn't enter DFU unless BOOT0 is high. Instead, we do
38 // it with hardware...in this case, we pull a GPIO high/low depending on the configuration, connects 3.3V to
39 // BOOT0's RC charging circuit, lets it charge the capacitor, and issue a system reset. See the QMK discord
40 // #hardware channel pins for an example circuit.
41 palSetPadMode(PAL_PORT(STM32_BOOTLOADER_DUAL_BANK_GPIO), PAL_PAD(STM32_BOOTLOADER_DUAL_BANK_GPIO), PAL_MODE_OUTPUT_PUSHPULL);
42# if STM32_BOOTLOADER_DUAL_BANK_POLARITY
43 palSetPad(PAL_PORT(STM32_BOOTLOADER_DUAL_BANK_GPIO), PAL_PAD(STM32_BOOTLOADER_DUAL_BANK_GPIO));
44# else
45 palClearPad(PAL_PORT(STM32_BOOTLOADER_DUAL_BANK_GPIO), PAL_PAD(STM32_BOOTLOADER_DUAL_BANK_GPIO));
46# endif
47
48 // Wait for a while for the capacitor to charge
49 wait_ms(100);
50
51 // Issue a system reset to get the ROM bootloader to execute, with BOOT0 high
52 NVIC_SystemReset();
53}
54
55void enter_bootloader_mode_if_requested(void) {} // not needed at all, but if anybody attempts to invoke it....
56
57#elif defined(STM32_BOOTLOADER_ADDRESS) // STM32_BOOTLOADER_DUAL_BANK
58
11extern uint32_t __ram0_end__; 59extern uint32_t __ram0_end__;
12# define BOOTLOADER_MAGIC 0xDEADBEEF
13# define MAGIC_ADDR (unsigned long *)(SYMVAL(__ram0_end__) - 4)
14 60
15/** \brief Jump to the bootloader
16 *
17 * FIXME: needs doc
18 */
19void bootloader_jump(void) { 61void bootloader_jump(void) {
20 *MAGIC_ADDR = BOOTLOADER_MAGIC; // set magic flag => reset handler will jump into boot loader 62 *MAGIC_ADDR = BOOTLOADER_MAGIC; // set magic flag => reset handler will jump into boot loader
21 NVIC_SystemReset(); 63 NVIC_SystemReset();
22} 64}
23 65
24/** \brief Enter bootloader mode if requested
25 *
26 * FIXME: needs doc
27 */
28void enter_bootloader_mode_if_requested(void) { 66void enter_bootloader_mode_if_requested(void) {
29 unsigned long *check = MAGIC_ADDR; 67 unsigned long *check = MAGIC_ADDR;
30 if (*check == BOOTLOADER_MAGIC) { 68 if (*check == BOOTLOADER_MAGIC) {
@@ -41,10 +79,10 @@ void enter_bootloader_mode_if_requested(void) {
41 } 79 }
42} 80}
43 81
44#elif defined(KL2x) || defined(K20x) /* STM32_BOOTLOADER_ADDRESS */ 82#elif defined(KL2x) || defined(K20x) // STM32_BOOTLOADER_DUAL_BANK // STM32_BOOTLOADER_ADDRESS
45/* Kinetis */ 83/* Kinetis */
46 84
47# if defined(KIIBOHD_BOOTLOADER) 85# if defined(BOOTLOADER_KIIBOHD)
48/* Kiibohd Bootloader (MCHCK and Infinity KB) */ 86/* Kiibohd Bootloader (MCHCK and Infinity KB) */
49# define SCB_AIRCR_VECTKEY_WRITEMAGIC 0x05FA0000 87# define SCB_AIRCR_VECTKEY_WRITEMAGIC 0x05FA0000
50const uint8_t sys_reset_to_loader_magic[] = "\xff\x00\x7fRESET TO LOADER\x7f\x00\xff"; 88const uint8_t sys_reset_to_loader_magic[] = "\xff\x00\x7fRESET TO LOADER\x7f\x00\xff";
@@ -54,14 +92,14 @@ void bootloader_jump(void) {
54 SCB->AIRCR = SCB_AIRCR_VECTKEY_WRITEMAGIC | SCB_AIRCR_SYSRESETREQ_Msk; 92 SCB->AIRCR = SCB_AIRCR_VECTKEY_WRITEMAGIC | SCB_AIRCR_SYSRESETREQ_Msk;
55} 93}
56 94
57# else /* defined(KIIBOHD_BOOTLOADER) */ 95# else /* defined(BOOTLOADER_KIIBOHD) */
58/* Default for Kinetis - expecting an ARM Teensy */ 96/* Default for Kinetis - expecting an ARM Teensy */
59# include "wait.h" 97# include "wait.h"
60void bootloader_jump(void) { 98void bootloader_jump(void) {
61 wait_ms(100); 99 wait_ms(100);
62 __BKPT(0); 100 __BKPT(0);
63} 101}
64# endif /* defined(KIIBOHD_BOOTLOADER) */ 102# endif /* defined(BOOTLOADER_KIIBOHD) */
65 103
66#else /* neither STM32 nor KINETIS */ 104#else /* neither STM32 nor KINETIS */
67__attribute__((weak)) void bootloader_jump(void) {} 105__attribute__((weak)) void bootloader_jump(void) {}
diff --git a/tmk_core/common/chibios/suspend.c b/tmk_core/common/chibios/suspend.c
index 8c071e7a0..64dfc05ab 100644
--- a/tmk_core/common/chibios/suspend.c
+++ b/tmk_core/common/chibios/suspend.c
@@ -9,6 +9,7 @@
9#include "mousekey.h" 9#include "mousekey.h"
10#include "host.h" 10#include "host.h"
11#include "suspend.h" 11#include "suspend.h"
12#include "led.h"
12#include "wait.h" 13#include "wait.h"
13 14
14#ifdef BACKLIGHT_ENABLE 15#ifdef BACKLIGHT_ENABLE
@@ -47,6 +48,20 @@ __attribute__((weak)) void suspend_power_down_kb(void) { suspend_power_down_user
47 * FIXME: needs doc 48 * FIXME: needs doc
48 */ 49 */
49void suspend_power_down(void) { 50void suspend_power_down(void) {
51#ifdef BACKLIGHT_ENABLE
52 backlight_set(0);
53#endif
54
55 // Turn off LED indicators
56 uint8_t leds_off = 0;
57#if defined(BACKLIGHT_CAPS_LOCK) && defined(BACKLIGHT_ENABLE)
58 if (is_backlight_enabled()) {
59 // Don't try to turn off Caps Lock indicator as it is backlight and backlight is already off
60 leds_off |= (1 << USB_LED_CAPS_LOCK);
61 }
62#endif
63 led_set(leds_off);
64
50 // TODO: figure out what to power down and how 65 // TODO: figure out what to power down and how
51 // shouldn't power down TPM/FTM if we want a breathing LED 66 // shouldn't power down TPM/FTM if we want a breathing LED
52 // also shouldn't power down USB 67 // also shouldn't power down USB
@@ -119,6 +134,7 @@ void suspend_wakeup_init(void) {
119#ifdef BACKLIGHT_ENABLE 134#ifdef BACKLIGHT_ENABLE
120 backlight_init(); 135 backlight_init();
121#endif /* BACKLIGHT_ENABLE */ 136#endif /* BACKLIGHT_ENABLE */
137 led_set(host_keyboard_leds());
122#if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE) 138#if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE)
123 is_suspended = false; 139 is_suspended = false;
124 if (rgblight_enabled) { 140 if (rgblight_enabled) {
diff --git a/tmk_core/common/command.c b/tmk_core/common/command.c
index ef6a39c0f..feeb2202e 100644
--- a/tmk_core/common/command.c
+++ b/tmk_core/common/command.c
@@ -180,7 +180,7 @@ static void print_version(void) {
180#ifdef NKRO_ENABLE 180#ifdef NKRO_ENABLE
181 " NKRO" 181 " NKRO"
182#endif 182#endif
183#ifdef LINK_TIME_OPTIMIZATION_ENABLE 183#ifdef LTO_ENABLE
184 " LTO" 184 " LTO"
185#endif 185#endif
186 186
diff --git a/tmk_core/common/keyboard.c b/tmk_core/common/keyboard.c
index 714c3d048..a45af56df 100644
--- a/tmk_core/common/keyboard.c
+++ b/tmk_core/common/keyboard.c
@@ -74,6 +74,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
74#ifdef MIDI_ENABLE 74#ifdef MIDI_ENABLE
75# include "process_midi.h" 75# include "process_midi.h"
76#endif 76#endif
77#ifdef JOYSTICK_ENABLE
78# include "process_joystick.h"
79#endif
77#ifdef HD44780_ENABLE 80#ifdef HD44780_ENABLE
78# include "hd44780.h" 81# include "hd44780.h"
79#endif 82#endif
@@ -420,6 +423,10 @@ MATRIX_LOOP_END:
420 } 423 }
421#endif 424#endif
422 425
426#ifdef JOYSTICK_ENABLE
427 joystick_task();
428#endif
429
423 // update LED 430 // update LED
424 if (led_status != host_keyboard_leds()) { 431 if (led_status != host_keyboard_leds()) {
425 led_status = host_keyboard_leds(); 432 led_status = host_keyboard_leds();
diff --git a/tmk_core/common/magic.c b/tmk_core/common/magic.c
index d8ab52573..e14994164 100644
--- a/tmk_core/common/magic.c
+++ b/tmk_core/common/magic.c
@@ -33,4 +33,7 @@ void magic(void) {
33 uint8_t default_layer = 0; 33 uint8_t default_layer = 0;
34 default_layer = eeconfig_read_default_layer(); 34 default_layer = eeconfig_read_default_layer();
35 default_layer_set((layer_state_t)default_layer); 35 default_layer_set((layer_state_t)default_layer);
36
37 /* Also initialize layer state to trigger callback functions for layer_state */
38 layer_state_set_kb((layer_state_t)layer_state);
36} 39}
diff --git a/tmk_core/common/mousekey.c b/tmk_core/common/mousekey.c
index 42bf231f4..ef18bcf1a 100644
--- a/tmk_core/common/mousekey.c
+++ b/tmk_core/common/mousekey.c
@@ -33,9 +33,9 @@ inline int8_t times_inv_sqrt2(int8_t x) {
33 33
34static report_mouse_t mouse_report = {0}; 34static report_mouse_t mouse_report = {0};
35static void mousekey_debug(void); 35static void mousekey_debug(void);
36static uint8_t mousekey_accel = 0; 36static uint8_t mousekey_accel = 0;
37static uint8_t mousekey_repeat = 0; 37static uint8_t mousekey_repeat = 0;
38static uint16_t last_timer = 0; 38static uint8_t mousekey_wheel_repeat = 0;
39 39
40#ifndef MK_3_SPEED 40#ifndef MK_3_SPEED
41 41
@@ -94,12 +94,12 @@ static uint8_t wheel_unit(void) {
94 unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed) / 2; 94 unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed) / 2;
95 } else if (mousekey_accel & (1 << 2)) { 95 } else if (mousekey_accel & (1 << 2)) {
96 unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed); 96 unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed);
97 } else if (mousekey_repeat == 0) { 97 } else if (mousekey_wheel_repeat == 0) {
98 unit = MOUSEKEY_WHEEL_DELTA; 98 unit = MOUSEKEY_WHEEL_DELTA;
99 } else if (mousekey_repeat >= mk_wheel_time_to_max) { 99 } else if (mousekey_wheel_repeat >= mk_wheel_time_to_max) {
100 unit = MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed; 100 unit = MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed;
101 } else { 101 } else {
102 unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed * mousekey_repeat) / mk_wheel_time_to_max; 102 unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed * mousekey_wheel_repeat) / mk_wheel_time_to_max;
103 } 103 }
104 return (unit > MOUSEKEY_WHEEL_MAX ? MOUSEKEY_WHEEL_MAX : (unit == 0 ? 1 : unit)); 104 return (unit > MOUSEKEY_WHEEL_MAX ? MOUSEKEY_WHEEL_MAX : (unit == 0 ? 1 : unit));
105} 105}
@@ -147,14 +147,17 @@ static uint8_t wheel_unit(void) {
147void mousekey_task(void) { 147void mousekey_task(void) {
148 // report cursor and scroll movement independently 148 // report cursor and scroll movement independently
149 report_mouse_t const tmpmr = mouse_report; 149 report_mouse_t const tmpmr = mouse_report;
150 if ((mouse_report.x || mouse_report.y) && timer_elapsed(last_timer_c) > (mousekey_repeat ? mk_interval : mk_delay * 10)) { 150
151 mouse_report.x = 0;
152 mouse_report.y = 0;
153 mouse_report.v = 0;
154 mouse_report.h = 0;
155
156 if ((tmpmr.x || tmpmr.y) && timer_elapsed(last_timer_c) > (mousekey_repeat ? mk_interval : mk_delay * 10)) {
151 if (mousekey_repeat != UINT8_MAX) mousekey_repeat++; 157 if (mousekey_repeat != UINT8_MAX) mousekey_repeat++;
152 mouse_report.v = 0; 158 if (tmpmr.x != 0) mouse_report.x = move_unit() * ((tmpmr.x > 0) ? 1 : -1);
153 mouse_report.h = 0; 159 if (tmpmr.y != 0) mouse_report.y = move_unit() * ((tmpmr.y > 0) ? 1 : -1);
154 if (mouse_report.x > 0) mouse_report.x = move_unit(); 160
155 if (mouse_report.x < 0) mouse_report.x = move_unit() * -1;
156 if (mouse_report.y > 0) mouse_report.y = move_unit();
157 if (mouse_report.y < 0) mouse_report.y = move_unit() * -1;
158 /* diagonal move [1/sqrt(2)] */ 161 /* diagonal move [1/sqrt(2)] */
159 if (mouse_report.x && mouse_report.y) { 162 if (mouse_report.x && mouse_report.y) {
160 mouse_report.x = times_inv_sqrt2(mouse_report.x); 163 mouse_report.x = times_inv_sqrt2(mouse_report.x);
@@ -166,18 +169,12 @@ void mousekey_task(void) {
166 mouse_report.y = 1; 169 mouse_report.y = 1;
167 } 170 }
168 } 171 }
169 mousekey_send();
170 last_timer_c = last_timer;
171 mouse_report = tmpmr;
172 } 172 }
173 if ((mouse_report.v || mouse_report.h) && timer_elapsed(last_timer_w) > (mousekey_repeat ? mk_wheel_interval : mk_wheel_delay * 10)) { 173 if ((tmpmr.v || tmpmr.h) && timer_elapsed(last_timer_w) > (mousekey_wheel_repeat ? mk_wheel_interval : mk_wheel_delay * 10)) {
174 if (mousekey_repeat != UINT8_MAX) mousekey_repeat++; 174 if (mousekey_wheel_repeat != UINT8_MAX) mousekey_wheel_repeat++;
175 mouse_report.x = 0; 175 if (tmpmr.v != 0) mouse_report.v = wheel_unit() * ((tmpmr.v > 0) ? 1 : -1);
176 mouse_report.y = 0; 176 if (tmpmr.h != 0) mouse_report.h = wheel_unit() * ((tmpmr.h > 0) ? 1 : -1);
177 if (mouse_report.v > 0) mouse_report.v = wheel_unit(); 177
178 if (mouse_report.v < 0) mouse_report.v = wheel_unit() * -1;
179 if (mouse_report.h > 0) mouse_report.h = wheel_unit();
180 if (mouse_report.h < 0) mouse_report.h = wheel_unit() * -1;
181 /* diagonal move [1/sqrt(2)] */ 178 /* diagonal move [1/sqrt(2)] */
182 if (mouse_report.v && mouse_report.h) { 179 if (mouse_report.v && mouse_report.h) {
183 mouse_report.v = times_inv_sqrt2(mouse_report.v); 180 mouse_report.v = times_inv_sqrt2(mouse_report.v);
@@ -189,10 +186,10 @@ void mousekey_task(void) {
189 mouse_report.h = 1; 186 mouse_report.h = 1;
190 } 187 }
191 } 188 }
192 mousekey_send();
193 last_timer_w = last_timer;
194 mouse_report = tmpmr;
195 } 189 }
190
191 if (mouse_report.x || mouse_report.y || mouse_report.v || mouse_report.h) mousekey_send();
192 mouse_report = tmpmr;
196} 193}
197 194
198void mousekey_on(uint8_t code) { 195void mousekey_on(uint8_t code) {
@@ -263,7 +260,8 @@ void mousekey_off(uint8_t code) {
263 mousekey_accel &= ~(1 << 1); 260 mousekey_accel &= ~(1 << 1);
264 else if (code == KC_MS_ACCEL2) 261 else if (code == KC_MS_ACCEL2)
265 mousekey_accel &= ~(1 << 2); 262 mousekey_accel &= ~(1 << 2);
266 if (mouse_report.x == 0 && mouse_report.y == 0 && mouse_report.v == 0 && mouse_report.h == 0) mousekey_repeat = 0; 263 if (mouse_report.x == 0 && mouse_report.y == 0) mousekey_repeat = 0;
264 if (mouse_report.v == 0 && mouse_report.h == 0) mousekey_wheel_repeat = 0;
267} 265}
268 266
269#else /* #ifndef MK_3_SPEED */ 267#else /* #ifndef MK_3_SPEED */
@@ -285,20 +283,22 @@ uint16_t w_intervals[mkspd_COUNT] = {MK_W_INTERVAL_UNMOD, MK_W_INTERVAL_0
285void mousekey_task(void) { 283void mousekey_task(void) {
286 // report cursor and scroll movement independently 284 // report cursor and scroll movement independently
287 report_mouse_t const tmpmr = mouse_report; 285 report_mouse_t const tmpmr = mouse_report;
288 if ((mouse_report.x || mouse_report.y) && timer_elapsed(last_timer_c) > c_intervals[mk_speed]) { 286 mouse_report.x = 0;
289 mouse_report.h = 0; 287 mouse_report.y = 0;
290 mouse_report.v = 0; 288 mouse_report.v = 0;
291 mousekey_send(); 289 mouse_report.h = 0;
292 last_timer_c = last_timer; 290
293 mouse_report = tmpmr; 291 if ((tmpmr.x || tmpmr.y) && timer_elapsed(last_timer_c) > c_intervals[mk_speed]) {
292 mouse_report.x = tmpmr.x;
293 mouse_report.y = tmpmr.y;
294 } 294 }
295 if ((mouse_report.h || mouse_report.v) && timer_elapsed(last_timer_w) > w_intervals[mk_speed]) { 295 if ((tmpmr.h || tmpmr.v) && timer_elapsed(last_timer_w) > w_intervals[mk_speed]) {
296 mouse_report.x = 0; 296 mouse_report.v = tmpmr.v;
297 mouse_report.y = 0; 297 mouse_report.h = tmpmr.h;
298 mousekey_send();
299 last_timer_w = last_timer;
300 mouse_report = tmpmr;
301 } 298 }
299
300 if (mouse_report.x || mouse_report.y || mouse_report.v || mouse_report.h) mousekey_send();
301 mouse_report = tmpmr;
302} 302}
303 303
304void adjust_speed(void) { 304void adjust_speed(void) {
@@ -413,14 +413,17 @@ void mousekey_off(uint8_t code) {
413 413
414void mousekey_send(void) { 414void mousekey_send(void) {
415 mousekey_debug(); 415 mousekey_debug();
416 uint16_t time = timer_read();
417 if (mouse_report.x || mouse_report.y) last_timer_c = time;
418 if (mouse_report.v || mouse_report.h) last_timer_w = time;
416 host_mouse_send(&mouse_report); 419 host_mouse_send(&mouse_report);
417 last_timer = timer_read();
418} 420}
419 421
420void mousekey_clear(void) { 422void mousekey_clear(void) {
421 mouse_report = (report_mouse_t){}; 423 mouse_report = (report_mouse_t){};
422 mousekey_repeat = 0; 424 mousekey_repeat = 0;
423 mousekey_accel = 0; 425 mousekey_wheel_repeat = 0;
426 mousekey_accel = 0;
424} 427}
425 428
426static void mousekey_debug(void) { 429static void mousekey_debug(void) {
diff --git a/tmk_core/common/progmem.h b/tmk_core/common/progmem.h
index 39a918fe9..c8863d3ad 100644
--- a/tmk_core/common/progmem.h
+++ b/tmk_core/common/progmem.h
@@ -4,6 +4,7 @@
4# include <avr/pgmspace.h> 4# include <avr/pgmspace.h>
5#else 5#else
6# define PROGMEM 6# define PROGMEM
7# define PGM_P const char*
7# define memcpy_P(dest, src, n) memcpy(dest, src, n) 8# define memcpy_P(dest, src, n) memcpy(dest, src, n)
8# define pgm_read_byte(address_short) *((uint8_t*)(address_short)) 9# define pgm_read_byte(address_short) *((uint8_t*)(address_short))
9# define pgm_read_word(address_short) *((uint16_t*)(address_short)) 10# define pgm_read_word(address_short) *((uint16_t*)(address_short))
diff --git a/tmk_core/common/report.h b/tmk_core/common/report.h
index c2b1b7c71..1aa33c998 100644
--- a/tmk_core/common/report.h
+++ b/tmk_core/common/report.h
@@ -29,7 +29,8 @@ enum hid_report_ids {
29 REPORT_ID_MOUSE, 29 REPORT_ID_MOUSE,
30 REPORT_ID_SYSTEM, 30 REPORT_ID_SYSTEM,
31 REPORT_ID_CONSUMER, 31 REPORT_ID_CONSUMER,
32 REPORT_ID_NKRO 32 REPORT_ID_NKRO,
33 REPORT_ID_JOYSTICK
33}; 34};
34 35
35/* Mouse buttons */ 36/* Mouse buttons */
@@ -46,8 +47,9 @@ enum mouse_buttons {
46 * See https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf#page=75 47 * See https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf#page=75
47 */ 48 */
48enum consumer_usages { 49enum consumer_usages {
49 // 15.5 Display Controls (https://www.usb.org/sites/default/files/hutrr41_0.pdf) 50 // 15.5 Display Controls
50 BRIGHTNESS_UP = 0x06F, 51 SNAPSHOT = 0x065,
52 BRIGHTNESS_UP = 0x06F, // https://www.usb.org/sites/default/files/hutrr41_0.pdf
51 BRIGHTNESS_DOWN = 0x070, 53 BRIGHTNESS_DOWN = 0x070,
52 // 15.7 Transport Controls 54 // 15.7 Transport Controls
53 TRANSPORT_RECORD = 0x0B2, 55 TRANSPORT_RECORD = 0x0B2,
@@ -57,6 +59,7 @@ enum consumer_usages {
57 TRANSPORT_PREV_TRACK = 0x0B6, 59 TRANSPORT_PREV_TRACK = 0x0B6,
58 TRANSPORT_STOP = 0x0B7, 60 TRANSPORT_STOP = 0x0B7,
59 TRANSPORT_EJECT = 0x0B8, 61 TRANSPORT_EJECT = 0x0B8,
62 TRANSPORT_RANDOM_PLAY = 0x0B9,
60 TRANSPORT_STOP_EJECT = 0x0CC, 63 TRANSPORT_STOP_EJECT = 0x0CC,
61 TRANSPORT_PLAY_PAUSE = 0x0CD, 64 TRANSPORT_PLAY_PAUSE = 0x0CD,
62 // 15.9.1 Audio Controls - Volume 65 // 15.9.1 Audio Controls - Volume
@@ -71,6 +74,7 @@ enum consumer_usages {
71 AL_LOCK = 0x19E, 74 AL_LOCK = 0x19E,
72 AL_CONTROL_PANEL = 0x19F, 75 AL_CONTROL_PANEL = 0x19F,
73 AL_ASSISTANT = 0x1CB, 76 AL_ASSISTANT = 0x1CB,
77 AL_KEYBOARD_LAYOUT = 0x1AE,
74 // 15.16 Generic GUI Application Controls 78 // 15.16 Generic GUI Application Controls
75 AC_MINIMIZE = 0x206, 79 AC_MINIMIZE = 0x206,
76 AC_SEARCH = 0x221, 80 AC_SEARCH = 0x221,
@@ -186,6 +190,16 @@ typedef struct {
186 int8_t h; 190 int8_t h;
187} __attribute__((packed)) report_mouse_t; 191} __attribute__((packed)) report_mouse_t;
188 192
193typedef struct {
194#if JOYSTICK_AXES_COUNT > 0
195 int8_t axes[JOYSTICK_AXES_COUNT];
196#endif
197
198#if JOYSTICK_BUTTON_COUNT > 0
199 uint8_t buttons[(JOYSTICK_BUTTON_COUNT - 1) / 8 + 1];
200#endif
201} __attribute__((packed)) joystick_report_t;
202
189/* keycode to system usage */ 203/* keycode to system usage */
190static inline uint16_t KEYCODE2SYSTEM(uint8_t key) { 204static inline uint16_t KEYCODE2SYSTEM(uint8_t key) {
191 switch (key) { 205 switch (key) {