summaryrefslogtreecommitdiff
path: root/tmk_core/common
diff options
context:
space:
mode:
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 c82c9c81be..345c030c94 100644
--- a/tmk_core/common/action.h
+++ b/tmk_core/common/action.h
@@ -29,7 +29,7 @@ extern "C" {
#endif
/* Disable macro and function features when LTO is enabled, since they break */
-#ifdef LINK_TIME_OPTIMIZATION_ENABLE
+#ifdef LTO_ENABLE
# ifndef NO_ACTION_MACRO
# define NO_ACTION_MACRO
# endif
diff --git a/tmk_core/common/action_layer.h b/tmk_core/common/action_layer.h
index 16922c1ff9..f9f6861120 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);
void layer_off(uint8_t layer);
void layer_invert(uint8_t layer);
/* bitwise operation */
-void layer_or(layer_state_t state);
-void layer_and(layer_state_t state);
-void layer_xor(layer_state_t state);
+void layer_or(layer_state_t state);
+void layer_and(layer_state_t state);
+void layer_xor(layer_state_t state);
+layer_state_t layer_state_set_user(layer_state_t state);
+layer_state_t layer_state_set_kb(layer_state_t state);
#else
# define layer_state 0
@@ -101,11 +103,10 @@ void layer_xor(layer_state_t state);
# define layer_or(state) (void)state
# define layer_and(state) (void)state
# define layer_xor(state) (void)state
+# define layer_state_set_kb(state) (void)state
+# define layer_state_set_user(state) (void)state
#endif
-layer_state_t layer_state_set_user(layer_state_t state);
-layer_state_t layer_state_set_kb(layer_state_t state);
-
/* pressed actions cache */
#if !defined(NO_ACTION_LAYER) && !defined(STRICT_LAYER_RELEASE)
diff --git a/tmk_core/common/bootmagic.c b/tmk_core/common/bootmagic.c
index bb2aa0db8c..c1b3adf94d 100644
--- a/tmk_core/common/bootmagic.c
+++ b/tmk_core/common/bootmagic.c
@@ -122,6 +122,8 @@ void bootmagic(void) {
default_layer = eeconfig_read_default_layer();
default_layer_set((layer_state_t)default_layer);
}
+ /* Also initialize layer state to trigger callback functions for layer_state */
+ layer_state_set_kb((layer_state_t)layer_state);
/* EE_HANDS handedness */
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 4cf5dae7e6..7b2cf5c435 100644
--- a/tmk_core/common/chibios/bootloader.c
+++ b/tmk_core/common/chibios/bootloader.c
@@ -2,29 +2,67 @@
#include "ch.h"
#include "hal.h"
-
-#ifdef STM32_BOOTLOADER_ADDRESS
-/* STM32 */
+#include "wait.h"
/* This code should be checked whether it runs correctly on platforms */
-# define SYMVAL(sym) (uint32_t)(((uint8_t *)&(sym)) - ((uint8_t *)0))
+#define SYMVAL(sym) (uint32_t)(((uint8_t *)&(sym)) - ((uint8_t *)0))
+#define BOOTLOADER_MAGIC 0xDEADBEEF
+#define MAGIC_ADDR (unsigned long *)(SYMVAL(__ram0_end__) - 4)
+
+#ifndef STM32_BOOTLOADER_DUAL_BANK
+# define STM32_BOOTLOADER_DUAL_BANK FALSE
+#endif
+
+#if STM32_BOOTLOADER_DUAL_BANK
+
+// Need pin definitions
+# include "config_common.h"
+
+# ifndef STM32_BOOTLOADER_DUAL_BANK_GPIO
+# error "No STM32_BOOTLOADER_DUAL_BANK_GPIO defined, don't know which pin to toggle"
+# endif
+
+# ifndef STM32_BOOTLOADER_DUAL_BANK_POLARITY
+# define STM32_BOOTLOADER_DUAL_BANK_POLARITY 0
+# endif
+
+# ifndef STM32_BOOTLOADER_DUAL_BANK_DELAY
+# define STM32_BOOTLOADER_DUAL_BANK_DELAY 100000
+# endif
+
+extern uint32_t __ram0_end__;
+
+void bootloader_jump(void) {
+ // For STM32 MCUs with dual-bank flash, and we're incapable of jumping to the bootloader. The first valid flash
+ // bank is executed unconditionally after a reset, so it doesn't enter DFU unless BOOT0 is high. Instead, we do
+ // it with hardware...in this case, we pull a GPIO high/low depending on the configuration, connects 3.3V to
+ // BOOT0's RC charging circuit, lets it charge the capacitor, and issue a system reset. See the QMK discord
+ // #hardware channel pins for an example circuit.
+ palSetPadMode(PAL_PORT(STM32_BOOTLOADER_DUAL_BANK_GPIO), PAL_PAD(STM32_BOOTLOADER_DUAL_BANK_GPIO), PAL_MODE_OUTPUT_PUSHPULL);
+# if STM32_BOOTLOADER_DUAL_BANK_POLARITY
+ palSetPad(PAL_PORT(STM32_BOOTLOADER_DUAL_BANK_GPIO), PAL_PAD(STM32_BOOTLOADER_DUAL_BANK_GPIO));
+# else
+ palClearPad(PAL_PORT(STM32_BOOTLOADER_DUAL_BANK_GPIO), PAL_PAD(STM32_BOOTLOADER_DUAL_BANK_GPIO));
+# endif
+
+ // Wait for a while for the capacitor to charge
+ wait_ms(100);
+
+ // Issue a system reset to get the ROM bootloader to execute, with BOOT0 high
+ NVIC_SystemReset();
+}
+
+void enter_bootloader_mode_if_requested(void) {} // not needed at all, but if anybody attempts to invoke it....
+
+#elif defined(STM32_BOOTLOADER_ADDRESS) // STM32_BOOTLOADER_DUAL_BANK
+
extern uint32_t __ram0_end__;
-# define BOOTLOADER_MAGIC 0xDEADBEEF
-# define MAGIC_ADDR (unsigned long *)(SYMVAL(__ram0_end__) - 4)
-/** \brief Jump to the bootloader
- *
- * FIXME: needs doc
- */
void bootloader_jump(void) {
*MAGIC_ADDR = BOOTLOADER_MAGIC; // set magic flag => reset handler will jump into boot loader
NVIC_SystemReset();
}
-/** \brief Enter bootloader mode if requested
- *
- * FIXME: needs doc
- */
void enter_bootloader_mode_if_requested(void) {
unsigned long *check = MAGIC_ADDR;
if (*check == BOOTLOADER_MAGIC) {
@@ -41,10 +79,10 @@ void enter_bootloader_mode_if_requested(void) {
}
}
-#elif defined(KL2x) || defined(K20x) /* STM32_BOOTLOADER_ADDRESS */
+#elif defined(KL2x) || defined(K20x) // STM32_BOOTLOADER_DUAL_BANK // STM32_BOOTLOADER_ADDRESS
/* Kinetis */
-# if defined(KIIBOHD_BOOTLOADER)
+# if defined(BOOTLOADER_KIIBOHD)
/* Kiibohd Bootloader (MCHCK and Infinity KB) */
# define SCB_AIRCR_VECTKEY_WRITEMAGIC 0x05FA0000
const uint8_t sys_reset_to_loader_magic[] = "\xff\x00\x7fRESET TO LOADER\x7f\x00\xff";
@@ -54,14 +92,14 @@ void bootloader_jump(void) {
SCB->AIRCR = SCB_AIRCR_VECTKEY_WRITEMAGIC | SCB_AIRCR_SYSRESETREQ_Msk;
}
-# else /* defined(KIIBOHD_BOOTLOADER) */
+# else /* defined(BOOTLOADER_KIIBOHD) */
/* Default for Kinetis - expecting an ARM Teensy */
# include "wait.h"
void bootloader_jump(void) {
wait_ms(100);
__BKPT(0);
}
-# endif /* defined(KIIBOHD_BOOTLOADER) */
+# endif /* defined(BOOTLOADER_KIIBOHD) */
#else /* neither STM32 nor KINETIS */
__attribute__((weak)) void bootloader_jump(void) {}
diff --git a/tmk_core/common/chibios/suspend.c b/tmk_core/common/chibios/suspend.c
index 8c071e7a08..64dfc05abc 100644
--- a/tmk_core/common/chibios/suspend.c
+++ b/tmk_core/common/chibios/suspend.c
@@ -9,6 +9,7 @@
#include "mousekey.h"
#include "host.h"
#include "suspend.h"
+#include "led.h"
#include "wait.h"
#ifdef BACKLIGHT_ENABLE
@@ -47,6 +48,20 @@ __attribute__((weak)) void suspend_power_down_kb(void) { suspend_power_down_user
* FIXME: needs doc
*/
void suspend_power_down(void) {
+#ifdef BACKLIGHT_ENABLE
+ backlight_set(0);
+#endif
+
+ // Turn off LED indicators
+ uint8_t leds_off = 0;
+#if defined(BACKLIGHT_CAPS_LOCK) && defined(BACKLIGHT_ENABLE)
+ if (is_backlight_enabled()) {
+ // Don't try to turn off Caps Lock indicator as it is backlight and backlight is already off
+ leds_off |= (1 << USB_LED_CAPS_LOCK);
+ }
+#endif
+ led_set(leds_off);
+
// TODO: figure out what to power down and how
// shouldn't power down TPM/FTM if we want a breathing LED
// also shouldn't power down USB
@@ -119,6 +134,7 @@ void suspend_wakeup_init(void) {
#ifdef BACKLIGHT_ENABLE
backlight_init();
#endif /* BACKLIGHT_ENABLE */
+ led_set(host_keyboard_leds());
#if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE)
is_suspended = false;
if (rgblight_enabled) {
diff --git a/tmk_core/common/command.c b/tmk_core/common/command.c
index ef6a39c0fe..feeb2202e2 100644
--- a/tmk_core/common/command.c
+++ b/tmk_core/common/command.c
@@ -180,7 +180,7 @@ static void print_version(void) {
#ifdef NKRO_ENABLE
" NKRO"
#endif
-#ifdef LINK_TIME_OPTIMIZATION_ENABLE
+#ifdef LTO_ENABLE
" LTO"
#endif
diff --git a/tmk_core/common/keyboard.c b/tmk_core/common/keyboard.c
index 714c3d048f..a45af56dfd 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/>.
#ifdef MIDI_ENABLE
# include "process_midi.h"
#endif
+#ifdef JOYSTICK_ENABLE
+# include "process_joystick.h"
+#endif
#ifdef HD44780_ENABLE
# include "hd44780.h"
#endif
@@ -420,6 +423,10 @@ MATRIX_LOOP_END:
}
#endif
+#ifdef JOYSTICK_ENABLE
+ joystick_task();
+#endif
+
// update LED
if (led_status != host_keyboard_leds()) {
led_status = host_keyboard_leds();
diff --git a/tmk_core/common/magic.c b/tmk_core/common/magic.c
index d8ab525735..e14994164e 100644
--- a/tmk_core/common/magic.c
+++ b/tmk_core/common/magic.c
@@ -33,4 +33,7 @@ void magic(void) {
uint8_t default_layer = 0;
default_layer = eeconfig_read_default_layer();
default_layer_set((layer_state_t)default_layer);
+
+ /* Also initialize layer state to trigger callback functions for layer_state */
+ layer_state_set_kb((layer_state_t)layer_state);
}
diff --git a/tmk_core/common/mousekey.c b/tmk_core/common/mousekey.c
index 42bf231f4c..ef18bcf1a8 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) {
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 uint16_t last_timer = 0;
+static uint8_t mousekey_accel = 0;
+static uint8_t mousekey_repeat = 0;
+static uint8_t mousekey_wheel_repeat = 0;
#ifndef MK_3_SPEED
@@ -94,12 +94,12 @@ static uint8_t wheel_unit(void) {
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_repeat == 0) {
+ } else if (mousekey_wheel_repeat == 0) {
unit = MOUSEKEY_WHEEL_DELTA;
- } else if (mousekey_repeat >= mk_wheel_time_to_max) {
+ } 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_repeat) / mk_wheel_time_to_max;
+ 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));
}
@@ -147,14 +147,17 @@ static uint8_t wheel_unit(void) {
void mousekey_task(void) {
// report cursor and scroll movement independently
report_mouse_t const tmpmr = mouse_report;
- if ((mouse_report.x || mouse_report.y) && timer_elapsed(last_timer_c) > (mousekey_repeat ? mk_interval : mk_delay * 10)) {
+
+ 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++;
- mouse_report.v = 0;
- mouse_report.h = 0;
- if (mouse_report.x > 0) mouse_report.x = move_unit();
- if (mouse_report.x < 0) mouse_report.x = move_unit() * -1;
- if (mouse_report.y > 0) mouse_report.y = move_unit();
- if (mouse_report.y < 0) mouse_report.y = move_unit() * -1;
+ 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);
@@ -166,18 +169,12 @@ void mousekey_task(void) {
mouse_report.y = 1;
}
}
- mousekey_send();
- last_timer_c = last_timer;
- mouse_report = tmpmr;
}
- if ((mouse_report.v || mouse_report.h) && timer_elapsed(last_timer_w) > (mousekey_repeat ? mk_wheel_interval : mk_wheel_delay * 10)) {
- if (mousekey_repeat != UINT8_MAX) mousekey_repeat++;
- mouse_report.x = 0;
- mouse_report.y = 0;
- if (mouse_report.v > 0) mouse_report.v = wheel_unit();
- if (mouse_report.v < 0) mouse_report.v = wheel_unit() * -1;
- if (mouse_report.h > 0) mouse_report.h = wheel_unit();
- if (mouse_report.h < 0) mouse_report.h = wheel_unit() * -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);
@@ -189,10 +186,10 @@ void mousekey_task(void) {
mouse_report.h = 1;
}
}
- mousekey_send();
- last_timer_w = last_timer;
- mouse_report = tmpmr;
}
+
+ if (mouse_report.x || mouse_report.y || mouse_report.v || mouse_report.h) mousekey_send();
+ mouse_report = tmpmr;
}
void mousekey_on(uint8_t code) {
@@ -263,7 +260,8 @@ void mousekey_off(uint8_t code) {
mousekey_accel &= ~(1 << 1);
else if (code == KC_MS_ACCEL2)
mousekey_accel &= ~(1 << 2);
- if (mouse_report.x == 0 && mouse_report.y == 0 && mouse_report.v == 0 && mouse_report.h == 0) mousekey_repeat = 0;
+ 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 */
@@ -285,20 +283,22 @@ uint16_t w_intervals[mkspd_COUNT] = {MK_W_INTERVAL_UNMOD, MK_W_INTERVAL_0
void mousekey_task(void) {
// report cursor and scroll movement independently
report_mouse_t const tmpmr = mouse_report;
- if ((mouse_report.x || mouse_report.y) && timer_elapsed(last_timer_c) > c_intervals[mk_speed]) {
- mouse_report.h = 0;
- mouse_report.v = 0;
- mousekey_send();
- last_timer_c = last_timer;
- mouse_report = tmpmr;
+ 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 ((mouse_report.h || mouse_report.v) && timer_elapsed(last_timer_w) > w_intervals[mk_speed]) {
- mouse_report.x = 0;
- mouse_report.y = 0;
- mousekey_send();
- last_timer_w = last_timer;
- mouse_report = tmpmr;
+ 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) {
@@ -413,14 +413,17 @@ void mousekey_off(uint8_t code) {
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);
- last_timer = timer_read();
}
void mousekey_clear(void) {
- mouse_report = (report_mouse_t){};
- mousekey_repeat = 0;
- mousekey_accel = 0;
+ mouse_report = (report_mouse_t){};
+ mousekey_repeat = 0;
+ mousekey_wheel_repeat = 0;
+ mousekey_accel = 0;
}
static void mousekey_debug(void) {
diff --git a/tmk_core/common/progmem.h b/tmk_core/common/progmem.h
index 39a918fe98..c8863d3ad2 100644
--- a/tmk_core/common/progmem.h
+++ b/tmk_core/common/progmem.h
@@ -4,6 +4,7 @@
# include <avr/pgmspace.h>
#else
# define PROGMEM
+# define PGM_P const char*
# define memcpy_P(dest, src, n) memcpy(dest, src, n)
# define pgm_read_byte(address_short) *((uint8_t*)(address_short))
# 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 c2b1b7c710..1aa33c998d 100644
--- a/tmk_core/common/report.h
+++ b/tmk_core/common/report.h
@@ -29,7 +29,8 @@ enum hid_report_ids {
REPORT_ID_MOUSE,
REPORT_ID_SYSTEM,
REPORT_ID_CONSUMER,
- REPORT_ID_NKRO
+ REPORT_ID_NKRO,
+ REPORT_ID_JOYSTICK
};
/* Mouse buttons */
@@ -46,8 +47,9 @@ enum mouse_buttons {
* See https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf#page=75
*/
enum consumer_usages {
- // 15.5 Display Controls (https://www.usb.org/sites/default/files/hutrr41_0.pdf)
- BRIGHTNESS_UP = 0x06F,
+ // 15.5 Display Controls
+ SNAPSHOT = 0x065,
+ BRIGHTNESS_UP = 0x06F, // https://www.usb.org/sites/default/files/hutrr41_0.pdf
BRIGHTNESS_DOWN = 0x070,
// 15.7 Transport Controls
TRANSPORT_RECORD = 0x0B2,
@@ -57,6 +59,7 @@ enum consumer_usages {
TRANSPORT_PREV_TRACK = 0x0B6,
TRANSPORT_STOP = 0x0B7,
TRANSPORT_EJECT = 0x0B8,
+ TRANSPORT_RANDOM_PLAY = 0x0B9,
TRANSPORT_STOP_EJECT = 0x0CC,
TRANSPORT_PLAY_PAUSE = 0x0CD,
// 15.9.1 Audio Controls - Volume
@@ -71,6 +74,7 @@ enum consumer_usages {
AL_LOCK = 0x19E,
AL_CONTROL_PANEL = 0x19F,
AL_ASSISTANT = 0x1CB,
+ AL_KEYBOARD_LAYOUT = 0x1AE,
// 15.16 Generic GUI Application Controls
AC_MINIMIZE = 0x206,
AC_SEARCH = 0x221,
@@ -186,6 +190,16 @@ typedef struct {
int8_t h;
} __attribute__((packed)) report_mouse_t;
+typedef struct {
+#if JOYSTICK_AXES_COUNT > 0
+ int8_t axes[JOYSTICK_AXES_COUNT];
+#endif
+
+#if JOYSTICK_BUTTON_COUNT > 0
+ uint8_t buttons[(JOYSTICK_BUTTON_COUNT - 1) / 8 + 1];
+#endif
+} __attribute__((packed)) joystick_report_t;
+
/* keycode to system usage */
static inline uint16_t KEYCODE2SYSTEM(uint8_t key) {
switch (key) {