From bc536b9b6d98e5428a28f6e6ba69675bd77b79cc Mon Sep 17 00:00:00 2001 From: Bob Date: Mon, 8 Apr 2019 17:07:15 -0400 Subject: Switch process_combo to using global register and timer (#2561) Since combos keep local state about what keys have been previously pressed, when combos are layered, multiple keypresses will register for any key with multiple combos assigned to it. In order to fix this, I switched process_combo to use a global keycode / keyrecord register and timer. When a keypress is consumed by a combo, it gets stored in the register and the timer is updated; when the next keypress takes too long or a key is pressed that isn't part of any combo, the buffer is emitted and the timer reset. This has a few side effects. For instance, I couldn't _not_ fix combo keys printing out of order while also fixing this bug, so combo keys print in order correctly when a combo fails. since combos no longer have local timers, the logic around when combos time out has changed. now that there is a single timer pressing any combo key (including one in a different combo) will reset the timer for all combos, making combo entry a little more lenient. Since combos no longer have local keycode / keyrecord state, there is an edge case where incomplete combo keys can be consumed. if you have a combo for a+s = tab and a combo for b+n = space, if you press a+b+n, only a space will be emitted. This is because when b+n completes successfully, it drops the register. --- quantum/process_keycode/process_combo.c | 239 +++++++++++++++++--------------- quantum/process_keycode/process_combo.h | 33 ++--- 2 files changed, 148 insertions(+), 124 deletions(-) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_combo.c b/quantum/process_keycode/process_combo.c index 13f8bbb331..a157ed48be 100644 --- a/quantum/process_keycode/process_combo.c +++ b/quantum/process_keycode/process_combo.c @@ -14,141 +14,164 @@ * along with this program. If not, see . */ -#include "process_combo.h" #include "print.h" +#include "process_combo.h" - -__attribute__ ((weak)) -combo_t key_combos[COMBO_COUNT] = { +__attribute__((weak)) combo_t key_combos[COMBO_COUNT] = { }; -__attribute__ ((weak)) -void process_combo_event(uint8_t combo_index, bool pressed) { - -} +__attribute__((weak)) void process_combo_event(uint8_t combo_index, + bool pressed) {} +static uint16_t timer = 0; static uint8_t current_combo_index = 0; +static bool drop_buffer = false; +static bool is_active = false; -static inline void send_combo(uint16_t action, bool pressed) -{ - if (action) { - if (pressed) { - register_code16(action); - } else { - unregister_code16(action); - } - } else { - process_combo_event(current_combo_index, pressed); - } -} - -#define ALL_COMBO_KEYS_ARE_DOWN (((1<state) -#define NO_COMBO_KEYS_ARE_DOWN (0 == combo->state) -#define KEY_STATE_DOWN(key) do{ combo->state |= (1<state &= ~(1<keys; ;++count) { - uint16_t key = pgm_read_word(&keys[count]); - if (keycode == key) index = count; - if (COMBO_END == key) break; - } - - /* Return if not a combo key */ - if (-1 == (int8_t)index) return false; - - /* The combos timer is used to signal whether the combo is active */ - bool is_combo_active = combo->is_active; - - if (record->event.pressed) { - KEY_STATE_DOWN(index); - - if (is_combo_active) { - if (ALL_COMBO_KEYS_ARE_DOWN) { /* Combo was pressed */ - send_combo(combo->keycode, true); - combo->is_active = false; - } else { /* Combo key was pressed */ - combo->timer = timer_read(); - combo->is_active = true; +static uint8_t buffer_size = 0; #ifdef COMBO_ALLOW_ACTION_KEYS - combo->prev_record = *record; +static keyrecord_t key_buffer[MAX_COMBO_LENGTH]; #else - combo->prev_key = keycode; +static uint16_t key_buffer[MAX_COMBO_LENGTH]; #endif - } - } + +static inline void send_combo(uint16_t action, bool pressed) { + if (action) { + if (pressed) { + register_code16(action); } else { - if (ALL_COMBO_KEYS_ARE_DOWN) { /* Combo was released */ - send_combo(combo->keycode, false); - } + unregister_code16(action); + } + } else { + process_combo_event(current_combo_index, pressed); + } +} - if (is_combo_active) { /* Combo key was tapped */ +static inline void dump_key_buffer(bool emit) { + if (buffer_size == 0) { + return; + } + + if (emit) { + for (uint8_t i = 0; i < buffer_size; i++) { #ifdef COMBO_ALLOW_ACTION_KEYS - record->event.pressed = true; - process_action(record, store_or_get_action(record->event.pressed, record->event.key)); - record->event.pressed = false; - process_action(record, store_or_get_action(record->event.pressed, record->event.key)); + const action_t action = store_or_get_action(key_buffer[i].event.pressed, + key_buffer[i].event.key); + process_action(&(key_buffer[i]), action); #else - register_code16(keycode); - send_keyboard_report(); - unregister_code16(keycode); + register_code16(key_buffer[i]); + send_keyboard_report(); #endif - combo->is_active = false; - combo->timer = 0; - } - - KEY_STATE_UP(index); } + } - if (NO_COMBO_KEYS_ARE_DOWN) { - combo->is_active = true; - combo->timer = 0; - } - - return is_combo_active; + buffer_size = 0; } -bool process_combo(uint16_t keycode, keyrecord_t *record) -{ - bool is_combo_key = false; +#define ALL_COMBO_KEYS_ARE_DOWN (((1 << count) - 1) == combo->state) +#define KEY_STATE_DOWN(key) \ + do { \ + combo->state |= (1 << key); \ + } while (0) +#define KEY_STATE_UP(key) \ + do { \ + combo->state &= ~(1 << key); \ + } while (0) + +static bool process_single_combo(combo_t *combo, uint16_t keycode, + keyrecord_t *record) { + uint8_t count = 0; + uint8_t index = -1; + /* Find index of keycode and number of combo keys */ + for (const uint16_t *keys = combo->keys;; ++count) { + uint16_t key = pgm_read_word(&keys[count]); + if (keycode == key) + index = count; + if (COMBO_END == key) + break; + } + + /* Continue processing if not a combo key */ + if (-1 == (int8_t)index) + return false; + + bool is_combo_active = is_active; + + if (record->event.pressed) { + KEY_STATE_DOWN(index); + + if (is_combo_active) { + if (ALL_COMBO_KEYS_ARE_DOWN) { /* Combo was pressed */ + send_combo(combo->keycode, true); + drop_buffer = true; + } + } + } else { + if (ALL_COMBO_KEYS_ARE_DOWN) { /* Combo was released */ + send_combo(combo->keycode, false); + } else { + /* continue processing without immediately returning */ + is_combo_active = false; + } - for (current_combo_index = 0; current_combo_index < COMBO_COUNT; ++current_combo_index) { - combo_t *combo = &key_combos[current_combo_index]; - is_combo_key |= process_single_combo(combo, keycode, record); - } + KEY_STATE_UP(index); + } - return !is_combo_key; + return is_combo_active; } -void matrix_scan_combo(void) -{ - for (int i = 0; i < COMBO_COUNT; ++i) { - // Do not treat the (weak) key_combos too strict. - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Warray-bounds" - combo_t *combo = &key_combos[i]; - #pragma GCC diagnostic pop - if (combo->is_active && - combo->timer && - timer_elapsed(combo->timer) > COMBO_TERM) { - - /* This disables the combo, meaning key events for this - * combo will be handled by the next processors in the chain - */ - combo->is_active = false; +#define NO_COMBO_KEYS_ARE_DOWN (0 == combo->state) + +bool process_combo(uint16_t keycode, keyrecord_t *record) { + bool is_combo_key = false; + drop_buffer = false; + bool no_combo_keys_pressed = false; + + for (current_combo_index = 0; current_combo_index < COMBO_COUNT; + ++current_combo_index) { + combo_t *combo = &key_combos[current_combo_index]; + is_combo_key |= process_single_combo(combo, keycode, record); + no_combo_keys_pressed |= NO_COMBO_KEYS_ARE_DOWN; + } + + if (drop_buffer) { + /* buffer is only dropped when we complete a combo, so we refresh the timer + * here */ + timer = timer_read(); + dump_key_buffer(false); + } else if (!is_combo_key) { + /* if no combos claim the key we need to emit the keybuffer */ + dump_key_buffer(true); + + // reset state if there are no combo keys pressed at all + if (no_combo_keys_pressed) { + timer = 0; + is_active = true; + } + } else if (record->event.pressed && is_active) { + /* otherwise the key is consumed and placed in the buffer */ + timer = timer_read(); + if (buffer_size < MAX_COMBO_LENGTH) { #ifdef COMBO_ALLOW_ACTION_KEYS - process_action(&combo->prev_record, - store_or_get_action(combo->prev_record.event.pressed, - combo->prev_record.event.key)); + key_buffer[buffer_size++] = *record; #else - unregister_code16(combo->prev_key); - register_code16(combo->prev_key); + key_buffer[buffer_size++] = keycode; #endif - } } + } + + return !is_combo_key; +} + +void matrix_scan_combo(void) { + if (is_active && timer && timer_elapsed(timer) > COMBO_TERM) { + + /* This disables the combo, meaning key events for this + * combo will be handled by the next processors in the chain + */ + is_active = false; + dump_key_buffer(true); + } } diff --git a/quantum/process_keycode/process_combo.h b/quantum/process_keycode/process_combo.h index a5787c9ed3..f06d2d3454 100644 --- a/quantum/process_keycode/process_combo.h +++ b/quantum/process_keycode/process_combo.h @@ -17,33 +17,34 @@ #ifndef PROCESS_COMBO_H #define PROCESS_COMBO_H -#include #include "progmem.h" #include "quantum.h" +#include -typedef struct -{ - const uint16_t *keys; - uint16_t keycode; #ifdef EXTRA_EXTRA_LONG_COMBOS - uint32_t state; +#define MAX_COMBO_LENGTH 32 #elif EXTRA_LONG_COMBOS - uint16_t state; +#define MAX_COMBO_LENGTH 16 #else - uint8_t state; +#define MAX_COMBO_LENGTH 8 #endif - uint16_t timer; - bool is_active; -#ifdef COMBO_ALLOW_ACTION_KEYS - keyrecord_t prev_record; + +typedef struct { + const uint16_t *keys; + uint16_t keycode; +#ifdef EXTRA_EXTRA_LONG_COMBOS + uint32_t state; +#elif EXTRA_LONG_COMBOS + uint16_t state; #else - uint16_t prev_key; + uint8_t state; #endif } combo_t; - -#define COMBO(ck, ca) {.keys = &(ck)[0], .keycode = (ca)} -#define COMBO_ACTION(ck) {.keys = &(ck)[0]} +#define COMBO(ck, ca) \ + { .keys = &(ck)[0], .keycode = (ca) } +#define COMBO_ACTION(ck) \ + { .keys = &(ck)[0] } #define COMBO_END 0 #ifndef COMBO_COUNT -- cgit v1.2.3 From 02b74d521bf84ba776a5920289887ad418806311 Mon Sep 17 00:00:00 2001 From: Bob Date: Sun, 14 Apr 2019 14:02:41 -0400 Subject: fix combo enabling logic (#5610) --- quantum/process_keycode/process_combo.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_combo.c b/quantum/process_keycode/process_combo.c index a157ed48be..2c6c9d0d5f 100644 --- a/quantum/process_keycode/process_combo.c +++ b/quantum/process_keycode/process_combo.c @@ -126,13 +126,13 @@ static bool process_single_combo(combo_t *combo, uint16_t keycode, bool process_combo(uint16_t keycode, keyrecord_t *record) { bool is_combo_key = false; drop_buffer = false; - bool no_combo_keys_pressed = false; + bool no_combo_keys_pressed = true; for (current_combo_index = 0; current_combo_index < COMBO_COUNT; ++current_combo_index) { combo_t *combo = &key_combos[current_combo_index]; is_combo_key |= process_single_combo(combo, keycode, record); - no_combo_keys_pressed |= NO_COMBO_KEYS_ARE_DOWN; + no_combo_keys_pressed = no_combo_keys_pressed && NO_COMBO_KEYS_ARE_DOWN; } if (drop_buffer) { -- cgit v1.2.3 From c745d9b82e3f2047feb97a7a8937f27c6e989fd7 Mon Sep 17 00:00:00 2001 From: XScorpion2 Date: Mon, 29 Apr 2019 22:21:46 -0500 Subject: Simple extended space cadet (#5277) * Simplifying and Extending Space Cadet to work on Ctrl and Alt keys * PR Review feedback * Reverting back to keycodes --- quantum/process_keycode/process_space_cadet.c | 146 ++++++++++++++++++++++++++ quantum/process_keycode/process_space_cadet.h | 21 ++++ 2 files changed, 167 insertions(+) create mode 100644 quantum/process_keycode/process_space_cadet.c create mode 100644 quantum/process_keycode/process_space_cadet.h (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_space_cadet.c b/quantum/process_keycode/process_space_cadet.c new file mode 100644 index 0000000000..a9c506168d --- /dev/null +++ b/quantum/process_keycode/process_space_cadet.c @@ -0,0 +1,146 @@ +/* Copyright 2019 Jack Humbert + * + * 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 . + */ +#include "process_space_cadet.h" + +#ifndef TAPPING_TERM + #define TAPPING_TERM 200 +#endif + +// ********** OBSOLETE DEFINES, STOP USING! (pls?) ********** +// Shift / paren setup +#ifndef LSPO_KEY + #define LSPO_KEY KC_9 +#endif +#ifndef RSPC_KEY + #define RSPC_KEY KC_0 +#endif + +// Shift / Enter setup +#ifndef SFTENT_KEY + #define SFTENT_KEY KC_ENT +#endif + +#ifdef DISABLE_SPACE_CADET_MODIFIER + #ifndef LSPO_MOD + #define LSPO_MOD KC_TRNS + #endif + #ifndef RSPC_MOD + #define RSPC_MOD KC_TRNS + #endif +#else + #ifndef LSPO_MOD + #define LSPO_MOD KC_LSFT + #endif + #ifndef RSPC_MOD + #define RSPC_MOD KC_RSFT + #endif +#endif +// ********************************************************** + +// Shift / paren setup +#ifndef LSPO_KEYS + #define LSPO_KEYS KC_LSFT, LSPO_MOD, LSPO_KEY +#endif +#ifndef RSPC_KEYS + #define RSPC_KEYS KC_RSFT, RSPC_MOD, RSPC_KEY +#endif + +// Control / paren setup +#ifndef LCPO_KEYS + #define LCPO_KEYS KC_LCTL, KC_LCTL, KC_9 +#endif +#ifndef RCPO_KEYS + #define RCPO_KEYS KC_RCTL, KC_RCTL, KC_0 +#endif + +// Alt / paren setup +#ifndef LAPO_KEYS + #define LAPO_KEYS KC_LALT, KC_LALT, KC_9 +#endif +#ifndef RAPO_KEYS + #define RAPO_KEYS KC_RALT, KC_RALT, KC_0 +#endif + +// Shift / Enter setup +#ifndef SFTENT_KEYS + #define SFTENT_KEYS KC_RSFT, KC_TRNS, SFTENT_KEY +#endif + +static uint8_t sc_last = 0; +static uint16_t sc_timer = 0; + +void perform_space_cadet(keyrecord_t *record, uint8_t normalMod, uint8_t tapMod, uint8_t keycode) { + if (record->event.pressed) { + sc_last = normalMod; + sc_timer = timer_read (); + if (IS_MOD(normalMod)) { + register_mods(MOD_BIT(normalMod)); + } + } + else { + if (IS_MOD(normalMod)) { + unregister_mods(MOD_BIT(normalMod)); + } + + if (sc_last == normalMod && timer_elapsed(sc_timer) < TAPPING_TERM) { + if (IS_MOD(tapMod)) { + register_mods(MOD_BIT(tapMod)); + } + tap_code(keycode); + if (IS_MOD(tapMod)) { + unregister_mods(MOD_BIT(tapMod)); + } + } + } +} + +bool process_space_cadet(uint16_t keycode, keyrecord_t *record) { + switch(keycode) { + case KC_LSPO: { + perform_space_cadet(record, LSPO_KEYS); + return false; + } + case KC_RSPC: { + perform_space_cadet(record, RSPC_KEYS); + return false; + } + case KC_LCPO: { + perform_space_cadet(record, LCPO_KEYS); + return false; + } + case KC_RCPC: { + perform_space_cadet(record, RCPO_KEYS); + return false; + } + case KC_LAPO: { + perform_space_cadet(record, LAPO_KEYS); + return false; + } + case KC_RAPC: { + perform_space_cadet(record, RAPO_KEYS); + return false; + } + case KC_SFTENT: { + perform_space_cadet(record, SFTENT_KEYS); + return false; + } + default: { + sc_last = 0; + break; + } + } + return true; +} diff --git a/quantum/process_keycode/process_space_cadet.h b/quantum/process_keycode/process_space_cadet.h new file mode 100644 index 0000000000..3f08b8002a --- /dev/null +++ b/quantum/process_keycode/process_space_cadet.h @@ -0,0 +1,21 @@ +/* Copyright 2019 Jack Humbert + * + * 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 . + */ +#pragma once + +#include "quantum.h" + +void perform_space_cadet(keyrecord_t *record, uint8_t normalMod, uint8_t tapMod, uint8_t keycode); +bool process_space_cadet(uint16_t keycode, keyrecord_t *record); -- cgit v1.2.3 From bdc8d89e6b8f49528b716d9bd3343a4f9e9327bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20=C4=90or=C4=91evi=C4=87?= Date: Fri, 3 May 2019 18:33:00 +0200 Subject: New keycode macro (XP) for shifted character pairs using UNICODEMAP + bug fixes and improvements (#4803) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Expose unicode_saved_mods * Add UNICODEMAP shift pair functionality and XS keycode * Add XS to keycode reference documentation * Pick pair index based on both Shift and Caps Lock state * Add XS to Unicode feature docs * Clean up process_unicode* headers * Extract unicode_map index calculation into function * Pick pair index as XOR rather than OR of Shift and Caps states * unicode_input_start() has to be called before the unicode_map index is calculated * Replace unicodemap_input_error() with more generic unicode_input_cancel() * Replace register+tap+unregister with tap_code16(LCTL(LSFT(KC_U))) * UNICODE_OSX_KEY → UNICODE_KEY_OSX, UNICODE_WINC_KEY → UNICODE_KEY_WINC * Make keycode range checks more robust * Fix keycode range checks for different input modes * Add UNICODE_KEY_LNX, update docs * QK_UNICODEMAP_SHIFT → QK_UNICODEMAP_PAIR * XS → XP, update docs * Tweak Unicode docs * Use recently added MOD_MASK_SHIFT and IS_HOST_LED_ON helpers * Update Unicode table in docs/keycodes.md * Update Unicode docs per review comments * Replace references to Mac OS X with macOS in Unicode docs * As of v0.9.0, WinCompose supports all possible code points * Expand descriptions in XP docs * Update keycode table and cycling docs * Further expand cycling docs --- quantum/process_keycode/process_unicode.c | 6 ++-- quantum/process_keycode/process_unicode.h | 2 +- quantum/process_keycode/process_unicode_common.c | 38 ++++++++++++++++-------- quantum/process_keycode/process_unicode_common.h | 13 +++++--- quantum/process_keycode/process_unicodemap.c | 36 ++++++++++++++-------- quantum/process_keycode/process_unicodemap.h | 4 +-- 6 files changed, 64 insertions(+), 35 deletions(-) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_unicode.c b/quantum/process_keycode/process_unicode.c index 19beb84520..2c914013ac 100644 --- a/quantum/process_keycode/process_unicode.c +++ b/quantum/process_keycode/process_unicode.c @@ -13,15 +13,15 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ + #include "process_unicode.h" #include "action_util.h" #include "eeprom.h" bool process_unicode(uint16_t keycode, keyrecord_t *record) { - if (keycode > QK_UNICODE && record->event.pressed) { - uint16_t unicode = keycode & 0x7FFF; + if (keycode >= QK_UNICODE && keycode <= QK_UNICODE_MAX && record->event.pressed) { unicode_input_start(); - register_hex(unicode); + register_hex(keycode & 0x7FFF); unicode_input_finish(); } return true; diff --git a/quantum/process_keycode/process_unicode.h b/quantum/process_keycode/process_unicode.h index 0913e99107..22765ad560 100644 --- a/quantum/process_keycode/process_unicode.h +++ b/quantum/process_keycode/process_unicode.h @@ -13,9 +13,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ + #pragma once -#include "quantum.h" #include "process_unicode_common.h" bool process_unicode(uint16_t keycode, keyrecord_t *record); diff --git a/quantum/process_keycode/process_unicode_common.c b/quantum/process_keycode/process_unicode_common.c index d0a9cf2324..21ac2291db 100644 --- a/quantum/process_keycode/process_unicode_common.c +++ b/quantum/process_keycode/process_unicode_common.c @@ -20,6 +20,8 @@ #include unicode_config_t unicode_config; +uint8_t unicode_saved_mods; + #if UNICODE_SELECTED_MODES != -1 static uint8_t selected[] = { UNICODE_SELECTED_MODES }; static uint8_t selected_count = sizeof selected / sizeof *selected; @@ -75,30 +77,24 @@ void persist_unicode_input_mode(void) { eeprom_update_byte(EECONFIG_UNICODEMODE, unicode_config.input_mode); } -static uint8_t saved_mods; - __attribute__((weak)) void unicode_input_start(void) { - saved_mods = get_mods(); // Save current mods + unicode_saved_mods = get_mods(); // Save current mods clear_mods(); // Unregister mods to start from a clean state switch (unicode_config.input_mode) { case UC_OSX: - register_code(UNICODE_OSX_KEY); + register_code(UNICODE_KEY_OSX); break; case UC_LNX: - register_code(KC_LCTL); - register_code(KC_LSFT); - tap_code(KC_U); // TODO: Replace with tap_code16(LCTL(LSFT(KC_U))); and test - unregister_code(KC_LSFT); - unregister_code(KC_LCTL); + tap_code16(UNICODE_KEY_LNX); break; case UC_WIN: register_code(KC_LALT); tap_code(KC_PPLS); break; case UC_WINC: - tap_code(UNICODE_WINC_KEY); + tap_code(UNICODE_KEY_WINC); tap_code(KC_U); break; } @@ -110,7 +106,7 @@ __attribute__((weak)) void unicode_input_finish(void) { switch (unicode_config.input_mode) { case UC_OSX: - unregister_code(UNICODE_OSX_KEY); + unregister_code(UNICODE_KEY_OSX); break; case UC_LNX: tap_code(KC_SPC); @@ -123,7 +119,25 @@ void unicode_input_finish(void) { break; } - set_mods(saved_mods); // Reregister previously set mods + set_mods(unicode_saved_mods); // Reregister previously set mods +} + +__attribute__((weak)) +void unicode_input_cancel(void) { + switch (unicode_config.input_mode) { + case UC_OSX: + unregister_code(UNICODE_KEY_OSX); + break; + case UC_LNX: + case UC_WINC: + tap_code(KC_ESC); + break; + case UC_WIN: + unregister_code(KC_LALT); + break; + } + + set_mods(unicode_saved_mods); // Reregister previously set mods } __attribute__((weak)) diff --git a/quantum/process_keycode/process_unicode_common.h b/quantum/process_keycode/process_unicode_common.h index e608ab76be..7340800e56 100644 --- a/quantum/process_keycode/process_unicode_common.h +++ b/quantum/process_keycode/process_unicode_common.h @@ -23,11 +23,14 @@ #endif // Keycodes used for starting Unicode input on different platforms -#ifndef UNICODE_OSX_KEY - #define UNICODE_OSX_KEY KC_LALT +#ifndef UNICODE_KEY_OSX + #define UNICODE_KEY_OSX KC_LALT #endif -#ifndef UNICODE_WINC_KEY - #define UNICODE_WINC_KEY KC_RALT +#ifndef UNICODE_KEY_LNX + #define UNICODE_KEY_LNX LCTL(LSFT(KC_U)) +#endif +#ifndef UNICODE_KEY_WINC + #define UNICODE_KEY_WINC KC_RALT #endif // Comma-delimited, ordered list of input modes selected for use (e.g. in cycle) @@ -63,6 +66,7 @@ typedef union { } unicode_config_t; extern unicode_config_t unicode_config; +extern uint8_t unicode_saved_mods; void unicode_input_mode_init(void); uint8_t get_unicode_input_mode(void); @@ -72,6 +76,7 @@ void persist_unicode_input_mode(void); void unicode_input_start(void); void unicode_input_finish(void); +void unicode_input_cancel(void); void register_hex(uint16_t hex); void send_unicode_hex_string(const char *str); diff --git a/quantum/process_keycode/process_unicodemap.c b/quantum/process_keycode/process_unicodemap.c index 3274027613..b887879860 100644 --- a/quantum/process_keycode/process_unicodemap.c +++ b/quantum/process_keycode/process_unicodemap.c @@ -15,7 +15,6 @@ */ #include "process_unicodemap.h" -#include "process_unicode_common.h" void register_hex32(uint32_t hex) { bool onzerostart = true; @@ -38,28 +37,39 @@ void register_hex32(uint32_t hex) { } __attribute__((weak)) -void unicodemap_input_error() {} +uint16_t unicodemap_index(uint16_t keycode) { + if (keycode >= QK_UNICODEMAP_PAIR) { + // Keycode is a pair: extract index based on Shift / Caps Lock state + uint16_t index = keycode - QK_UNICODEMAP_PAIR; + + bool shift = unicode_saved_mods & MOD_MASK_SHIFT, caps = IS_HOST_LED_ON(USB_LED_CAPS_LOCK); + if (shift ^ caps) { index >>= 7; } + + return index & 0x7F; + } else { + // Keycode is a regular index + return keycode - QK_UNICODEMAP; + } +} bool process_unicodemap(uint16_t keycode, keyrecord_t *record) { - if ((keycode & QK_UNICODEMAP) == QK_UNICODEMAP && record->event.pressed) { - uint16_t index = keycode - QK_UNICODEMAP; - uint32_t code = pgm_read_dword(unicode_map + index); + if (keycode >= QK_UNICODEMAP && keycode <= QK_UNICODEMAP_PAIR_MAX && record->event.pressed) { + unicode_input_start(); + + uint32_t code = pgm_read_dword(unicode_map + unicodemap_index(keycode)); uint8_t input_mode = get_unicode_input_mode(); - if (code > 0xFFFF && code <= 0x10FFFF && input_mode == UC_OSX) { - // Convert to UTF-16 surrogate pair + if (code > 0x10FFFF || (code > 0xFFFF && input_mode == UC_WIN)) { + // Character is out of range supported by the platform + unicode_input_cancel(); + } else if (code > 0xFFFF && input_mode == UC_OSX) { + // Convert to UTF-16 surrogate pair on Mac code -= 0x10000; uint32_t lo = code & 0x3FF, hi = (code & 0xFFC00) >> 10; - - unicode_input_start(); register_hex32(hi + 0xD800); register_hex32(lo + 0xDC00); unicode_input_finish(); - } else if ((code > 0x10FFFF && input_mode == UC_OSX) || (code > 0xFFFFF && input_mode == UC_LNX)) { - // Character is out of range supported by the OS - unicodemap_input_error(); } else { - unicode_input_start(); register_hex32(code); unicode_input_finish(); } diff --git a/quantum/process_keycode/process_unicodemap.h b/quantum/process_keycode/process_unicodemap.h index fe4f979155..51709c5dc8 100644 --- a/quantum/process_keycode/process_unicodemap.h +++ b/quantum/process_keycode/process_unicodemap.h @@ -16,10 +16,10 @@ #pragma once -#include "quantum.h" #include "process_unicode_common.h" extern const uint32_t PROGMEM unicode_map[]; -void unicodemap_input_error(void); +void register_hex32(uint32_t hex); +uint16_t unicodemap_index(uint16_t keycode); bool process_unicodemap(uint16_t keycode, keyrecord_t *record); -- cgit v1.2.3 From e290dc5ad811e9d121e216fba6fe03666772c3a4 Mon Sep 17 00:00:00 2001 From: XScorpion2 Date: Sun, 5 May 2019 18:27:02 -0500 Subject: Space Cadet: Reducing unnecessary reported keypresses (#5781) * Reducing unnecessary reported keypresses and minor docs / variable name changes * Apply suggestions from code review Co-Authored-By: XScorpion2 --- quantum/process_keycode/process_space_cadet.c | 39 +++++++++++++++------------ quantum/process_keycode/process_space_cadet.h | 2 +- 2 files changed, 23 insertions(+), 18 deletions(-) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_space_cadet.c b/quantum/process_keycode/process_space_cadet.c index a9c506168d..ac39df8089 100644 --- a/quantum/process_keycode/process_space_cadet.c +++ b/quantum/process_keycode/process_space_cadet.c @@ -62,16 +62,16 @@ #ifndef LCPO_KEYS #define LCPO_KEYS KC_LCTL, KC_LCTL, KC_9 #endif -#ifndef RCPO_KEYS - #define RCPO_KEYS KC_RCTL, KC_RCTL, KC_0 +#ifndef RCPC_KEYS + #define RCPC_KEYS KC_RCTL, KC_RCTL, KC_0 #endif // Alt / paren setup #ifndef LAPO_KEYS #define LAPO_KEYS KC_LALT, KC_LALT, KC_9 #endif -#ifndef RAPO_KEYS - #define RAPO_KEYS KC_RALT, KC_RALT, KC_0 +#ifndef RAPC_KEYS + #define RAPC_KEYS KC_RALT, KC_RALT, KC_0 #endif // Shift / Enter setup @@ -82,27 +82,32 @@ static uint8_t sc_last = 0; static uint16_t sc_timer = 0; -void perform_space_cadet(keyrecord_t *record, uint8_t normalMod, uint8_t tapMod, uint8_t keycode) { +void perform_space_cadet(keyrecord_t *record, uint8_t holdMod, uint8_t tapMod, uint8_t keycode) { if (record->event.pressed) { - sc_last = normalMod; + sc_last = holdMod; sc_timer = timer_read (); - if (IS_MOD(normalMod)) { - register_mods(MOD_BIT(normalMod)); + if (IS_MOD(holdMod)) { + register_mods(MOD_BIT(holdMod)); } } else { - if (IS_MOD(normalMod)) { - unregister_mods(MOD_BIT(normalMod)); - } - - if (sc_last == normalMod && timer_elapsed(sc_timer) < TAPPING_TERM) { - if (IS_MOD(tapMod)) { - register_mods(MOD_BIT(tapMod)); + if (sc_last == holdMod && timer_elapsed(sc_timer) < TAPPING_TERM) { + if (holdMod != tapMod) { + if (IS_MOD(holdMod)) { + unregister_mods(MOD_BIT(holdMod)); + } + if (IS_MOD(tapMod)) { + register_mods(MOD_BIT(tapMod)); + } } tap_code(keycode); if (IS_MOD(tapMod)) { unregister_mods(MOD_BIT(tapMod)); } + } else { + if (IS_MOD(holdMod)) { + unregister_mods(MOD_BIT(holdMod)); + } } } } @@ -122,7 +127,7 @@ bool process_space_cadet(uint16_t keycode, keyrecord_t *record) { return false; } case KC_RCPC: { - perform_space_cadet(record, RCPO_KEYS); + perform_space_cadet(record, RCPC_KEYS); return false; } case KC_LAPO: { @@ -130,7 +135,7 @@ bool process_space_cadet(uint16_t keycode, keyrecord_t *record) { return false; } case KC_RAPC: { - perform_space_cadet(record, RAPO_KEYS); + perform_space_cadet(record, RAPC_KEYS); return false; } case KC_SFTENT: { diff --git a/quantum/process_keycode/process_space_cadet.h b/quantum/process_keycode/process_space_cadet.h index 3f08b8002a..c823143504 100644 --- a/quantum/process_keycode/process_space_cadet.h +++ b/quantum/process_keycode/process_space_cadet.h @@ -17,5 +17,5 @@ #include "quantum.h" -void perform_space_cadet(keyrecord_t *record, uint8_t normalMod, uint8_t tapMod, uint8_t keycode); +void perform_space_cadet(keyrecord_t *record, uint8_t holdMod, uint8_t tapMod, uint8_t keycode); bool process_space_cadet(uint16_t keycode, keyrecord_t *record); -- cgit v1.2.3 From c6184d2e7ed9695c22635431394e501b1d5e6271 Mon Sep 17 00:00:00 2001 From: XScorpion2 Date: Sun, 12 May 2019 00:20:14 -0500 Subject: Added check for event pressed to clear space cadet (#5839) * Added check for pressed to clear space cadet * Found some docs to update * Update docs/quantum_keycodes.md Co-Authored-By: fauxpark * Changes from PR --- quantum/process_keycode/process_space_cadet.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_space_cadet.c b/quantum/process_keycode/process_space_cadet.c index ac39df8089..089199eee2 100644 --- a/quantum/process_keycode/process_space_cadet.c +++ b/quantum/process_keycode/process_space_cadet.c @@ -60,18 +60,18 @@ // Control / paren setup #ifndef LCPO_KEYS - #define LCPO_KEYS KC_LCTL, KC_LCTL, KC_9 + #define LCPO_KEYS KC_LCTL, KC_LSFT, KC_9 #endif #ifndef RCPC_KEYS - #define RCPC_KEYS KC_RCTL, KC_RCTL, KC_0 + #define RCPC_KEYS KC_RCTL, KC_RSFT, KC_0 #endif // Alt / paren setup #ifndef LAPO_KEYS - #define LAPO_KEYS KC_LALT, KC_LALT, KC_9 + #define LAPO_KEYS KC_LALT, KC_LSFT, KC_9 #endif #ifndef RAPC_KEYS - #define RAPC_KEYS KC_RALT, KC_RALT, KC_0 + #define RAPC_KEYS KC_RALT, KC_RSFT, KC_0 #endif // Shift / Enter setup @@ -143,7 +143,9 @@ bool process_space_cadet(uint16_t keycode, keyrecord_t *record) { return false; } default: { - sc_last = 0; + if (record->event.pressed) { + sc_last = 0; + } break; } } -- cgit v1.2.3 From d85110b6ec5fcdf3ef88b41909ce739b017abbea Mon Sep 17 00:00:00 2001 From: Josh Date: Fri, 17 May 2019 16:48:53 -0400 Subject: Adds a configurable initial delay to the audio clicky feature (#4286) * Adding an AUDIO_CLICKY_DELAY_DURATION configurable value to the AUDIO_CLICKY feature. * Tweaking my community keymap to work better with my rev 4 planck. --- quantum/process_keycode/process_clicky.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_clicky.c b/quantum/process_keycode/process_clicky.c index 12fef51f9e..43b803afe7 100644 --- a/quantum/process_keycode/process_clicky.c +++ b/quantum/process_keycode/process_clicky.c @@ -3,6 +3,9 @@ #ifdef AUDIO_CLICKY +#ifndef AUDIO_CLICKY_DELAY_DURATION +#define AUDIO_CLICKY_DELAY_DURATION 1 +#endif // !AUDIO_CLICKY_DELAY_DURATION #ifndef AUDIO_CLICKY_FREQ_DEFAULT #define AUDIO_CLICKY_FREQ_DEFAULT 440.0f #endif // !AUDIO_CLICKY_FREQ_DEFAULT @@ -21,7 +24,9 @@ float clicky_freq = AUDIO_CLICKY_FREQ_DEFAULT; float clicky_rand = AUDIO_CLICKY_FREQ_RANDOMNESS; -float clicky_song[][2] = {{AUDIO_CLICKY_FREQ_DEFAULT, 3}, {AUDIO_CLICKY_FREQ_DEFAULT, 1}}; // 3 and 1 --> durations + +// the first "note" is an intentional delay; the 2nd and 3rd notes are the "clicky" +float clicky_song[][2] = {{AUDIO_CLICKY_FREQ_MIN, AUDIO_CLICKY_DELAY_DURATION}, {AUDIO_CLICKY_FREQ_DEFAULT, 3}, {AUDIO_CLICKY_FREQ_DEFAULT, 1}}; // 3 and 1 --> durations extern audio_config_t audio_config; @@ -34,8 +39,8 @@ void clicky_play(void) { #ifndef NO_MUSIC_MODE if (music_activated || midi_activated || !audio_config.enable) return; #endif // !NO_MUSIC_MODE - clicky_song[0][0] = 2.0f * clicky_freq * (1.0f + clicky_rand * ( ((float)rand()) / ((float)(RAND_MAX)) ) ); - clicky_song[1][0] = clicky_freq * (1.0f + clicky_rand * ( ((float)rand()) / ((float)(RAND_MAX)) ) ); + clicky_song[1][0] = 2.0f * clicky_freq * (1.0f + clicky_rand * ( ((float)rand()) / ((float)(RAND_MAX)) ) ); + clicky_song[2][0] = clicky_freq * (1.0f + clicky_rand * ( ((float)rand()) / ((float)(RAND_MAX)) ) ); PLAY_SONG(clicky_song); } -- cgit v1.2.3 From d16db6936715a98b6ae769463d5ccafab25b7203 Mon Sep 17 00:00:00 2001 From: XScorpion2 Date: Sat, 6 Jul 2019 23:00:05 -0500 Subject: Added mod carry over from press to release. (#5866) Update docs/feature_space_cadet.md Co-Authored-By: fauxpark --- quantum/process_keycode/process_space_cadet.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_space_cadet.c b/quantum/process_keycode/process_space_cadet.c index 089199eee2..c8721d446c 100644 --- a/quantum/process_keycode/process_space_cadet.c +++ b/quantum/process_keycode/process_space_cadet.c @@ -81,11 +81,17 @@ static uint8_t sc_last = 0; static uint16_t sc_timer = 0; +#ifdef SPACE_CADET_MODIFIER_CARRYOVER +static uint8_t sc_mods = 0; +#endif void perform_space_cadet(keyrecord_t *record, uint8_t holdMod, uint8_t tapMod, uint8_t keycode) { if (record->event.pressed) { sc_last = holdMod; sc_timer = timer_read (); +#ifdef SPACE_CADET_MODIFIER_CARRYOVER + sc_mods = get_mods(); +#endif if (IS_MOD(holdMod)) { register_mods(MOD_BIT(holdMod)); } @@ -100,7 +106,13 @@ void perform_space_cadet(keyrecord_t *record, uint8_t holdMod, uint8_t tapMod, u register_mods(MOD_BIT(tapMod)); } } +#ifdef SPACE_CADET_MODIFIER_CARRYOVER + set_weak_mods(sc_mods); +#endif tap_code(keycode); +#ifdef SPACE_CADET_MODIFIER_CARRYOVER + clear_weak_mods(); +#endif if (IS_MOD(tapMod)) { unregister_mods(MOD_BIT(tapMod)); } -- cgit v1.2.3 From 2a231457bd494079c36cf3e07c9b887016adb491 Mon Sep 17 00:00:00 2001 From: Aapo Saaristo Date: Tue, 16 Jul 2019 08:53:04 +0300 Subject: Add user-overridable callback for cancelling UCIS input (#5564) * Add user-overridable callback for cancelling UCIS input To clean up things from qk_ucis_start_user() for instance. * restore lost newline to quantum/process_keycode/process_ucis.c Co-Authored-By: shinmai --- quantum/process_keycode/process_ucis.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_ucis.c b/quantum/process_keycode/process_ucis.c index 5de2e41fc3..fd4508b535 100644 --- a/quantum/process_keycode/process_ucis.c +++ b/quantum/process_keycode/process_ucis.c @@ -64,6 +64,10 @@ void qk_ucis_symbol_fallback (void) { } } +__attribute__((weak)) +void qk_ucis_cancel(void) { +} + void register_ucis(const char *hex) { for(int i = 0; hex[i]; i++) { uint8_t kc = 0; @@ -130,6 +134,7 @@ bool process_ucis (uint16_t keycode, keyrecord_t *record) { if (keycode == KC_ESC) { qk_ucis_state.in_progress = false; + qk_ucis_cancel(); return false; } -- cgit v1.2.3 From 09f5767072b65d98371199ab03981940d132b123 Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Mon, 15 Jul 2019 23:56:34 -0700 Subject: Add out of bound check for Leader Key sequence array (#5840) * Add out of bound check for Leader Key sequence array * A shot at advanced C stuff for Leader Key optimization * Revert most changes * Change default back * Include string.h if compiling for ARM * Use sizeof instead of a number --- quantum/process_keycode/process_leader.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_leader.c b/quantum/process_keycode/process_leader.c index 897e9eabf6..ee8099ca21 100644 --- a/quantum/process_keycode/process_leader.c +++ b/quantum/process_keycode/process_leader.c @@ -17,6 +17,9 @@ #ifdef LEADER_ENABLE #include "process_leader.h" +#ifdef __arm__ +# include +#endif #ifndef LEADER_TIMEOUT #define LEADER_TIMEOUT 300 @@ -41,11 +44,7 @@ void qk_leader_start(void) { leading = true; leader_time = timer_read(); leader_sequence_size = 0; - leader_sequence[0] = 0; - leader_sequence[1] = 0; - leader_sequence[2] = 0; - leader_sequence[3] = 0; - leader_sequence[4] = 0; + memset(leader_sequence, 0, sizeof(leader_sequence)); } bool process_leader(uint16_t keycode, keyrecord_t *record) { @@ -58,8 +57,13 @@ bool process_leader(uint16_t keycode, keyrecord_t *record) { keycode = keycode & 0xFF; } #endif // LEADER_KEY_STRICT_KEY_PROCESSING - leader_sequence[leader_sequence_size] = keycode; - leader_sequence_size++; + if ( leader_sequence_size < ( sizeof(leader_sequence) / sizeof(leader_sequence[0]) ) ) { + leader_sequence[leader_sequence_size] = keycode; + leader_sequence_size++; + } else { + leading = false; + leader_end(); + } #ifdef LEADER_PER_KEY_TIMING leader_time = timer_read(); #endif -- cgit v1.2.3 From c44fc68297029da87233777aff6978d39caebbb1 Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Tue, 16 Jul 2019 01:37:19 -0700 Subject: Allow Combo feature to be enabled/disabled live (#6318) * Add ability to enable/disable combos * Update documentation for Combo feature * Change keycodes for appeasement * Simplify combo_toggle function * Update names * Update combo docs to use tables --- quantum/process_keycode/process_combo.c | 43 ++++++++++++++++++++++++++++++++- quantum/process_keycode/process_combo.h | 5 ++++ 2 files changed, 47 insertions(+), 1 deletion(-) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_combo.c b/quantum/process_keycode/process_combo.c index 2c6c9d0d5f..d3c3b1673c 100644 --- a/quantum/process_keycode/process_combo.c +++ b/quantum/process_keycode/process_combo.c @@ -28,6 +28,7 @@ static uint16_t timer = 0; static uint8_t current_combo_index = 0; static bool drop_buffer = false; static bool is_active = false; +static bool b_combo_enable = true; // defaults to enabled static uint8_t buffer_size = 0; #ifdef COMBO_ALLOW_ACTION_KEYS @@ -128,6 +129,23 @@ bool process_combo(uint16_t keycode, keyrecord_t *record) { drop_buffer = false; bool no_combo_keys_pressed = true; + if (keycode == CMB_ON && record->event.pressed) { + combo_enable(); + return true; + } + + if (keycode == CMB_OFF && record->event.pressed) { + combo_disable(); + return true; + } + + if (keycode == CMB_TOG && record->event.pressed) { + combo_toggle(); + return true; + } + + if (!is_combo_enabled()) { return true; } + for (current_combo_index = 0; current_combo_index < COMBO_COUNT; ++current_combo_index) { combo_t *combo = &key_combos[current_combo_index]; @@ -166,7 +184,7 @@ bool process_combo(uint16_t keycode, keyrecord_t *record) { } void matrix_scan_combo(void) { - if (is_active && timer && timer_elapsed(timer) > COMBO_TERM) { + if (b_combo_enable && is_active && timer && timer_elapsed(timer) > COMBO_TERM) { /* This disables the combo, meaning key events for this * combo will be handled by the next processors in the chain @@ -175,3 +193,26 @@ void matrix_scan_combo(void) { dump_key_buffer(true); } } + +void combo_enable(void) { + b_combo_enable = true; +} + +void combo_disable(void) { + b_combo_enable = is_active = false; + timer = 0; + dump_key_buffer(true); + +} + +void combo_toggle(void) { + if (b_combo_enable) { + combo_disable(); + } else { + combo_enable(); + } +} + +bool is_combo_enabled(void) { + return b_combo_enable; +} diff --git a/quantum/process_keycode/process_combo.h b/quantum/process_keycode/process_combo.h index f06d2d3454..aab2849572 100644 --- a/quantum/process_keycode/process_combo.h +++ b/quantum/process_keycode/process_combo.h @@ -58,4 +58,9 @@ bool process_combo(uint16_t keycode, keyrecord_t *record); void matrix_scan_combo(void); void process_combo_event(uint8_t combo_index, bool pressed); +void combo_enable(void); +void combo_disable(void); +void combo_toggle(void); +bool is_combo_enabled(void); + #endif -- cgit v1.2.3 From e5d2cb8f98fb4dbec3c64e19acfaa4e6db57e257 Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Tue, 16 Jul 2019 09:22:29 -0700 Subject: Fix Preprocessor check for Leader Keys --- quantum/process_keycode/process_leader.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_leader.c b/quantum/process_keycode/process_leader.c index ee8099ca21..f787e6b017 100644 --- a/quantum/process_keycode/process_leader.c +++ b/quantum/process_keycode/process_leader.c @@ -17,9 +17,7 @@ #ifdef LEADER_ENABLE #include "process_leader.h" -#ifdef __arm__ -# include -#endif +#include #ifndef LEADER_TIMEOUT #define LEADER_TIMEOUT 300 -- cgit v1.2.3 From 009d45d4d75310e0c4c4b5678e2e4f0200d0d606 Mon Sep 17 00:00:00 2001 From: Zach DeCook Date: Tue, 6 Aug 2019 14:26:28 -0400 Subject: MIDI: Fix basic noteon: send correct velocity (#6476) --- quantum/process_keycode/process_midi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_midi.c b/quantum/process_keycode/process_midi.c index a67f736285..be6455ee94 100644 --- a/quantum/process_keycode/process_midi.c +++ b/quantum/process_keycode/process_midi.c @@ -24,7 +24,7 @@ void process_midi_basic_noteon(uint8_t note) { - midi_send_noteon(&midi_device, 0, note, 128); + midi_send_noteon(&midi_device, 0, note, 127); } void process_midi_basic_noteoff(uint8_t note) -- cgit v1.2.3 From 406f03bb0ceeaf7fda7d04da2379c1f197b5cc6d Mon Sep 17 00:00:00 2001 From: fauxpark Date: Fri, 9 Aug 2019 07:15:34 +1000 Subject: Mask off TD() parameter properly (#6143) * Mask off TD() parameter properly * More parentheses --- quantum/process_keycode/process_tap_dance.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_tap_dance.h b/quantum/process_keycode/process_tap_dance.h index ca12f4746e..00d70cbc59 100644 --- a/quantum/process_keycode/process_tap_dance.h +++ b/quantum/process_keycode/process_tap_dance.h @@ -34,7 +34,7 @@ typedef struct bool finished; } qk_tap_dance_state_t; -#define TD(n) (QK_TAP_DANCE + n) +#define TD(n) (QK_TAP_DANCE | ((n) & 0xFF)) typedef void (*qk_tap_dance_user_fn_t) (qk_tap_dance_state_t *state, void *user_data); -- cgit v1.2.3 From b624f32f944acdc59dcb130674c09090c5c404cb Mon Sep 17 00:00:00 2001 From: skullY Date: Fri, 30 Aug 2019 11:19:03 -0700 Subject: clang-format changes --- quantum/process_keycode/process_audio.c | 31 +- quantum/process_keycode/process_auto_shift.c | 296 ++++++++------- quantum/process_keycode/process_auto_shift.h | 2 +- quantum/process_keycode/process_clicky.c | 131 +++---- quantum/process_keycode/process_combo.c | 259 +++++++------ quantum/process_keycode/process_combo.h | 28 +- quantum/process_keycode/process_key_lock.c | 48 ++- quantum/process_keycode/process_key_lock.h | 2 +- quantum/process_keycode/process_leader.c | 86 ++--- quantum/process_keycode/process_leader.h | 7 +- quantum/process_keycode/process_midi.c | 115 +++--- quantum/process_keycode/process_midi.h | 30 +- quantum/process_keycode/process_music.c | 354 +++++++++--------- quantum/process_keycode/process_music.h | 28 +- quantum/process_keycode/process_printer.c | 443 +++++++++++------------ quantum/process_keycode/process_printer_bb.c | 435 +++++++++++----------- quantum/process_keycode/process_space_cadet.c | 175 +++++---- quantum/process_keycode/process_steno.c | 208 +++++------ quantum/process_keycode/process_steno.h | 8 +- quantum/process_keycode/process_tap_dance.c | 268 +++++++------- quantum/process_keycode/process_tap_dance.h | 113 +++--- quantum/process_keycode/process_terminal.c | 271 +++++++------- quantum/process_keycode/process_terminal.h | 2 +- quantum/process_keycode/process_ucis.c | 213 ++++++----- quantum/process_keycode/process_ucis.h | 24 +- quantum/process_keycode/process_unicode.c | 12 +- quantum/process_keycode/process_unicode_common.c | 321 ++++++++-------- quantum/process_keycode/process_unicode_common.h | 246 ++++++------- quantum/process_keycode/process_unicodemap.c | 95 ++--- quantum/process_keycode/process_unicodemap.h | 4 +- 30 files changed, 2028 insertions(+), 2227 deletions(-) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_audio.c b/quantum/process_keycode/process_audio.c index 0a25aa5354..3b5fa8490b 100644 --- a/quantum/process_keycode/process_audio.c +++ b/quantum/process_keycode/process_audio.c @@ -2,30 +2,28 @@ #include "process_audio.h" #ifndef VOICE_CHANGE_SONG - #define VOICE_CHANGE_SONG SONG(VOICE_CHANGE_SOUND) +# define VOICE_CHANGE_SONG SONG(VOICE_CHANGE_SOUND) #endif float voice_change_song[][2] = VOICE_CHANGE_SONG; #ifndef PITCH_STANDARD_A - #define PITCH_STANDARD_A 440.0f +# define PITCH_STANDARD_A 440.0f #endif -float compute_freq_for_midi_note(uint8_t note) -{ +float compute_freq_for_midi_note(uint8_t note) { // https://en.wikipedia.org/wiki/MIDI_tuning_standard return pow(2.0, (note - 69) / 12.0) * PITCH_STANDARD_A; } bool process_audio(uint16_t keycode, keyrecord_t *record) { - if (keycode == AU_ON && record->event.pressed) { - audio_on(); - return false; + audio_on(); + return false; } if (keycode == AU_OFF && record->event.pressed) { - audio_off(); - return false; + audio_off(); + return false; } if (keycode == AU_TOG && record->event.pressed) { @@ -52,17 +50,10 @@ bool process_audio(uint16_t keycode, keyrecord_t *record) { return true; } -void process_audio_noteon(uint8_t note) { - play_note(compute_freq_for_midi_note(note), 0xF); -} +void process_audio_noteon(uint8_t note) { play_note(compute_freq_for_midi_note(note), 0xF); } -void process_audio_noteoff(uint8_t note) { - stop_note(compute_freq_for_midi_note(note)); -} +void process_audio_noteoff(uint8_t note) { stop_note(compute_freq_for_midi_note(note)); } -void process_audio_all_notes_off(void) { - stop_all_notes(); -} +void process_audio_all_notes_off(void) { stop_all_notes(); } -__attribute__ ((weak)) -void audio_on_user() {} +__attribute__((weak)) void audio_on_user() {} diff --git a/quantum/process_keycode/process_auto_shift.c b/quantum/process_keycode/process_auto_shift.c index 0d0930ee67..4ae3fe446e 100644 --- a/quantum/process_keycode/process_auto_shift.c +++ b/quantum/process_keycode/process_auto_shift.c @@ -16,195 +16,185 @@ #ifdef AUTO_SHIFT_ENABLE -#include +# include -#include "process_auto_shift.h" +# include "process_auto_shift.h" -#define TAP(key) \ - register_code(key); \ - unregister_code(key) +# define TAP(key) \ + register_code(key); \ + unregister_code(key) -#define TAP_WITH_MOD(mod, key) \ - register_code(mod); \ - register_code(key); \ - unregister_code(key); \ - unregister_code(mod) +# define TAP_WITH_MOD(mod, key) \ + register_code(mod); \ + register_code(key); \ + unregister_code(key); \ + unregister_code(mod) -uint16_t autoshift_time = 0; +uint16_t autoshift_time = 0; uint16_t autoshift_timeout = AUTO_SHIFT_TIMEOUT; uint16_t autoshift_lastkey = KC_NO; void autoshift_timer_report(void) { - char display[8]; + char display[8]; - snprintf(display, 8, "\n%d\n", autoshift_timeout); + snprintf(display, 8, "\n%d\n", autoshift_timeout); - send_string((const char *)display); + send_string((const char *)display); } void autoshift_on(uint16_t keycode) { - autoshift_time = timer_read(); - autoshift_lastkey = keycode; + autoshift_time = timer_read(); + autoshift_lastkey = keycode; } void autoshift_flush(void) { - if (autoshift_lastkey != KC_NO) { - uint16_t elapsed = timer_elapsed(autoshift_time); + if (autoshift_lastkey != KC_NO) { + uint16_t elapsed = timer_elapsed(autoshift_time); - if (elapsed > autoshift_timeout) { - register_code(KC_LSFT); - } + if (elapsed > autoshift_timeout) { + register_code(KC_LSFT); + } - register_code(autoshift_lastkey); - unregister_code(autoshift_lastkey); + register_code(autoshift_lastkey); + unregister_code(autoshift_lastkey); - if (elapsed > autoshift_timeout) { - unregister_code(KC_LSFT); - } + if (elapsed > autoshift_timeout) { + unregister_code(KC_LSFT); + } - autoshift_time = 0; - autoshift_lastkey = KC_NO; - } + autoshift_time = 0; + autoshift_lastkey = KC_NO; + } } bool autoshift_enabled = true; -void autoshift_enable(void) { - autoshift_enabled = true; -} +void autoshift_enable(void) { autoshift_enabled = true; } void autoshift_disable(void) { - autoshift_enabled = false; - autoshift_flush(); -} - -void autoshift_toggle(void) { - if (autoshift_enabled) { autoshift_enabled = false; autoshift_flush(); - } - else { - autoshift_enabled = true; - } } -bool autoshift_state(void) { - return autoshift_enabled; +void autoshift_toggle(void) { + if (autoshift_enabled) { + autoshift_enabled = false; + autoshift_flush(); + } else { + autoshift_enabled = true; + } } -bool process_auto_shift(uint16_t keycode, keyrecord_t *record) { -#ifndef AUTO_SHIFT_MODIFIERS - static uint8_t any_mod_pressed; -#endif - - if (record->event.pressed) { - switch (keycode) { - case KC_ASUP: - autoshift_timeout += 5; - return false; - - case KC_ASDN: - autoshift_timeout -= 5; - return false; - - case KC_ASRP: - autoshift_timer_report(); - return false; - - case KC_ASTG: - autoshift_toggle(); - return false; - case KC_ASON: - autoshift_enable(); - return false; - case KC_ASOFF: - autoshift_disable(); - return false; - -#ifndef NO_AUTO_SHIFT_ALPHA - case KC_A: - case KC_B: - case KC_C: - case KC_D: - case KC_E: - case KC_F: - case KC_G: - case KC_H: - case KC_I: - case KC_J: - case KC_K: - case KC_L: - case KC_M: - case KC_N: - case KC_O: - case KC_P: - case KC_Q: - case KC_R: - case KC_S: - case KC_T: - case KC_U: - case KC_V: - case KC_W: - case KC_X: - case KC_Y: - case KC_Z: -#endif -#ifndef NO_AUTO_SHIFT_NUMERIC - case KC_1: - case KC_2: - case KC_3: - case KC_4: - case KC_5: - case KC_6: - case KC_7: - case KC_8: - case KC_9: - case KC_0: -#endif -#ifndef NO_AUTO_SHIFT_SPECIAL - case KC_MINUS: - case KC_EQL: - case KC_TAB: - case KC_LBRC: - case KC_RBRC: - case KC_BSLS: - case KC_SCLN: - case KC_QUOT: - case KC_COMM: - case KC_DOT: - case KC_SLSH: - case KC_GRAVE: - case KC_NONUS_BSLASH: - case KC_NONUS_HASH: -#endif +bool autoshift_state(void) { return autoshift_enabled; } - autoshift_flush(); - if (!autoshift_enabled) return true; - -#ifndef AUTO_SHIFT_MODIFIERS - any_mod_pressed = get_mods() & ( - MOD_BIT(KC_LGUI)|MOD_BIT(KC_RGUI)| - MOD_BIT(KC_LALT)|MOD_BIT(KC_RALT)| - MOD_BIT(KC_LCTL)|MOD_BIT(KC_RCTL)| - MOD_BIT(KC_LSFT)|MOD_BIT(KC_RSFT) - ); - - if (any_mod_pressed) { - return true; +bool process_auto_shift(uint16_t keycode, keyrecord_t *record) { +# ifndef AUTO_SHIFT_MODIFIERS + static uint8_t any_mod_pressed; +# endif + + if (record->event.pressed) { + switch (keycode) { + case KC_ASUP: + autoshift_timeout += 5; + return false; + + case KC_ASDN: + autoshift_timeout -= 5; + return false; + + case KC_ASRP: + autoshift_timer_report(); + return false; + + case KC_ASTG: + autoshift_toggle(); + return false; + case KC_ASON: + autoshift_enable(); + return false; + case KC_ASOFF: + autoshift_disable(); + return false; + +# ifndef NO_AUTO_SHIFT_ALPHA + case KC_A: + case KC_B: + case KC_C: + case KC_D: + case KC_E: + case KC_F: + case KC_G: + case KC_H: + case KC_I: + case KC_J: + case KC_K: + case KC_L: + case KC_M: + case KC_N: + case KC_O: + case KC_P: + case KC_Q: + case KC_R: + case KC_S: + case KC_T: + case KC_U: + case KC_V: + case KC_W: + case KC_X: + case KC_Y: + case KC_Z: +# endif +# ifndef NO_AUTO_SHIFT_NUMERIC + case KC_1: + case KC_2: + case KC_3: + case KC_4: + case KC_5: + case KC_6: + case KC_7: + case KC_8: + case KC_9: + case KC_0: +# endif +# ifndef NO_AUTO_SHIFT_SPECIAL + case KC_MINUS: + case KC_EQL: + case KC_TAB: + case KC_LBRC: + case KC_RBRC: + case KC_BSLS: + case KC_SCLN: + case KC_QUOT: + case KC_COMM: + case KC_DOT: + case KC_SLSH: + case KC_GRAVE: + case KC_NONUS_BSLASH: + case KC_NONUS_HASH: +# endif + + autoshift_flush(); + if (!autoshift_enabled) return true; + +# ifndef AUTO_SHIFT_MODIFIERS + any_mod_pressed = get_mods() & (MOD_BIT(KC_LGUI) | MOD_BIT(KC_RGUI) | MOD_BIT(KC_LALT) | MOD_BIT(KC_RALT) | MOD_BIT(KC_LCTL) | MOD_BIT(KC_RCTL) | MOD_BIT(KC_LSFT) | MOD_BIT(KC_RSFT)); + + if (any_mod_pressed) { + return true; + } +# endif + + autoshift_on(keycode); + return false; + + default: + autoshift_flush(); + return true; } -#endif - - autoshift_on(keycode); - return false; - - default: + } else { autoshift_flush(); - return true; } - } else { - autoshift_flush(); - } - return true; + return true; } #endif diff --git a/quantum/process_keycode/process_auto_shift.h b/quantum/process_keycode/process_auto_shift.h index a4abf04145..083325d8e3 100644 --- a/quantum/process_keycode/process_auto_shift.h +++ b/quantum/process_keycode/process_auto_shift.h @@ -20,7 +20,7 @@ #include "quantum.h" #ifndef AUTO_SHIFT_TIMEOUT - #define AUTO_SHIFT_TIMEOUT 175 +# define AUTO_SHIFT_TIMEOUT 175 #endif bool process_auto_shift(uint16_t keycode, keyrecord_t *record); diff --git a/quantum/process_keycode/process_clicky.c b/quantum/process_keycode/process_clicky.c index 43b803afe7..6ab382d4aa 100644 --- a/quantum/process_keycode/process_clicky.c +++ b/quantum/process_keycode/process_clicky.c @@ -3,104 +3,111 @@ #ifdef AUDIO_CLICKY -#ifndef AUDIO_CLICKY_DELAY_DURATION -#define AUDIO_CLICKY_DELAY_DURATION 1 -#endif // !AUDIO_CLICKY_DELAY_DURATION -#ifndef AUDIO_CLICKY_FREQ_DEFAULT -#define AUDIO_CLICKY_FREQ_DEFAULT 440.0f -#endif // !AUDIO_CLICKY_FREQ_DEFAULT -#ifndef AUDIO_CLICKY_FREQ_MIN -#define AUDIO_CLICKY_FREQ_MIN 65.0f -#endif // !AUDIO_CLICKY_FREQ_MIN -#ifndef AUDIO_CLICKY_FREQ_MAX -#define AUDIO_CLICKY_FREQ_MAX 1500.0f -#endif // !AUDIO_CLICKY_FREQ_MAX -#ifndef AUDIO_CLICKY_FREQ_FACTOR -#define AUDIO_CLICKY_FREQ_FACTOR 1.18921f -#endif // !AUDIO_CLICKY_FREQ_FACTOR -#ifndef AUDIO_CLICKY_FREQ_RANDOMNESS -#define AUDIO_CLICKY_FREQ_RANDOMNESS 0.05f -#endif // !AUDIO_CLICKY_FREQ_RANDOMNESS +# ifndef AUDIO_CLICKY_DELAY_DURATION +# define AUDIO_CLICKY_DELAY_DURATION 1 +# endif // !AUDIO_CLICKY_DELAY_DURATION +# ifndef AUDIO_CLICKY_FREQ_DEFAULT +# define AUDIO_CLICKY_FREQ_DEFAULT 440.0f +# endif // !AUDIO_CLICKY_FREQ_DEFAULT +# ifndef AUDIO_CLICKY_FREQ_MIN +# define AUDIO_CLICKY_FREQ_MIN 65.0f +# endif // !AUDIO_CLICKY_FREQ_MIN +# ifndef AUDIO_CLICKY_FREQ_MAX +# define AUDIO_CLICKY_FREQ_MAX 1500.0f +# endif // !AUDIO_CLICKY_FREQ_MAX +# ifndef AUDIO_CLICKY_FREQ_FACTOR +# define AUDIO_CLICKY_FREQ_FACTOR 1.18921f +# endif // !AUDIO_CLICKY_FREQ_FACTOR +# ifndef AUDIO_CLICKY_FREQ_RANDOMNESS +# define AUDIO_CLICKY_FREQ_RANDOMNESS 0.05f +# endif // !AUDIO_CLICKY_FREQ_RANDOMNESS float clicky_freq = AUDIO_CLICKY_FREQ_DEFAULT; float clicky_rand = AUDIO_CLICKY_FREQ_RANDOMNESS; // the first "note" is an intentional delay; the 2nd and 3rd notes are the "clicky" -float clicky_song[][2] = {{AUDIO_CLICKY_FREQ_MIN, AUDIO_CLICKY_DELAY_DURATION}, {AUDIO_CLICKY_FREQ_DEFAULT, 3}, {AUDIO_CLICKY_FREQ_DEFAULT, 1}}; // 3 and 1 --> durations +float clicky_song[][2] = {{AUDIO_CLICKY_FREQ_MIN, AUDIO_CLICKY_DELAY_DURATION}, {AUDIO_CLICKY_FREQ_DEFAULT, 3}, {AUDIO_CLICKY_FREQ_DEFAULT, 1}}; // 3 and 1 --> durations extern audio_config_t audio_config; -#ifndef NO_MUSIC_MODE +# ifndef NO_MUSIC_MODE extern bool music_activated; extern bool midi_activated; -#endif // !NO_MUSIC_MODE +# endif // !NO_MUSIC_MODE void clicky_play(void) { -#ifndef NO_MUSIC_MODE - if (music_activated || midi_activated || !audio_config.enable) return; -#endif // !NO_MUSIC_MODE - clicky_song[1][0] = 2.0f * clicky_freq * (1.0f + clicky_rand * ( ((float)rand()) / ((float)(RAND_MAX)) ) ); - clicky_song[2][0] = clicky_freq * (1.0f + clicky_rand * ( ((float)rand()) / ((float)(RAND_MAX)) ) ); - PLAY_SONG(clicky_song); +# ifndef NO_MUSIC_MODE + if (music_activated || midi_activated || !audio_config.enable) return; +# endif // !NO_MUSIC_MODE + clicky_song[1][0] = 2.0f * clicky_freq * (1.0f + clicky_rand * (((float)rand()) / ((float)(RAND_MAX)))); + clicky_song[2][0] = clicky_freq * (1.0f + clicky_rand * (((float)rand()) / ((float)(RAND_MAX)))); + PLAY_SONG(clicky_song); } void clicky_freq_up(void) { - float new_freq = clicky_freq * AUDIO_CLICKY_FREQ_FACTOR; - if (new_freq < AUDIO_CLICKY_FREQ_MAX) { - clicky_freq = new_freq; - } + float new_freq = clicky_freq * AUDIO_CLICKY_FREQ_FACTOR; + if (new_freq < AUDIO_CLICKY_FREQ_MAX) { + clicky_freq = new_freq; + } } void clicky_freq_down(void) { - float new_freq = clicky_freq / AUDIO_CLICKY_FREQ_FACTOR; - if (new_freq > AUDIO_CLICKY_FREQ_MIN) { - clicky_freq = new_freq; - } + float new_freq = clicky_freq / AUDIO_CLICKY_FREQ_FACTOR; + if (new_freq > AUDIO_CLICKY_FREQ_MIN) { + clicky_freq = new_freq; + } } -void clicky_freq_reset(void) { - clicky_freq = AUDIO_CLICKY_FREQ_DEFAULT; -} +void clicky_freq_reset(void) { clicky_freq = AUDIO_CLICKY_FREQ_DEFAULT; } void clicky_toggle(void) { - audio_config.clicky_enable ^= 1; - eeconfig_update_audio(audio_config.raw); + audio_config.clicky_enable ^= 1; + eeconfig_update_audio(audio_config.raw); } void clicky_on(void) { - audio_config.clicky_enable = 1; - eeconfig_update_audio(audio_config.raw); + audio_config.clicky_enable = 1; + eeconfig_update_audio(audio_config.raw); } void clicky_off(void) { - audio_config.clicky_enable = 0; - eeconfig_update_audio(audio_config.raw); + audio_config.clicky_enable = 0; + eeconfig_update_audio(audio_config.raw); } -bool is_clicky_on(void) { - return (audio_config.clicky_enable != 0); -} +bool is_clicky_on(void) { return (audio_config.clicky_enable != 0); } bool process_clicky(uint16_t keycode, keyrecord_t *record) { - if (keycode == CLICKY_TOGGLE && record->event.pressed) { clicky_toggle(); } - - if (keycode == CLICKY_ENABLE && record->event.pressed) { clicky_on(); } - if (keycode == CLICKY_DISABLE && record->event.pressed) { clicky_off(); } + if (keycode == CLICKY_TOGGLE && record->event.pressed) { + clicky_toggle(); + } - if (keycode == CLICKY_RESET && record->event.pressed) { clicky_freq_reset(); } + if (keycode == CLICKY_ENABLE && record->event.pressed) { + clicky_on(); + } + if (keycode == CLICKY_DISABLE && record->event.pressed) { + clicky_off(); + } - if (keycode == CLICKY_UP && record->event.pressed) { clicky_freq_up(); } - if (keycode == CLICKY_DOWN && record->event.pressed) { clicky_freq_down(); } + if (keycode == CLICKY_RESET && record->event.pressed) { + clicky_freq_reset(); + } + if (keycode == CLICKY_UP && record->event.pressed) { + clicky_freq_up(); + } + if (keycode == CLICKY_DOWN && record->event.pressed) { + clicky_freq_down(); + } - if (audio_config.enable && audio_config.clicky_enable) { - if (record->event.pressed) { // Leave this separate so it's easier to add upstroke sound - if (keycode != AU_OFF && keycode != AU_TOG) { // DO NOT PLAY if audio will be disabled, and causes issuse on ARM - clicky_play(); - } + if (audio_config.enable && audio_config.clicky_enable) { + if (record->event.pressed) { // Leave this separate so it's easier to add upstroke sound + if (keycode != AU_OFF && keycode != AU_TOG) { // DO NOT PLAY if audio will be disabled, and causes issuse on ARM + clicky_play(); + } + } } - } - return true; + return true; } -#endif //AUDIO_CLICKY +#endif // AUDIO_CLICKY diff --git a/quantum/process_keycode/process_combo.c b/quantum/process_keycode/process_combo.c index d3c3b1673c..f40ca74525 100644 --- a/quantum/process_keycode/process_combo.c +++ b/quantum/process_keycode/process_combo.c @@ -21,14 +21,13 @@ __attribute__((weak)) combo_t key_combos[COMBO_COUNT] = { }; -__attribute__((weak)) void process_combo_event(uint8_t combo_index, - bool pressed) {} +__attribute__((weak)) void process_combo_event(uint8_t combo_index, bool pressed) {} -static uint16_t timer = 0; -static uint8_t current_combo_index = 0; -static bool drop_buffer = false; -static bool is_active = false; -static bool b_combo_enable = true; // defaults to enabled +static uint16_t timer = 0; +static uint8_t current_combo_index = 0; +static bool drop_buffer = false; +static bool is_active = false; +static bool b_combo_enable = true; // defaults to enabled static uint8_t buffer_size = 0; #ifdef COMBO_ALLOW_ACTION_KEYS @@ -38,171 +37,163 @@ static uint16_t key_buffer[MAX_COMBO_LENGTH]; #endif static inline void send_combo(uint16_t action, bool pressed) { - if (action) { - if (pressed) { - register_code16(action); + if (action) { + if (pressed) { + register_code16(action); + } else { + unregister_code16(action); + } } else { - unregister_code16(action); + process_combo_event(current_combo_index, pressed); } - } else { - process_combo_event(current_combo_index, pressed); - } } static inline void dump_key_buffer(bool emit) { - if (buffer_size == 0) { - return; - } + if (buffer_size == 0) { + return; + } - if (emit) { - for (uint8_t i = 0; i < buffer_size; i++) { + if (emit) { + for (uint8_t i = 0; i < buffer_size; i++) { #ifdef COMBO_ALLOW_ACTION_KEYS - const action_t action = store_or_get_action(key_buffer[i].event.pressed, - key_buffer[i].event.key); - process_action(&(key_buffer[i]), action); + const action_t action = store_or_get_action(key_buffer[i].event.pressed, key_buffer[i].event.key); + process_action(&(key_buffer[i]), action); #else - register_code16(key_buffer[i]); - send_keyboard_report(); + register_code16(key_buffer[i]); + send_keyboard_report(); #endif + } } - } - buffer_size = 0; + buffer_size = 0; } #define ALL_COMBO_KEYS_ARE_DOWN (((1 << count) - 1) == combo->state) -#define KEY_STATE_DOWN(key) \ - do { \ - combo->state |= (1 << key); \ - } while (0) -#define KEY_STATE_UP(key) \ - do { \ - combo->state &= ~(1 << key); \ - } while (0) - -static bool process_single_combo(combo_t *combo, uint16_t keycode, - keyrecord_t *record) { - uint8_t count = 0; - uint8_t index = -1; - /* Find index of keycode and number of combo keys */ - for (const uint16_t *keys = combo->keys;; ++count) { - uint16_t key = pgm_read_word(&keys[count]); - if (keycode == key) - index = count; - if (COMBO_END == key) - break; - } - - /* Continue processing if not a combo key */ - if (-1 == (int8_t)index) - return false; - - bool is_combo_active = is_active; - - if (record->event.pressed) { - KEY_STATE_DOWN(index); - - if (is_combo_active) { - if (ALL_COMBO_KEYS_ARE_DOWN) { /* Combo was pressed */ - send_combo(combo->keycode, true); - drop_buffer = true; - } +#define KEY_STATE_DOWN(key) \ + do { \ + combo->state |= (1 << key); \ + } while (0) +#define KEY_STATE_UP(key) \ + do { \ + combo->state &= ~(1 << key); \ + } while (0) + +static bool process_single_combo(combo_t *combo, uint16_t keycode, keyrecord_t *record) { + uint8_t count = 0; + uint8_t index = -1; + /* Find index of keycode and number of combo keys */ + for (const uint16_t *keys = combo->keys;; ++count) { + uint16_t key = pgm_read_word(&keys[count]); + if (keycode == key) index = count; + if (COMBO_END == key) break; } - } else { - if (ALL_COMBO_KEYS_ARE_DOWN) { /* Combo was released */ - send_combo(combo->keycode, false); + + /* Continue processing if not a combo key */ + if (-1 == (int8_t)index) return false; + + bool is_combo_active = is_active; + + if (record->event.pressed) { + KEY_STATE_DOWN(index); + + if (is_combo_active) { + if (ALL_COMBO_KEYS_ARE_DOWN) { /* Combo was pressed */ + send_combo(combo->keycode, true); + drop_buffer = true; + } + } } else { - /* continue processing without immediately returning */ - is_combo_active = false; + if (ALL_COMBO_KEYS_ARE_DOWN) { /* Combo was released */ + send_combo(combo->keycode, false); + } else { + /* continue processing without immediately returning */ + is_combo_active = false; + } + + KEY_STATE_UP(index); } - KEY_STATE_UP(index); - } - - return is_combo_active; + return is_combo_active; } #define NO_COMBO_KEYS_ARE_DOWN (0 == combo->state) bool process_combo(uint16_t keycode, keyrecord_t *record) { - bool is_combo_key = false; - drop_buffer = false; - bool no_combo_keys_pressed = true; - - if (keycode == CMB_ON && record->event.pressed) { - combo_enable(); - return true; - } - - if (keycode == CMB_OFF && record->event.pressed) { - combo_disable(); - return true; - } - - if (keycode == CMB_TOG && record->event.pressed) { - combo_toggle(); - return true; - } - - if (!is_combo_enabled()) { return true; } - - for (current_combo_index = 0; current_combo_index < COMBO_COUNT; - ++current_combo_index) { - combo_t *combo = &key_combos[current_combo_index]; - is_combo_key |= process_single_combo(combo, keycode, record); - no_combo_keys_pressed = no_combo_keys_pressed && NO_COMBO_KEYS_ARE_DOWN; - } - - if (drop_buffer) { - /* buffer is only dropped when we complete a combo, so we refresh the timer - * here */ - timer = timer_read(); - dump_key_buffer(false); - } else if (!is_combo_key) { - /* if no combos claim the key we need to emit the keybuffer */ - dump_key_buffer(true); + bool is_combo_key = false; + drop_buffer = false; + bool no_combo_keys_pressed = true; + + if (keycode == CMB_ON && record->event.pressed) { + combo_enable(); + return true; + } - // reset state if there are no combo keys pressed at all - if (no_combo_keys_pressed) { - timer = 0; - is_active = true; + if (keycode == CMB_OFF && record->event.pressed) { + combo_disable(); + return true; } - } else if (record->event.pressed && is_active) { - /* otherwise the key is consumed and placed in the buffer */ - timer = timer_read(); - if (buffer_size < MAX_COMBO_LENGTH) { + if (keycode == CMB_TOG && record->event.pressed) { + combo_toggle(); + return true; + } + + if (!is_combo_enabled()) { + return true; + } + + for (current_combo_index = 0; current_combo_index < COMBO_COUNT; ++current_combo_index) { + combo_t *combo = &key_combos[current_combo_index]; + is_combo_key |= process_single_combo(combo, keycode, record); + no_combo_keys_pressed = no_combo_keys_pressed && NO_COMBO_KEYS_ARE_DOWN; + } + + if (drop_buffer) { + /* buffer is only dropped when we complete a combo, so we refresh the timer + * here */ + timer = timer_read(); + dump_key_buffer(false); + } else if (!is_combo_key) { + /* if no combos claim the key we need to emit the keybuffer */ + dump_key_buffer(true); + + // reset state if there are no combo keys pressed at all + if (no_combo_keys_pressed) { + timer = 0; + is_active = true; + } + } else if (record->event.pressed && is_active) { + /* otherwise the key is consumed and placed in the buffer */ + timer = timer_read(); + + if (buffer_size < MAX_COMBO_LENGTH) { #ifdef COMBO_ALLOW_ACTION_KEYS - key_buffer[buffer_size++] = *record; + key_buffer[buffer_size++] = *record; #else - key_buffer[buffer_size++] = keycode; + key_buffer[buffer_size++] = keycode; #endif + } } - } - return !is_combo_key; + return !is_combo_key; } void matrix_scan_combo(void) { - if (b_combo_enable && is_active && timer && timer_elapsed(timer) > COMBO_TERM) { - - /* This disables the combo, meaning key events for this - * combo will be handled by the next processors in the chain - */ - is_active = false; - dump_key_buffer(true); - } + if (b_combo_enable && is_active && timer && timer_elapsed(timer) > COMBO_TERM) { + /* This disables the combo, meaning key events for this + * combo will be handled by the next processors in the chain + */ + is_active = false; + dump_key_buffer(true); + } } -void combo_enable(void) { - b_combo_enable = true; -} +void combo_enable(void) { b_combo_enable = true; } void combo_disable(void) { b_combo_enable = is_active = false; - timer = 0; + timer = 0; dump_key_buffer(true); - } void combo_toggle(void) { @@ -213,6 +204,4 @@ void combo_toggle(void) { } } -bool is_combo_enabled(void) { - return b_combo_enable; -} +bool is_combo_enabled(void) { return b_combo_enable; } diff --git a/quantum/process_keycode/process_combo.h b/quantum/process_keycode/process_combo.h index aab2849572..e21ee19609 100644 --- a/quantum/process_keycode/process_combo.h +++ b/quantum/process_keycode/process_combo.h @@ -22,36 +22,36 @@ #include #ifdef EXTRA_EXTRA_LONG_COMBOS -#define MAX_COMBO_LENGTH 32 +# define MAX_COMBO_LENGTH 32 #elif EXTRA_LONG_COMBOS -#define MAX_COMBO_LENGTH 16 +# define MAX_COMBO_LENGTH 16 #else -#define MAX_COMBO_LENGTH 8 +# define MAX_COMBO_LENGTH 8 #endif typedef struct { - const uint16_t *keys; - uint16_t keycode; + const uint16_t *keys; + uint16_t keycode; #ifdef EXTRA_EXTRA_LONG_COMBOS - uint32_t state; + uint32_t state; #elif EXTRA_LONG_COMBOS - uint16_t state; + uint16_t state; #else - uint8_t state; + uint8_t state; #endif } combo_t; -#define COMBO(ck, ca) \ - { .keys = &(ck)[0], .keycode = (ca) } -#define COMBO_ACTION(ck) \ - { .keys = &(ck)[0] } +#define COMBO(ck, ca) \ + { .keys = &(ck)[0], .keycode = (ca) } +#define COMBO_ACTION(ck) \ + { .keys = &(ck)[0] } #define COMBO_END 0 #ifndef COMBO_COUNT -#define COMBO_COUNT 0 +# define COMBO_COUNT 0 #endif #ifndef COMBO_TERM -#define COMBO_TERM TAPPING_TERM +# define COMBO_TERM TAPPING_TERM #endif bool process_combo(uint16_t keycode, keyrecord_t *record); diff --git a/quantum/process_keycode/process_key_lock.c b/quantum/process_keycode/process_key_lock.c index 50cc0a5ccb..602127a74b 100644 --- a/quantum/process_keycode/process_key_lock.c +++ b/quantum/process_keycode/process_key_lock.c @@ -19,36 +19,33 @@ #include "process_key_lock.h" #define BV_64(shift) (((uint64_t)1) << (shift)) -#define GET_KEY_ARRAY(code) (((code) < 0x40) ? key_state[0] : \ - ((code) < 0x80) ? key_state[1] : \ - ((code) < 0xC0) ? key_state[2] : key_state[3]) -#define GET_CODE_INDEX(code) (((code) < 0x40) ? (code) : \ - ((code) < 0x80) ? (code) - 0x40 : \ - ((code) < 0xC0) ? (code) - 0x80 : (code) - 0xC0) -#define KEY_STATE(code) (GET_KEY_ARRAY(code) & BV_64(GET_CODE_INDEX(code))) == BV_64(GET_CODE_INDEX(code)) -#define SET_KEY_ARRAY_STATE(code, val) do { \ - switch (code) { \ - case 0x00 ... 0x3F: \ - key_state[0] = (val); \ - break; \ - case 0x40 ... 0x7F: \ - key_state[1] = (val); \ - break; \ - case 0x80 ... 0xBF: \ - key_state[2] = (val); \ - break; \ - case 0xC0 ... 0xFF: \ - key_state[3] = (val); \ - break; \ - } \ -} while(0) +#define GET_KEY_ARRAY(code) (((code) < 0x40) ? key_state[0] : ((code) < 0x80) ? key_state[1] : ((code) < 0xC0) ? key_state[2] : key_state[3]) +#define GET_CODE_INDEX(code) (((code) < 0x40) ? (code) : ((code) < 0x80) ? (code)-0x40 : ((code) < 0xC0) ? (code)-0x80 : (code)-0xC0) +#define KEY_STATE(code) (GET_KEY_ARRAY(code) & BV_64(GET_CODE_INDEX(code))) == BV_64(GET_CODE_INDEX(code)) +#define SET_KEY_ARRAY_STATE(code, val) \ + do { \ + switch (code) { \ + case 0x00 ... 0x3F: \ + key_state[0] = (val); \ + break; \ + case 0x40 ... 0x7F: \ + key_state[1] = (val); \ + break; \ + case 0x80 ... 0xBF: \ + key_state[2] = (val); \ + break; \ + case 0xC0 ... 0xFF: \ + key_state[3] = (val); \ + break; \ + } \ + } while (0) #define SET_KEY_STATE(code) SET_KEY_ARRAY_STATE(code, (GET_KEY_ARRAY(code) | BV_64(GET_CODE_INDEX(code)))) #define UNSET_KEY_STATE(code) SET_KEY_ARRAY_STATE(code, (GET_KEY_ARRAY(code)) & ~(BV_64(GET_CODE_INDEX(code)))) #define IS_STANDARD_KEYCODE(code) ((code) <= 0xFF) // Locked key state. This is an array of 256 bits, one for each of the standard keys supported qmk. -uint64_t key_state[4] = { 0x0, 0x0, 0x0, 0x0 }; -bool watching = false; +uint64_t key_state[4] = {0x0, 0x0, 0x0, 0x0}; +bool watching = false; // Translate any OSM keycodes back to their unmasked versions. static inline uint16_t translate_keycode(uint16_t keycode) { @@ -135,4 +132,3 @@ bool process_key_lock(uint16_t *keycode, keyrecord_t *record) { return !(IS_STANDARD_KEYCODE(translated_keycode) && KEY_STATE(translated_keycode)); } } - diff --git a/quantum/process_keycode/process_key_lock.h b/quantum/process_keycode/process_key_lock.h index 876db4a324..a8e110a4bf 100644 --- a/quantum/process_keycode/process_key_lock.h +++ b/quantum/process_keycode/process_key_lock.h @@ -21,4 +21,4 @@ bool process_key_lock(uint16_t *keycode, keyrecord_t *record); -#endif // PROCESS_KEY_LOCK_H +#endif // PROCESS_KEY_LOCK_H diff --git a/quantum/process_keycode/process_leader.c b/quantum/process_keycode/process_leader.c index f787e6b017..58a615d85a 100644 --- a/quantum/process_keycode/process_leader.c +++ b/quantum/process_keycode/process_leader.c @@ -16,64 +16,64 @@ #ifdef LEADER_ENABLE -#include "process_leader.h" -#include +# include "process_leader.h" +# include -#ifndef LEADER_TIMEOUT - #define LEADER_TIMEOUT 300 -#endif +# ifndef LEADER_TIMEOUT +# define LEADER_TIMEOUT 300 +# endif -__attribute__ ((weak)) -void leader_start(void) {} +__attribute__((weak)) void leader_start(void) {} -__attribute__ ((weak)) -void leader_end(void) {} +__attribute__((weak)) void leader_end(void) {} // Leader key stuff -bool leading = false; +bool leading = false; uint16_t leader_time = 0; -uint16_t leader_sequence[5] = {0, 0, 0, 0, 0}; -uint8_t leader_sequence_size = 0; +uint16_t leader_sequence[5] = {0, 0, 0, 0, 0}; +uint8_t leader_sequence_size = 0; void qk_leader_start(void) { - if (leading) { return; } - leader_start(); - leading = true; - leader_time = timer_read(); - leader_sequence_size = 0; - memset(leader_sequence, 0, sizeof(leader_sequence)); + if (leading) { + return; + } + leader_start(); + leading = true; + leader_time = timer_read(); + leader_sequence_size = 0; + memset(leader_sequence, 0, sizeof(leader_sequence)); } bool process_leader(uint16_t keycode, keyrecord_t *record) { - // Leader key set-up - if (record->event.pressed) { - if (leading) { - if (timer_elapsed(leader_time) < LEADER_TIMEOUT) { -#ifndef LEADER_KEY_STRICT_KEY_PROCESSING - if ((keycode >= QK_MOD_TAP && keycode <= QK_MOD_TAP_MAX) || (keycode >= QK_LAYER_TAP && keycode <= QK_LAYER_TAP_MAX)) { - keycode = keycode & 0xFF; - } -#endif // LEADER_KEY_STRICT_KEY_PROCESSING - if ( leader_sequence_size < ( sizeof(leader_sequence) / sizeof(leader_sequence[0]) ) ) { - leader_sequence[leader_sequence_size] = keycode; - leader_sequence_size++; + // Leader key set-up + if (record->event.pressed) { + if (leading) { + if (timer_elapsed(leader_time) < LEADER_TIMEOUT) { +# ifndef LEADER_KEY_STRICT_KEY_PROCESSING + if ((keycode >= QK_MOD_TAP && keycode <= QK_MOD_TAP_MAX) || (keycode >= QK_LAYER_TAP && keycode <= QK_LAYER_TAP_MAX)) { + keycode = keycode & 0xFF; + } +# endif // LEADER_KEY_STRICT_KEY_PROCESSING + if (leader_sequence_size < (sizeof(leader_sequence) / sizeof(leader_sequence[0]))) { + leader_sequence[leader_sequence_size] = keycode; + leader_sequence_size++; + } else { + leading = false; + leader_end(); + } +# ifdef LEADER_PER_KEY_TIMING + leader_time = timer_read(); +# endif + return false; + } } else { - leading = false; - leader_end(); + if (keycode == KC_LEAD) { + qk_leader_start(); + } } -#ifdef LEADER_PER_KEY_TIMING - leader_time = timer_read(); -#endif - return false; - } - } else { - if (keycode == KC_LEAD) { - qk_leader_start(); - } } - } - return true; + return true; } #endif diff --git a/quantum/process_keycode/process_leader.h b/quantum/process_keycode/process_leader.h index 15bccc3f67..e0edf57b32 100644 --- a/quantum/process_keycode/process_leader.h +++ b/quantum/process_keycode/process_leader.h @@ -19,7 +19,6 @@ #include "quantum.h" - bool process_leader(uint16_t keycode, keyrecord_t *record); void leader_start(void); @@ -32,7 +31,11 @@ void qk_leader_start(void); #define SEQ_FOUR_KEYS(key1, key2, key3, key4) if (leader_sequence[0] == (key1) && leader_sequence[1] == (key2) && leader_sequence[2] == (key3) && leader_sequence[3] == (key4) && leader_sequence[4] == 0) #define SEQ_FIVE_KEYS(key1, key2, key3, key4, key5) if (leader_sequence[0] == (key1) && leader_sequence[1] == (key2) && leader_sequence[2] == (key3) && leader_sequence[3] == (key4) && leader_sequence[4] == (key5)) -#define LEADER_EXTERNS() extern bool leading; extern uint16_t leader_time; extern uint16_t leader_sequence[5]; extern uint8_t leader_sequence_size +#define LEADER_EXTERNS() \ + extern bool leading; \ + extern uint16_t leader_time; \ + extern uint16_t leader_sequence[5]; \ + extern uint8_t leader_sequence_size #define LEADER_DICTIONARY() if (leading && timer_elapsed(leader_time) > LEADER_TIMEOUT) #endif diff --git a/quantum/process_keycode/process_midi.c b/quantum/process_keycode/process_midi.c index be6455ee94..b2fb902eb4 100644 --- a/quantum/process_keycode/process_midi.c +++ b/quantum/process_keycode/process_midi.c @@ -16,86 +16,65 @@ #include "process_midi.h" #ifdef MIDI_ENABLE -#include -#include "midi.h" -#include "qmk_midi.h" +# include +# include "midi.h" +# include "qmk_midi.h" -#ifdef MIDI_BASIC +# ifdef MIDI_BASIC -void process_midi_basic_noteon(uint8_t note) -{ - midi_send_noteon(&midi_device, 0, note, 127); -} +void process_midi_basic_noteon(uint8_t note) { midi_send_noteon(&midi_device, 0, note, 127); } -void process_midi_basic_noteoff(uint8_t note) -{ - midi_send_noteoff(&midi_device, 0, note, 0); -} +void process_midi_basic_noteoff(uint8_t note) { midi_send_noteoff(&midi_device, 0, note, 0); } -void process_midi_all_notes_off(void) -{ - midi_send_cc(&midi_device, 0, 0x7B, 0); -} +void process_midi_all_notes_off(void) { midi_send_cc(&midi_device, 0, 0x7B, 0); } -#endif // MIDI_BASIC +# endif // MIDI_BASIC -#ifdef MIDI_ADVANCED +# ifdef MIDI_ADVANCED -#include "timer.h" +# include "timer.h" static uint8_t tone_status[MIDI_TONE_COUNT]; -static uint8_t midi_modulation; -static int8_t midi_modulation_step; +static uint8_t midi_modulation; +static int8_t midi_modulation_step; static uint16_t midi_modulation_timer; -midi_config_t midi_config; +midi_config_t midi_config; -inline uint8_t compute_velocity(uint8_t setting) -{ - return (setting + 1) * (128 / (MIDI_VELOCITY_MAX - MIDI_VELOCITY_MIN + 1)); -} +inline uint8_t compute_velocity(uint8_t setting) { return (setting + 1) * (128 / (MIDI_VELOCITY_MAX - MIDI_VELOCITY_MIN + 1)); } -void midi_init(void) -{ - midi_config.octave = MI_OCT_2 - MIDI_OCTAVE_MIN; - midi_config.transpose = 0; - midi_config.velocity = (MIDI_VELOCITY_MAX - MIDI_VELOCITY_MIN); - midi_config.channel = 0; +void midi_init(void) { + midi_config.octave = MI_OCT_2 - MIDI_OCTAVE_MIN; + midi_config.transpose = 0; + midi_config.velocity = (MIDI_VELOCITY_MAX - MIDI_VELOCITY_MIN); + midi_config.channel = 0; midi_config.modulation_interval = 8; - for (uint8_t i = 0; i < MIDI_TONE_COUNT; i++) - { + for (uint8_t i = 0; i < MIDI_TONE_COUNT; i++) { tone_status[i] = MIDI_INVALID_NOTE; } - midi_modulation = 0; - midi_modulation_step = 0; + midi_modulation = 0; + midi_modulation_step = 0; midi_modulation_timer = 0; } -uint8_t midi_compute_note(uint16_t keycode) -{ - return 12 * midi_config.octave + (keycode - MIDI_TONE_MIN) + midi_config.transpose; -} +uint8_t midi_compute_note(uint16_t keycode) { return 12 * midi_config.octave + (keycode - MIDI_TONE_MIN) + midi_config.transpose; } -bool process_midi(uint16_t keycode, keyrecord_t *record) -{ +bool process_midi(uint16_t keycode, keyrecord_t *record) { switch (keycode) { - case MIDI_TONE_MIN ... MIDI_TONE_MAX: - { - uint8_t channel = midi_config.channel; - uint8_t tone = keycode - MIDI_TONE_MIN; + case MIDI_TONE_MIN ... MIDI_TONE_MAX: { + uint8_t channel = midi_config.channel; + uint8_t tone = keycode - MIDI_TONE_MIN; uint8_t velocity = compute_velocity(midi_config.velocity); if (record->event.pressed) { uint8_t note = midi_compute_note(keycode); midi_send_noteon(&midi_device, channel, note, velocity); dprintf("midi noteon channel:%d note:%d velocity:%d\n", channel, note, velocity); tone_status[tone] = note; - } - else { + } else { uint8_t note = tone_status[tone]; - if (note != MIDI_INVALID_NOTE) - { + if (note != MIDI_INVALID_NOTE) { midi_send_noteoff(&midi_device, channel, note, velocity); dprintf("midi noteoff channel:%d note:%d velocity:%d\n", channel, note, velocity); } @@ -137,8 +116,7 @@ bool process_midi(uint16_t keycode, keyrecord_t *record) if (record->event.pressed && midi_config.transpose < (MIDI_TRANSPOSE_MAX - MI_TRNS_0)) { const bool positive = midi_config.transpose > 0; midi_config.transpose++; - if (positive && midi_config.transpose < 0) - midi_config.transpose--; + if (positive && midi_config.transpose < 0) midi_config.transpose--; dprintf("midi transpose %d\n", midi_config.transpose); } return false; @@ -211,8 +189,7 @@ bool process_midi(uint16_t keycode, keyrecord_t *record) if (record->event.pressed) { midi_config.modulation_interval++; // prevent overflow - if (midi_config.modulation_interval == 0) - midi_config.modulation_interval--; + if (midi_config.modulation_interval == 0) midi_config.modulation_interval--; dprintf("midi modulation interval %d\n", midi_config.modulation_interval); } return false; @@ -226,8 +203,7 @@ bool process_midi(uint16_t keycode, keyrecord_t *record) if (record->event.pressed) { midi_send_pitchbend(&midi_device, midi_config.channel, -0x2000); dprintf("midi pitchbend channel:%d amount:%d\n", midi_config.channel, -0x2000); - } - else { + } else { midi_send_pitchbend(&midi_device, midi_config.channel, 0); dprintf("midi pitchbend channel:%d amount:%d\n", midi_config.channel, 0); } @@ -236,8 +212,7 @@ bool process_midi(uint16_t keycode, keyrecord_t *record) if (record->event.pressed) { midi_send_pitchbend(&midi_device, midi_config.channel, 0x1fff); dprintf("midi pitchbend channel:%d amount:%d\n", midi_config.channel, 0x1fff); - } - else { + } else { midi_send_pitchbend(&midi_device, midi_config.channel, 0); dprintf("midi pitchbend channel:%d amount:%d\n", midi_config.channel, 0); } @@ -247,35 +222,29 @@ bool process_midi(uint16_t keycode, keyrecord_t *record) return true; } -#endif // MIDI_ADVANCED +# endif // MIDI_ADVANCED -void midi_task(void) -{ +void midi_task(void) { midi_device_process(&midi_device); -#ifdef MIDI_ADVANCED - if (timer_elapsed(midi_modulation_timer) < midi_config.modulation_interval) - return; +# ifdef MIDI_ADVANCED + if (timer_elapsed(midi_modulation_timer) < midi_config.modulation_interval) return; midi_modulation_timer = timer_read(); - if (midi_modulation_step != 0) - { + if (midi_modulation_step != 0) { dprintf("midi modulation %d\n", midi_modulation); midi_send_cc(&midi_device, midi_config.channel, 0x1, midi_modulation); if (midi_modulation_step < 0 && midi_modulation < -midi_modulation_step) { - midi_modulation = 0; + midi_modulation = 0; midi_modulation_step = 0; return; } midi_modulation += midi_modulation_step; - if (midi_modulation > 127) - midi_modulation = 127; + if (midi_modulation > 127) midi_modulation = 127; } -#endif +# endif } - - -#endif // MIDI_ENABLE +#endif // MIDI_ENABLE diff --git a/quantum/process_keycode/process_midi.h b/quantum/process_keycode/process_midi.h index 1968fbe3fa..0007b3ed25 100644 --- a/quantum/process_keycode/process_midi.h +++ b/quantum/process_keycode/process_midi.h @@ -21,24 +21,24 @@ #ifdef MIDI_ENABLE -#ifdef MIDI_BASIC +# ifdef MIDI_BASIC void process_midi_basic_noteon(uint8_t note); void process_midi_basic_noteoff(uint8_t note); void process_midi_all_notes_off(void); -#endif +# endif void midi_task(void); -#ifdef MIDI_ADVANCED +# ifdef MIDI_ADVANCED typedef union { - uint32_t raw; - struct { - uint8_t octave :4; - int8_t transpose :4; - uint8_t velocity :4; - uint8_t channel :4; - uint8_t modulation_interval :4; - }; + uint32_t raw; + struct { + uint8_t octave : 4; + int8_t transpose : 4; + uint8_t velocity : 4; + uint8_t channel : 4; + uint8_t modulation_interval : 4; + }; } midi_config_t; extern midi_config_t midi_config; @@ -46,12 +46,12 @@ extern midi_config_t midi_config; void midi_init(void); bool process_midi(uint16_t keycode, keyrecord_t *record); -#define MIDI_INVALID_NOTE 0xFF -#define MIDI_TONE_COUNT (MIDI_TONE_MAX - MIDI_TONE_MIN + 1) +# define MIDI_INVALID_NOTE 0xFF +# define MIDI_TONE_COUNT (MIDI_TONE_MAX - MIDI_TONE_MIN + 1) uint8_t midi_compute_note(uint16_t keycode); -#endif // MIDI_ADVANCED +# endif // MIDI_ADVANCED -#endif // MIDI_ENABLE +#endif // MIDI_ENABLE #endif diff --git a/quantum/process_keycode/process_music.c b/quantum/process_keycode/process_music.c index 697aa237fa..b61a16e878 100644 --- a/quantum/process_keycode/process_music.c +++ b/quantum/process_keycode/process_music.c @@ -16,103 +16,91 @@ #include "process_music.h" #ifdef AUDIO_ENABLE -#include "process_audio.h" +# include "process_audio.h" #endif #if defined(MIDI_ENABLE) && defined(MIDI_BASIC) -#include "process_midi.h" +# include "process_midi.h" #endif #if defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC)) -bool music_activated = false; -bool midi_activated = false; +bool music_activated = false; +bool midi_activated = false; uint8_t music_starting_note = 0x0C; -int music_offset = 7; -uint8_t music_mode = MUSIC_MODE_MAJOR; +int music_offset = 7; +uint8_t music_mode = MUSIC_MODE_MAJOR; // music sequencer -static bool music_sequence_recording = false; -static bool music_sequence_recorded = false; -static bool music_sequence_playing = false; -static uint8_t music_sequence[16] = {0}; -static uint8_t music_sequence_count = 0; -static uint8_t music_sequence_position = 0; - -static uint16_t music_sequence_timer = 0; +static bool music_sequence_recording = false; +static bool music_sequence_recorded = false; +static bool music_sequence_playing = false; +static uint8_t music_sequence[16] = {0}; +static uint8_t music_sequence_count = 0; +static uint8_t music_sequence_position = 0; + +static uint16_t music_sequence_timer = 0; static uint16_t music_sequence_interval = 100; -#ifdef AUDIO_ENABLE - #ifndef MUSIC_ON_SONG - #define MUSIC_ON_SONG SONG(MUSIC_ON_SOUND) - #endif - #ifndef MUSIC_OFF_SONG - #define MUSIC_OFF_SONG SONG(MUSIC_OFF_SOUND) - #endif - #ifndef MIDI_ON_SONG - #define MIDI_ON_SONG SONG(MUSIC_ON_SOUND) - #endif - #ifndef MIDI_OFF_SONG - #define MIDI_OFF_SONG SONG(MUSIC_OFF_SOUND) - #endif - #ifndef CHROMATIC_SONG - #define CHROMATIC_SONG SONG(CHROMATIC_SOUND) - #endif - #ifndef GUITAR_SONG - #define GUITAR_SONG SONG(GUITAR_SOUND) - #endif - #ifndef VIOLIN_SONG - #define VIOLIN_SONG SONG(VIOLIN_SOUND) - #endif - #ifndef MAJOR_SONG - #define MAJOR_SONG SONG(MAJOR_SOUND) - #endif - float music_mode_songs[NUMBER_OF_MODES][5][2] = { - CHROMATIC_SONG, - GUITAR_SONG, - VIOLIN_SONG, - MAJOR_SONG - }; - float music_on_song[][2] = MUSIC_ON_SONG; - float music_off_song[][2] = MUSIC_OFF_SONG; - float midi_on_song[][2] = MIDI_ON_SONG; - float midi_off_song[][2] = MIDI_OFF_SONG; -#endif +# ifdef AUDIO_ENABLE +# ifndef MUSIC_ON_SONG +# define MUSIC_ON_SONG SONG(MUSIC_ON_SOUND) +# endif +# ifndef MUSIC_OFF_SONG +# define MUSIC_OFF_SONG SONG(MUSIC_OFF_SOUND) +# endif +# ifndef MIDI_ON_SONG +# define MIDI_ON_SONG SONG(MUSIC_ON_SOUND) +# endif +# ifndef MIDI_OFF_SONG +# define MIDI_OFF_SONG SONG(MUSIC_OFF_SOUND) +# endif +# ifndef CHROMATIC_SONG +# define CHROMATIC_SONG SONG(CHROMATIC_SOUND) +# endif +# ifndef GUITAR_SONG +# define GUITAR_SONG SONG(GUITAR_SOUND) +# endif +# ifndef VIOLIN_SONG +# define VIOLIN_SONG SONG(VIOLIN_SOUND) +# endif +# ifndef MAJOR_SONG +# define MAJOR_SONG SONG(MAJOR_SOUND) +# endif +float music_mode_songs[NUMBER_OF_MODES][5][2] = {CHROMATIC_SONG, GUITAR_SONG, VIOLIN_SONG, MAJOR_SONG}; +float music_on_song[][2] = MUSIC_ON_SONG; +float music_off_song[][2] = MUSIC_OFF_SONG; +float midi_on_song[][2] = MIDI_ON_SONG; +float midi_off_song[][2] = MIDI_OFF_SONG; +# endif static void music_noteon(uint8_t note) { - #ifdef AUDIO_ENABLE - if (music_activated) - process_audio_noteon(note); - #endif - #if defined(MIDI_ENABLE) && defined(MIDI_BASIC) - if (midi_activated) - process_midi_basic_noteon(note); - #endif +# ifdef AUDIO_ENABLE + if (music_activated) process_audio_noteon(note); +# endif +# if defined(MIDI_ENABLE) && defined(MIDI_BASIC) + if (midi_activated) process_midi_basic_noteon(note); +# endif } static void music_noteoff(uint8_t note) { - #ifdef AUDIO_ENABLE - if (music_activated) - process_audio_noteoff(note); - #endif - #if defined(MIDI_ENABLE) && defined(MIDI_BASIC) - if (midi_activated) - process_midi_basic_noteoff(note); - #endif +# ifdef AUDIO_ENABLE + if (music_activated) process_audio_noteoff(note); +# endif +# if defined(MIDI_ENABLE) && defined(MIDI_BASIC) + if (midi_activated) process_midi_basic_noteoff(note); +# endif } void music_all_notes_off(void) { - #ifdef AUDIO_ENABLE - if (music_activated) - process_audio_all_notes_off(); - #endif - #if defined(MIDI_ENABLE) && defined(MIDI_BASIC) - if (midi_activated) - process_midi_all_notes_off(); - #endif +# ifdef AUDIO_ENABLE + if (music_activated) process_audio_all_notes_off(); +# endif +# if defined(MIDI_ENABLE) && defined(MIDI_BASIC) + if (midi_activated) process_midi_all_notes_off(); +# endif } bool process_music(uint16_t keycode, keyrecord_t *record) { - if (keycode == MU_ON && record->event.pressed) { music_on(); return false; @@ -152,110 +140,101 @@ bool process_music(uint16_t keycode, keyrecord_t *record) { } if (keycode == MU_MOD && record->event.pressed) { - music_mode_cycle(); - return false; + music_mode_cycle(); + return false; } if (music_activated || midi_activated) { - if (record->event.pressed) { - if (keycode == KC_LCTL) { // Start recording - music_all_notes_off(); - music_sequence_recording = true; - music_sequence_recorded = false; - music_sequence_playing = false; - music_sequence_count = 0; - return false; - } - - if (keycode == KC_LALT) { // Stop recording/playing - music_all_notes_off(); - if (music_sequence_recording) { // was recording - music_sequence_recorded = true; - } - music_sequence_recording = false; - music_sequence_playing = false; - return false; - } - - if (keycode == KC_LGUI && music_sequence_recorded) { // Start playing - music_all_notes_off(); - music_sequence_recording = false; - music_sequence_playing = true; - music_sequence_position = 0; - music_sequence_timer = 0; - return false; - } - - if (keycode == KC_UP) { - music_sequence_interval-=10; - return false; + if (record->event.pressed) { + if (keycode == KC_LCTL) { // Start recording + music_all_notes_off(); + music_sequence_recording = true; + music_sequence_recorded = false; + music_sequence_playing = false; + music_sequence_count = 0; + return false; + } + + if (keycode == KC_LALT) { // Stop recording/playing + music_all_notes_off(); + if (music_sequence_recording) { // was recording + music_sequence_recorded = true; + } + music_sequence_recording = false; + music_sequence_playing = false; + return false; + } + + if (keycode == KC_LGUI && music_sequence_recorded) { // Start playing + music_all_notes_off(); + music_sequence_recording = false; + music_sequence_playing = true; + music_sequence_position = 0; + music_sequence_timer = 0; + return false; + } + + if (keycode == KC_UP) { + music_sequence_interval -= 10; + return false; + } + + if (keycode == KC_DOWN) { + music_sequence_interval += 10; + return false; + } } - if (keycode == KC_DOWN) { - music_sequence_interval+=10; - return false; - } - } - - uint8_t note = 36; - #ifdef MUSIC_MAP + uint8_t note = 36; +# ifdef MUSIC_MAP if (music_mode == MUSIC_MODE_CHROMATIC) { - note = music_starting_note + music_offset + 36 + music_map[record->event.key.row][record->event.key.col]; + note = music_starting_note + music_offset + 36 + music_map[record->event.key.row][record->event.key.col]; } else { - uint8_t position = music_map[record->event.key.row][record->event.key.col]; - note = music_starting_note + music_offset + 36 + SCALE[position % 12] + (position / 12)*12; + uint8_t position = music_map[record->event.key.row][record->event.key.col]; + note = music_starting_note + music_offset + 36 + SCALE[position % 12] + (position / 12) * 12; } - #else +# else if (music_mode == MUSIC_MODE_CHROMATIC) - note = (music_starting_note + record->event.key.col + music_offset - 3)+12*(MATRIX_ROWS - record->event.key.row); + note = (music_starting_note + record->event.key.col + music_offset - 3) + 12 * (MATRIX_ROWS - record->event.key.row); else if (music_mode == MUSIC_MODE_GUITAR) - note = (music_starting_note + record->event.key.col + music_offset + 32)+5*(MATRIX_ROWS - record->event.key.row); + note = (music_starting_note + record->event.key.col + music_offset + 32) + 5 * (MATRIX_ROWS - record->event.key.row); else if (music_mode == MUSIC_MODE_VIOLIN) - note = (music_starting_note + record->event.key.col + music_offset + 32)+7*(MATRIX_ROWS - record->event.key.row); + note = (music_starting_note + record->event.key.col + music_offset + 32) + 7 * (MATRIX_ROWS - record->event.key.row); else if (music_mode == MUSIC_MODE_MAJOR) - note = (music_starting_note + SCALE[record->event.key.col + music_offset] - 3)+12*(MATRIX_ROWS - record->event.key.row); + note = (music_starting_note + SCALE[record->event.key.col + music_offset] - 3) + 12 * (MATRIX_ROWS - record->event.key.row); else - note = music_starting_note; - #endif - - if (record->event.pressed) { - music_noteon(note); - if (music_sequence_recording) { - music_sequence[music_sequence_count] = note; - music_sequence_count++; + note = music_starting_note; +# endif + + if (record->event.pressed) { + music_noteon(note); + if (music_sequence_recording) { + music_sequence[music_sequence_count] = note; + music_sequence_count++; + } + } else { + music_noteoff(note); } - } else { - music_noteoff(note); - } - if (music_mask(keycode)) - return false; + if (music_mask(keycode)) return false; } return true; } bool music_mask(uint16_t keycode) { - #ifdef MUSIC_MASK +# ifdef MUSIC_MASK return MUSIC_MASK; - #else +# else return music_mask_kb(keycode); - #endif +# endif } -__attribute__((weak)) -bool music_mask_kb(uint16_t keycode) { - return music_mask_user(keycode); -} +__attribute__((weak)) bool music_mask_kb(uint16_t keycode) { return music_mask_user(keycode); } -__attribute__((weak)) -bool music_mask_user(uint16_t keycode) { - return keycode < 0xFF; -} +__attribute__((weak)) bool music_mask_user(uint16_t keycode) { return keycode < 0xFF; } -bool is_music_on(void) { - return (music_activated != 0); -} +bool is_music_on(void) { return (music_activated != 0); } void music_toggle(void) { if (!music_activated) { @@ -267,23 +246,21 @@ void music_toggle(void) { void music_on(void) { music_activated = 1; - #ifdef AUDIO_ENABLE - PLAY_SONG(music_on_song); - #endif +# ifdef AUDIO_ENABLE + PLAY_SONG(music_on_song); +# endif music_on_user(); } void music_off(void) { music_all_notes_off(); music_activated = 0; - #ifdef AUDIO_ENABLE - PLAY_SONG(music_off_song); - #endif +# ifdef AUDIO_ENABLE + PLAY_SONG(music_off_song); +# endif } -bool is_midi_on(void) { - return (midi_activated != 0); -} +bool is_midi_on(void) { return (midi_activated != 0); } void midi_toggle(void) { if (!midi_activated) { @@ -295,50 +272,47 @@ void midi_toggle(void) { void midi_on(void) { midi_activated = 1; - #ifdef AUDIO_ENABLE - PLAY_SONG(midi_on_song); - #endif +# ifdef AUDIO_ENABLE + PLAY_SONG(midi_on_song); +# endif midi_on_user(); } void midi_off(void) { - #if defined(MIDI_ENABLE) && defined(MIDI_BASIC) - process_midi_all_notes_off(); - #endif +# if defined(MIDI_ENABLE) && defined(MIDI_BASIC) + process_midi_all_notes_off(); +# endif midi_activated = 0; - #ifdef AUDIO_ENABLE - PLAY_SONG(midi_off_song); - #endif +# ifdef AUDIO_ENABLE + PLAY_SONG(midi_off_song); +# endif } void music_mode_cycle(void) { - music_all_notes_off(); - music_mode = (music_mode + 1) % NUMBER_OF_MODES; - #ifdef AUDIO_ENABLE + music_all_notes_off(); + music_mode = (music_mode + 1) % NUMBER_OF_MODES; +# ifdef AUDIO_ENABLE PLAY_SONG(music_mode_songs[music_mode]); - #endif +# endif } void matrix_scan_music(void) { - if (music_sequence_playing) { - if ((music_sequence_timer == 0) || (timer_elapsed(music_sequence_timer) > music_sequence_interval)) { - music_sequence_timer = timer_read(); - uint8_t prev_note = music_sequence[(music_sequence_position - 1 < 0)?(music_sequence_position - 1 + music_sequence_count):(music_sequence_position - 1)]; - uint8_t next_note = music_sequence[music_sequence_position]; - music_noteoff(prev_note); - music_noteon(next_note); - music_sequence_position = (music_sequence_position + 1) % music_sequence_count; + if (music_sequence_playing) { + if ((music_sequence_timer == 0) || (timer_elapsed(music_sequence_timer) > music_sequence_interval)) { + music_sequence_timer = timer_read(); + uint8_t prev_note = music_sequence[(music_sequence_position - 1 < 0) ? (music_sequence_position - 1 + music_sequence_count) : (music_sequence_position - 1)]; + uint8_t next_note = music_sequence[music_sequence_position]; + music_noteoff(prev_note); + music_noteon(next_note); + music_sequence_position = (music_sequence_position + 1) % music_sequence_count; + } } - } } -__attribute__ ((weak)) -void music_on_user() {} +__attribute__((weak)) void music_on_user() {} -__attribute__ ((weak)) -void midi_on_user() {} +__attribute__((weak)) void midi_on_user() {} -__attribute__ ((weak)) -void music_scale_user() {} +__attribute__((weak)) void music_scale_user() {} -#endif // defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC)) +#endif // defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC)) diff --git a/quantum/process_keycode/process_music.h b/quantum/process_keycode/process_music.h index f6753d4f24..292bc53742 100644 --- a/quantum/process_keycode/process_music.h +++ b/quantum/process_keycode/process_music.h @@ -21,18 +21,11 @@ #if defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC)) -enum music_modes { - MUSIC_MODE_CHROMATIC, - MUSIC_MODE_GUITAR, - MUSIC_MODE_VIOLIN, - MUSIC_MODE_MAJOR, - NUMBER_OF_MODES -}; +enum music_modes { MUSIC_MODE_CHROMATIC, MUSIC_MODE_GUITAR, MUSIC_MODE_VIOLIN, MUSIC_MODE_MAJOR, NUMBER_OF_MODES }; - -#ifdef MUSIC_MAP - extern const uint8_t music_map[MATRIX_ROWS][MATRIX_COLS]; -#endif +# ifdef MUSIC_MAP +extern const uint8_t music_map[MATRIX_ROWS][MATRIX_COLS]; +# endif bool process_music(uint16_t keycode, keyrecord_t *record); @@ -58,14 +51,11 @@ bool music_mask(uint16_t keycode); bool music_mask_kb(uint16_t keycode); bool music_mask_user(uint16_t keycode); -#ifndef SCALE -#define SCALE (int8_t []){ 0 + (12*0), 2 + (12*0), 4 + (12*0), 5 + (12*0), 7 + (12*0), 9 + (12*0), 11 + (12*0), \ - 0 + (12*1), 2 + (12*1), 4 + (12*1), 5 + (12*1), 7 + (12*1), 9 + (12*1), 11 + (12*1), \ - 0 + (12*2), 2 + (12*2), 4 + (12*2), 5 + (12*2), 7 + (12*2), 9 + (12*2), 11 + (12*2), \ - 0 + (12*3), 2 + (12*3), 4 + (12*3), 5 + (12*3), 7 + (12*3), 9 + (12*3), 11 + (12*3), \ - 0 + (12*4), 2 + (12*4), 4 + (12*4), 5 + (12*4), 7 + (12*4), 9 + (12*4), 11 + (12*4), } -#endif +# ifndef SCALE +# define SCALE \ + (int8_t[]) { 0 + (12 * 0), 2 + (12 * 0), 4 + (12 * 0), 5 + (12 * 0), 7 + (12 * 0), 9 + (12 * 0), 11 + (12 * 0), 0 + (12 * 1), 2 + (12 * 1), 4 + (12 * 1), 5 + (12 * 1), 7 + (12 * 1), 9 + (12 * 1), 11 + (12 * 1), 0 + (12 * 2), 2 + (12 * 2), 4 + (12 * 2), 5 + (12 * 2), 7 + (12 * 2), 9 + (12 * 2), 11 + (12 * 2), 0 + (12 * 3), 2 + (12 * 3), 4 + (12 * 3), 5 + (12 * 3), 7 + (12 * 3), 9 + (12 * 3), 11 + (12 * 3), 0 + (12 * 4), 2 + (12 * 4), 4 + (12 * 4), 5 + (12 * 4), 7 + (12 * 4), 9 + (12 * 4), 11 + (12 * 4), } +# endif -#endif // defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC)) +#endif // defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC)) #endif diff --git a/quantum/process_keycode/process_printer.c b/quantum/process_keycode/process_printer.c index 613af70183..7c5e4169a6 100644 --- a/quantum/process_keycode/process_printer.c +++ b/quantum/process_keycode/process_printer.c @@ -17,17 +17,15 @@ #include "process_printer.h" #include "action_util.h" -bool printing_enabled = false; -uint8_t character_shift = 0; +bool printing_enabled = false; +uint8_t character_shift = 0; void enable_printing(void) { - printing_enabled = true; - serial_init(); + printing_enabled = true; + serial_init(); } -void disable_printing(void) { - printing_enabled = false; -} +void disable_printing(void) { printing_enabled = false; } uint8_t shifted_numbers[10] = {0x21, 0x40, 0x23, 0x24, 0x25, 0x5E, 0x26, 0x2A, 0x28, 0x29}; @@ -36,235 +34,232 @@ uint8_t shifted_numbers[10] = {0x21, 0x40, 0x23, 0x24, 0x25, 0x5E, 0x26, 0x2A, 0 // keycode_to_ascii[KC_MINS] = {0x2D, 0x5F}; void print_char(char c) { - USB_Disable(); - serial_send(c); - USB_Init(); + USB_Disable(); + serial_send(c); + USB_Init(); } void print_string(char c[]) { - for(uint8_t i = 0; i < strlen(c); i++) - print_char(c[i]); + for (uint8_t i = 0; i < strlen(c); i++) print_char(c[i]); } void print_box_string(const char text[]) { - size_t len = strlen(text); - char out[len * 3 + 8]; - out[0] = 0xDA; - for (uint8_t i = 0; i < len; i++) { - out[i+1] = 0xC4; - } - out[len + 1] = 0xBF; - out[len + 2] = '\n'; - - out[len + 3] = 0xB3; - for (uint8_t i = 0; i < len; i++) { - out[len + 4 + i] = text[i]; - } - out[len * 2 + 4] = 0xB3; - out[len * 2 + 5] = '\n'; + size_t len = strlen(text); + char out[len * 3 + 8]; + out[0] = 0xDA; + for (uint8_t i = 0; i < len; i++) { + out[i + 1] = 0xC4; + } + out[len + 1] = 0xBF; + out[len + 2] = '\n'; + out[len + 3] = 0xB3; + for (uint8_t i = 0; i < len; i++) { + out[len + 4 + i] = text[i]; + } + out[len * 2 + 4] = 0xB3; + out[len * 2 + 5] = '\n'; - out[len * 2 + 6] = 0xC0; - for (uint8_t i = 0; i < len; i++) { - out[len * 2 + 7 + i] = 0xC4; - } - out[len * 3 + 7] = 0xD9; - out[len * 3 + 8] = '\n'; + out[len * 2 + 6] = 0xC0; + for (uint8_t i = 0; i < len; i++) { + out[len * 2 + 7 + i] = 0xC4; + } + out[len * 3 + 7] = 0xD9; + out[len * 3 + 8] = '\n'; - print_string(out); + print_string(out); } bool process_printer(uint16_t keycode, keyrecord_t *record) { - if (keycode == PRINT_ON) { - enable_printing(); - return false; - } - if (keycode == PRINT_OFF) { - disable_printing(); - return false; - } - - if (printing_enabled) { - switch(keycode) { - case KC_EXLM ... KC_RPRN: - case KC_UNDS: - case KC_PLUS: - case KC_LCBR: - case KC_RCBR: - case KC_PIPE: - case KC_TILD: - keycode &= 0xFF; - case KC_LSFT: - case KC_RSFT: - if (record->event.pressed) { - character_shift++; - } else { - character_shift--; - } - return false; - break; - } + if (keycode == PRINT_ON) { + enable_printing(); + return false; + } + if (keycode == PRINT_OFF) { + disable_printing(); + return false; + } - switch(keycode) { - case KC_F1: - if (record->event.pressed) { - print_box_string("This is a line of text!"); - } - return false; - case KC_ESC: - if (record->event.pressed) { - print_char(0x1B); - } - return false; - break; - case KC_SPC: - if (record->event.pressed) { - print_char(0x20); - } - return false; - break; - case KC_A ... KC_Z: - if (record->event.pressed) { - if (character_shift) { - print_char(0x41 + (keycode - KC_A)); - } else { - print_char(0x61 + (keycode - KC_A)); - } - } - return false; - break; - case KC_1 ... KC_0: - if (record->event.pressed) { - if (character_shift) { - print_char(shifted_numbers[keycode - KC_1]); - } else { - print_char(0x30 + ((keycode - KC_1 + 1) % 10)); - } - } - return false; - break; - case KC_ENT: - if (record->event.pressed) { - if (character_shift) { - print_char(0x0C); - } else { - print_char(0x0A); - } - } - return false; - break; - case KC_BSPC: - if (record->event.pressed) { - if (character_shift) { - print_char(0x18); - } else { - print_char(0x1A); - } - } - return false; - break; - case KC_DOT: - if (record->event.pressed) { - if (character_shift) { - print_char(0x3E); - } else { - print_char(0x2E); - } - } - return false; - break; - case KC_COMM: - if (record->event.pressed) { - if (character_shift) { - print_char(0x3C); - } else { - print_char(0x2C); - } - } - return false; - break; - case KC_SLSH: - if (record->event.pressed) { - if (character_shift) { - print_char(0x3F); - } else { - print_char(0x2F); - } - } - return false; - break; - case KC_QUOT: - if (record->event.pressed) { - if (character_shift) { - print_char(0x22); - } else { - print_char(0x27); - } - } - return false; - break; - case KC_GRV: - if (record->event.pressed) { - if (character_shift) { - print_char(0x7E); - } else { - print_char(0x60); - } - } - return false; - break; - case KC_MINS: - if (record->event.pressed) { - if (character_shift) { - print_char(0x5F); - } else { - print_char(0x2D); - } - } - return false; - break; - case KC_EQL: - if (record->event.pressed) { - if (character_shift) { - print_char(0x2B); - } else { - print_char(0x3D); - } - } - return false; - break; - case KC_LBRC: - if (record->event.pressed) { - if (character_shift) { - print_char(0x7B); - } else { - print_char(0x5B); - } - } - return false; - break; - case KC_RBRC: - if (record->event.pressed) { - if (character_shift) { - print_char(0x7D); - } else { - print_char(0x5D); - } - } - return false; - break; - case KC_BSLS: - if (record->event.pressed) { - if (character_shift) { - print_char(0x7C); - } else { - print_char(0x5C); - } - } - return false; - break; - } - } - return true; + if (printing_enabled) { + switch (keycode) { + case KC_EXLM ... KC_RPRN: + case KC_UNDS: + case KC_PLUS: + case KC_LCBR: + case KC_RCBR: + case KC_PIPE: + case KC_TILD: + keycode &= 0xFF; + case KC_LSFT: + case KC_RSFT: + if (record->event.pressed) { + character_shift++; + } else { + character_shift--; + } + return false; + break; + } + switch (keycode) { + case KC_F1: + if (record->event.pressed) { + print_box_string("This is a line of text!"); + } + return false; + case KC_ESC: + if (record->event.pressed) { + print_char(0x1B); + } + return false; + break; + case KC_SPC: + if (record->event.pressed) { + print_char(0x20); + } + return false; + break; + case KC_A ... KC_Z: + if (record->event.pressed) { + if (character_shift) { + print_char(0x41 + (keycode - KC_A)); + } else { + print_char(0x61 + (keycode - KC_A)); + } + } + return false; + break; + case KC_1 ... KC_0: + if (record->event.pressed) { + if (character_shift) { + print_char(shifted_numbers[keycode - KC_1]); + } else { + print_char(0x30 + ((keycode - KC_1 + 1) % 10)); + } + } + return false; + break; + case KC_ENT: + if (record->event.pressed) { + if (character_shift) { + print_char(0x0C); + } else { + print_char(0x0A); + } + } + return false; + break; + case KC_BSPC: + if (record->event.pressed) { + if (character_shift) { + print_char(0x18); + } else { + print_char(0x1A); + } + } + return false; + break; + case KC_DOT: + if (record->event.pressed) { + if (character_shift) { + print_char(0x3E); + } else { + print_char(0x2E); + } + } + return false; + break; + case KC_COMM: + if (record->event.pressed) { + if (character_shift) { + print_char(0x3C); + } else { + print_char(0x2C); + } + } + return false; + break; + case KC_SLSH: + if (record->event.pressed) { + if (character_shift) { + print_char(0x3F); + } else { + print_char(0x2F); + } + } + return false; + break; + case KC_QUOT: + if (record->event.pressed) { + if (character_shift) { + print_char(0x22); + } else { + print_char(0x27); + } + } + return false; + break; + case KC_GRV: + if (record->event.pressed) { + if (character_shift) { + print_char(0x7E); + } else { + print_char(0x60); + } + } + return false; + break; + case KC_MINS: + if (record->event.pressed) { + if (character_shift) { + print_char(0x5F); + } else { + print_char(0x2D); + } + } + return false; + break; + case KC_EQL: + if (record->event.pressed) { + if (character_shift) { + print_char(0x2B); + } else { + print_char(0x3D); + } + } + return false; + break; + case KC_LBRC: + if (record->event.pressed) { + if (character_shift) { + print_char(0x7B); + } else { + print_char(0x5B); + } + } + return false; + break; + case KC_RBRC: + if (record->event.pressed) { + if (character_shift) { + print_char(0x7D); + } else { + print_char(0x5D); + } + } + return false; + break; + case KC_BSLS: + if (record->event.pressed) { + if (character_shift) { + print_char(0x7C); + } else { + print_char(0x5C); + } + } + return false; + break; + } + } + return true; } diff --git a/quantum/process_keycode/process_printer_bb.c b/quantum/process_keycode/process_printer_bb.c index 3a00f169d8..e482d82591 100644 --- a/quantum/process_keycode/process_printer_bb.c +++ b/quantum/process_keycode/process_printer_bb.c @@ -17,44 +17,29 @@ #include "process_printer.h" #include "action_util.h" -bool printing_enabled = false; -uint8_t character_shift = 0; +bool printing_enabled = false; +uint8_t character_shift = 0; #define SERIAL_PIN_DDR DDRD #define SERIAL_PIN_PORT PORTD #define SERIAL_PIN_MASK _BV(PD3) #define SERIAL_DELAY 52 -inline static -void serial_delay(void) { - _delay_us(SERIAL_DELAY); -} +inline static void serial_delay(void) { _delay_us(SERIAL_DELAY); } -inline static -void serial_high(void) { - SERIAL_PIN_PORT |= SERIAL_PIN_MASK; -} +inline static void serial_high(void) { SERIAL_PIN_PORT |= SERIAL_PIN_MASK; } -inline static -void serial_low(void) { - SERIAL_PIN_PORT &= ~SERIAL_PIN_MASK; -} - -inline static -void serial_output(void) { - SERIAL_PIN_DDR |= SERIAL_PIN_MASK; -} +inline static void serial_low(void) { SERIAL_PIN_PORT &= ~SERIAL_PIN_MASK; } +inline static void serial_output(void) { SERIAL_PIN_DDR |= SERIAL_PIN_MASK; } void enable_printing() { - printing_enabled = true; - serial_output(); - serial_high(); + printing_enabled = true; + serial_output(); + serial_high(); } -void disable_printing() { - printing_enabled = false; -} +void disable_printing() { printing_enabled = false; } uint8_t shifted_numbers[10] = {0x21, 0x40, 0x23, 0x24, 0x25, 0x5E, 0x26, 0x2A, 0x28, 0x29}; @@ -63,214 +48,212 @@ uint8_t shifted_numbers[10] = {0x21, 0x40, 0x23, 0x24, 0x25, 0x5E, 0x26, 0x2A, 0 // keycode_to_ascii[KC_MINS] = {0x2D, 0x5F}; void print_char(char c) { - uint8_t b = 8; - serial_output(); - while( b-- ) { - if(c & (1 << b)) { - serial_high(); - } else { - serial_low(); + uint8_t b = 8; + serial_output(); + while (b--) { + if (c & (1 << b)) { + serial_high(); + } else { + serial_low(); + } + serial_delay(); } - serial_delay(); - } } void print_string(char c[]) { - for(uint8_t i = 0; i < strlen(c); i++) - print_char(c[i]); + for (uint8_t i = 0; i < strlen(c); i++) print_char(c[i]); } bool process_printer(uint16_t keycode, keyrecord_t *record) { - if (keycode == PRINT_ON) { - enable_printing(); - return false; - } - if (keycode == PRINT_OFF) { - disable_printing(); - return false; - } - - if (printing_enabled) { - switch(keycode) { - case KC_EXLM ... KC_RPRN: - case KC_UNDS: - case KC_PLUS: - case KC_LCBR: - case KC_RCBR: - case KC_PIPE: - case KC_TILD: - keycode &= 0xFF; - case KC_LSFT: - case KC_RSFT: - if (record->event.pressed) { - character_shift++; - } else { - character_shift--; - } - return false; - break; - } + if (keycode == PRINT_ON) { + enable_printing(); + return false; + } + if (keycode == PRINT_OFF) { + disable_printing(); + return false; + } - switch(keycode) { - case KC_F1: - if (record->event.pressed) { - print_string("This is a line of text!\n\n\n"); - } - return false; - case KC_ESC: - if (record->event.pressed) { - print_char(0x1B); - } - return false; - break; - case KC_SPC: - if (record->event.pressed) { - print_char(0x20); - } - return false; - break; - case KC_A ... KC_Z: - if (record->event.pressed) { - if (character_shift) { - print_char(0x41 + (keycode - KC_A)); - } else { - print_char(0x61 + (keycode - KC_A)); - } - } - return false; - break; - case KC_1 ... KC_0: - if (record->event.pressed) { - if (character_shift) { - print_char(shifted_numbers[keycode - KC_1]); - } else { - print_char(0x30 + ((keycode - KC_1 + 1) % 10)); - } - } - return false; - break; - case KC_ENT: - if (record->event.pressed) { - if (character_shift) { - print_char(0x0C); - } else { - print_char(0x0A); - } - } - return false; - break; - case KC_BSPC: - if (record->event.pressed) { - if (character_shift) { - print_char(0x18); - } else { - print_char(0x1A); - } - } - return false; - break; - case KC_DOT: - if (record->event.pressed) { - if (character_shift) { - print_char(0x3E); - } else { - print_char(0x2E); - } - } - return false; - break; - case KC_COMM: - if (record->event.pressed) { - if (character_shift) { - print_char(0x3C); - } else { - print_char(0x2C); - } - } - return false; - break; - case KC_SLSH: - if (record->event.pressed) { - if (character_shift) { - print_char(0x3F); - } else { - print_char(0x2F); - } - } - return false; - break; - case KC_QUOT: - if (record->event.pressed) { - if (character_shift) { - print_char(0x22); - } else { - print_char(0x27); - } - } - return false; - break; - case KC_GRV: - if (record->event.pressed) { - if (character_shift) { - print_char(0x7E); - } else { - print_char(0x60); - } - } - return false; - break; - case KC_MINS: - if (record->event.pressed) { - if (character_shift) { - print_char(0x5F); - } else { - print_char(0x2D); - } - } - return false; - break; - case KC_EQL: - if (record->event.pressed) { - if (character_shift) { - print_char(0x2B); - } else { - print_char(0x3D); - } - } - return false; - break; - case KC_LBRC: - if (record->event.pressed) { - if (character_shift) { - print_char(0x7B); - } else { - print_char(0x5B); - } - } - return false; - break; - case KC_RBRC: - if (record->event.pressed) { - if (character_shift) { - print_char(0x7D); - } else { - print_char(0x5D); - } - } - return false; - break; - case KC_BSLS: - if (record->event.pressed) { - if (character_shift) { - print_char(0x7C); - } else { - print_char(0x5C); - } - } - return false; - break; - } - } - return true; + if (printing_enabled) { + switch (keycode) { + case KC_EXLM ... KC_RPRN: + case KC_UNDS: + case KC_PLUS: + case KC_LCBR: + case KC_RCBR: + case KC_PIPE: + case KC_TILD: + keycode &= 0xFF; + case KC_LSFT: + case KC_RSFT: + if (record->event.pressed) { + character_shift++; + } else { + character_shift--; + } + return false; + break; + } + switch (keycode) { + case KC_F1: + if (record->event.pressed) { + print_string("This is a line of text!\n\n\n"); + } + return false; + case KC_ESC: + if (record->event.pressed) { + print_char(0x1B); + } + return false; + break; + case KC_SPC: + if (record->event.pressed) { + print_char(0x20); + } + return false; + break; + case KC_A ... KC_Z: + if (record->event.pressed) { + if (character_shift) { + print_char(0x41 + (keycode - KC_A)); + } else { + print_char(0x61 + (keycode - KC_A)); + } + } + return false; + break; + case KC_1 ... KC_0: + if (record->event.pressed) { + if (character_shift) { + print_char(shifted_numbers[keycode - KC_1]); + } else { + print_char(0x30 + ((keycode - KC_1 + 1) % 10)); + } + } + return false; + break; + case KC_ENT: + if (record->event.pressed) { + if (character_shift) { + print_char(0x0C); + } else { + print_char(0x0A); + } + } + return false; + break; + case KC_BSPC: + if (record->event.pressed) { + if (character_shift) { + print_char(0x18); + } else { + print_char(0x1A); + } + } + return false; + break; + case KC_DOT: + if (record->event.pressed) { + if (character_shift) { + print_char(0x3E); + } else { + print_char(0x2E); + } + } + return false; + break; + case KC_COMM: + if (record->event.pressed) { + if (character_shift) { + print_char(0x3C); + } else { + print_char(0x2C); + } + } + return false; + break; + case KC_SLSH: + if (record->event.pressed) { + if (character_shift) { + print_char(0x3F); + } else { + print_char(0x2F); + } + } + return false; + break; + case KC_QUOT: + if (record->event.pressed) { + if (character_shift) { + print_char(0x22); + } else { + print_char(0x27); + } + } + return false; + break; + case KC_GRV: + if (record->event.pressed) { + if (character_shift) { + print_char(0x7E); + } else { + print_char(0x60); + } + } + return false; + break; + case KC_MINS: + if (record->event.pressed) { + if (character_shift) { + print_char(0x5F); + } else { + print_char(0x2D); + } + } + return false; + break; + case KC_EQL: + if (record->event.pressed) { + if (character_shift) { + print_char(0x2B); + } else { + print_char(0x3D); + } + } + return false; + break; + case KC_LBRC: + if (record->event.pressed) { + if (character_shift) { + print_char(0x7B); + } else { + print_char(0x5B); + } + } + return false; + break; + case KC_RBRC: + if (record->event.pressed) { + if (character_shift) { + print_char(0x7D); + } else { + print_char(0x5D); + } + } + return false; + break; + case KC_BSLS: + if (record->event.pressed) { + if (character_shift) { + print_char(0x7C); + } else { + print_char(0x5C); + } + } + return false; + break; + } + } + return true; } diff --git a/quantum/process_keycode/process_space_cadet.c b/quantum/process_keycode/process_space_cadet.c index c8721d446c..6833fdb9fb 100644 --- a/quantum/process_keycode/process_space_cadet.c +++ b/quantum/process_keycode/process_space_cadet.c @@ -16,150 +16,149 @@ #include "process_space_cadet.h" #ifndef TAPPING_TERM - #define TAPPING_TERM 200 +# define TAPPING_TERM 200 #endif // ********** OBSOLETE DEFINES, STOP USING! (pls?) ********** // Shift / paren setup #ifndef LSPO_KEY - #define LSPO_KEY KC_9 +# define LSPO_KEY KC_9 #endif #ifndef RSPC_KEY - #define RSPC_KEY KC_0 +# define RSPC_KEY KC_0 #endif // Shift / Enter setup #ifndef SFTENT_KEY - #define SFTENT_KEY KC_ENT +# define SFTENT_KEY KC_ENT #endif #ifdef DISABLE_SPACE_CADET_MODIFIER - #ifndef LSPO_MOD - #define LSPO_MOD KC_TRNS - #endif - #ifndef RSPC_MOD - #define RSPC_MOD KC_TRNS - #endif +# ifndef LSPO_MOD +# define LSPO_MOD KC_TRNS +# endif +# ifndef RSPC_MOD +# define RSPC_MOD KC_TRNS +# endif #else - #ifndef LSPO_MOD - #define LSPO_MOD KC_LSFT - #endif - #ifndef RSPC_MOD - #define RSPC_MOD KC_RSFT - #endif +# ifndef LSPO_MOD +# define LSPO_MOD KC_LSFT +# endif +# ifndef RSPC_MOD +# define RSPC_MOD KC_RSFT +# endif #endif // ********************************************************** // Shift / paren setup #ifndef LSPO_KEYS - #define LSPO_KEYS KC_LSFT, LSPO_MOD, LSPO_KEY +# define LSPO_KEYS KC_LSFT, LSPO_MOD, LSPO_KEY #endif #ifndef RSPC_KEYS - #define RSPC_KEYS KC_RSFT, RSPC_MOD, RSPC_KEY +# define RSPC_KEYS KC_RSFT, RSPC_MOD, RSPC_KEY #endif // Control / paren setup #ifndef LCPO_KEYS - #define LCPO_KEYS KC_LCTL, KC_LSFT, KC_9 +# define LCPO_KEYS KC_LCTL, KC_LSFT, KC_9 #endif #ifndef RCPC_KEYS - #define RCPC_KEYS KC_RCTL, KC_RSFT, KC_0 +# define RCPC_KEYS KC_RCTL, KC_RSFT, KC_0 #endif // Alt / paren setup #ifndef LAPO_KEYS - #define LAPO_KEYS KC_LALT, KC_LSFT, KC_9 +# define LAPO_KEYS KC_LALT, KC_LSFT, KC_9 #endif #ifndef RAPC_KEYS - #define RAPC_KEYS KC_RALT, KC_RSFT, KC_0 +# define RAPC_KEYS KC_RALT, KC_RSFT, KC_0 #endif // Shift / Enter setup #ifndef SFTENT_KEYS - #define SFTENT_KEYS KC_RSFT, KC_TRNS, SFTENT_KEY +# define SFTENT_KEYS KC_RSFT, KC_TRNS, SFTENT_KEY #endif -static uint8_t sc_last = 0; +static uint8_t sc_last = 0; static uint16_t sc_timer = 0; #ifdef SPACE_CADET_MODIFIER_CARRYOVER static uint8_t sc_mods = 0; #endif void perform_space_cadet(keyrecord_t *record, uint8_t holdMod, uint8_t tapMod, uint8_t keycode) { - if (record->event.pressed) { - sc_last = holdMod; - sc_timer = timer_read (); + if (record->event.pressed) { + sc_last = holdMod; + sc_timer = timer_read(); #ifdef SPACE_CADET_MODIFIER_CARRYOVER - sc_mods = get_mods(); + sc_mods = get_mods(); #endif - if (IS_MOD(holdMod)) { - register_mods(MOD_BIT(holdMod)); - } - } - else { - if (sc_last == holdMod && timer_elapsed(sc_timer) < TAPPING_TERM) { - if (holdMod != tapMod) { if (IS_MOD(holdMod)) { - unregister_mods(MOD_BIT(holdMod)); - } - if (IS_MOD(tapMod)) { - register_mods(MOD_BIT(tapMod)); + register_mods(MOD_BIT(holdMod)); } - } + } else { + if (sc_last == holdMod && timer_elapsed(sc_timer) < TAPPING_TERM) { + if (holdMod != tapMod) { + if (IS_MOD(holdMod)) { + unregister_mods(MOD_BIT(holdMod)); + } + if (IS_MOD(tapMod)) { + register_mods(MOD_BIT(tapMod)); + } + } #ifdef SPACE_CADET_MODIFIER_CARRYOVER - set_weak_mods(sc_mods); + set_weak_mods(sc_mods); #endif - tap_code(keycode); + tap_code(keycode); #ifdef SPACE_CADET_MODIFIER_CARRYOVER - clear_weak_mods(); -#endif - if (IS_MOD(tapMod)) { - unregister_mods(MOD_BIT(tapMod)); - } - } else { - if (IS_MOD(holdMod)) { - unregister_mods(MOD_BIT(holdMod)); - } + clear_weak_mods(); +#endif + if (IS_MOD(tapMod)) { + unregister_mods(MOD_BIT(tapMod)); + } + } else { + if (IS_MOD(holdMod)) { + unregister_mods(MOD_BIT(holdMod)); + } + } } - } } bool process_space_cadet(uint16_t keycode, keyrecord_t *record) { - switch(keycode) { - case KC_LSPO: { - perform_space_cadet(record, LSPO_KEYS); - return false; - } - case KC_RSPC: { - perform_space_cadet(record, RSPC_KEYS); - return false; - } - case KC_LCPO: { - perform_space_cadet(record, LCPO_KEYS); - return false; - } - case KC_RCPC: { - perform_space_cadet(record, RCPC_KEYS); - return false; - } - case KC_LAPO: { - perform_space_cadet(record, LAPO_KEYS); - return false; - } - case KC_RAPC: { - perform_space_cadet(record, RAPC_KEYS); - return false; - } - case KC_SFTENT: { - perform_space_cadet(record, SFTENT_KEYS); - return false; - } - default: { - if (record->event.pressed) { - sc_last = 0; - } - break; + switch (keycode) { + case KC_LSPO: { + perform_space_cadet(record, LSPO_KEYS); + return false; + } + case KC_RSPC: { + perform_space_cadet(record, RSPC_KEYS); + return false; + } + case KC_LCPO: { + perform_space_cadet(record, LCPO_KEYS); + return false; + } + case KC_RCPC: { + perform_space_cadet(record, RCPC_KEYS); + return false; + } + case KC_LAPO: { + perform_space_cadet(record, LAPO_KEYS); + return false; + } + case KC_RAPC: { + perform_space_cadet(record, RAPC_KEYS); + return false; + } + case KC_SFTENT: { + perform_space_cadet(record, SFTENT_KEYS); + return false; + } + default: { + if (record->event.pressed) { + sc_last = 0; + } + break; + } } - } - return true; + return true; } diff --git a/quantum/process_keycode/process_steno.c b/quantum/process_keycode/process_steno.c index 50a1ef2fcf..e0b33ec861 100644 --- a/quantum/process_keycode/process_steno.c +++ b/quantum/process_keycode/process_steno.c @@ -58,150 +58,136 @@ #define GEMINI_STATE_SIZE 6 #define MAX_STATE_SIZE GEMINI_STATE_SIZE -static uint8_t state[MAX_STATE_SIZE] = {0}; -static uint8_t chord[MAX_STATE_SIZE] = {0}; -static int8_t pressed = 0; +static uint8_t state[MAX_STATE_SIZE] = {0}; +static uint8_t chord[MAX_STATE_SIZE] = {0}; +static int8_t pressed = 0; static steno_mode_t mode; -static const uint8_t boltmap[64] PROGMEM = { - TXB_NUL, TXB_NUM, TXB_NUM, TXB_NUM, TXB_NUM, TXB_NUM, TXB_NUM, - TXB_S_L, TXB_S_L, TXB_T_L, TXB_K_L, TXB_P_L, TXB_W_L, TXB_H_L, - TXB_R_L, TXB_A_L, TXB_O_L, TXB_STR, TXB_STR, TXB_NUL, TXB_NUL, - TXB_NUL, TXB_STR, TXB_STR, TXB_E_R, TXB_U_R, TXB_F_R, TXB_R_R, - TXB_P_R, TXB_B_R, TXB_L_R, TXB_G_R, TXB_T_R, TXB_S_R, TXB_D_R, - TXB_NUM, TXB_NUM, TXB_NUM, TXB_NUM, TXB_NUM, TXB_NUM, TXB_Z_R -}; +static const uint8_t boltmap[64] PROGMEM = {TXB_NUL, TXB_NUM, TXB_NUM, TXB_NUM, TXB_NUM, TXB_NUM, TXB_NUM, TXB_S_L, TXB_S_L, TXB_T_L, TXB_K_L, TXB_P_L, TXB_W_L, TXB_H_L, TXB_R_L, TXB_A_L, TXB_O_L, TXB_STR, TXB_STR, TXB_NUL, TXB_NUL, TXB_NUL, TXB_STR, TXB_STR, TXB_E_R, TXB_U_R, TXB_F_R, TXB_R_R, TXB_P_R, TXB_B_R, TXB_L_R, TXB_G_R, TXB_T_R, TXB_S_R, TXB_D_R, TXB_NUM, TXB_NUM, TXB_NUM, TXB_NUM, TXB_NUM, TXB_NUM, TXB_Z_R}; static void steno_clear_state(void) { - memset(state, 0, sizeof(state)); - memset(chord, 0, sizeof(chord)); + memset(state, 0, sizeof(state)); + memset(chord, 0, sizeof(chord)); } static void send_steno_state(uint8_t size, bool send_empty) { - for (uint8_t i = 0; i < size; ++i) { - if (chord[i] || send_empty) { - virtser_send(chord[i]); + for (uint8_t i = 0; i < size; ++i) { + if (chord[i] || send_empty) { + virtser_send(chord[i]); + } } - } } void steno_init() { - if (!eeconfig_is_enabled()) { - eeconfig_init(); - } - mode = eeprom_read_byte(EECONFIG_STENOMODE); + if (!eeconfig_is_enabled()) { + eeconfig_init(); + } + mode = eeprom_read_byte(EECONFIG_STENOMODE); } void steno_set_mode(steno_mode_t new_mode) { - steno_clear_state(); - mode = new_mode; - eeprom_update_byte(EECONFIG_STENOMODE, mode); + steno_clear_state(); + mode = new_mode; + eeprom_update_byte(EECONFIG_STENOMODE, mode); } /* override to intercept chords right before they get sent. * return zero to suppress normal sending behavior. */ -__attribute__ ((weak)) -bool send_steno_chord_user(steno_mode_t mode, uint8_t chord[6]) { return true; } +__attribute__((weak)) bool send_steno_chord_user(steno_mode_t mode, uint8_t chord[6]) { return true; } -__attribute__ ((weak)) -bool postprocess_steno_user(uint16_t keycode, keyrecord_t *record, steno_mode_t mode, uint8_t chord[6], int8_t pressed) { return true; } +__attribute__((weak)) bool postprocess_steno_user(uint16_t keycode, keyrecord_t *record, steno_mode_t mode, uint8_t chord[6], int8_t pressed) { return true; } -__attribute__ ((weak)) -bool process_steno_user(uint16_t keycode, keyrecord_t *record) { return true; } +__attribute__((weak)) bool process_steno_user(uint16_t keycode, keyrecord_t *record) { return true; } static void send_steno_chord(void) { - if (send_steno_chord_user(mode, chord)) { - switch(mode) { - case STENO_MODE_BOLT: - send_steno_state(BOLT_STATE_SIZE, false); - virtser_send(0); // terminating byte - break; - case STENO_MODE_GEMINI: - chord[0] |= 0x80; // Indicate start of packet - send_steno_state(GEMINI_STATE_SIZE, true); - break; + if (send_steno_chord_user(mode, chord)) { + switch (mode) { + case STENO_MODE_BOLT: + send_steno_state(BOLT_STATE_SIZE, false); + virtser_send(0); // terminating byte + break; + case STENO_MODE_GEMINI: + chord[0] |= 0x80; // Indicate start of packet + send_steno_state(GEMINI_STATE_SIZE, true); + break; + } } - } - steno_clear_state(); + steno_clear_state(); } -uint8_t *steno_get_state(void) { - return &state[0]; -} +uint8_t *steno_get_state(void) { return &state[0]; } -uint8_t *steno_get_chord(void) { - return &chord[0]; -} +uint8_t *steno_get_chord(void) { return &chord[0]; } static bool update_state_bolt(uint8_t key, bool press) { - uint8_t boltcode = pgm_read_byte(boltmap + key); - if (press) { - state[TXB_GET_GROUP(boltcode)] |= boltcode; - chord[TXB_GET_GROUP(boltcode)] |= boltcode; - } else { - state[TXB_GET_GROUP(boltcode)] &= ~boltcode; - } - return false; + uint8_t boltcode = pgm_read_byte(boltmap + key); + if (press) { + state[TXB_GET_GROUP(boltcode)] |= boltcode; + chord[TXB_GET_GROUP(boltcode)] |= boltcode; + } else { + state[TXB_GET_GROUP(boltcode)] &= ~boltcode; + } + return false; } static bool update_state_gemini(uint8_t key, bool press) { - int idx = key / 7; - uint8_t bit = 1 << (6 - (key % 7)); - if (press) { - state[idx] |= bit; - chord[idx] |= bit; - } else { - state[idx] &= ~bit; - } - return false; + int idx = key / 7; + uint8_t bit = 1 << (6 - (key % 7)); + if (press) { + state[idx] |= bit; + chord[idx] |= bit; + } else { + state[idx] &= ~bit; + } + return false; } bool process_steno(uint16_t keycode, keyrecord_t *record) { - switch (keycode) { - case QK_STENO_BOLT: - if (!process_steno_user(keycode, record)) { - return false; - } - if (IS_PRESSED(record->event)) { - steno_set_mode(STENO_MODE_BOLT); - } - return false; - - case QK_STENO_GEMINI: - if (!process_steno_user(keycode, record)) { - return false; - } - if (IS_PRESSED(record->event)) { - steno_set_mode(STENO_MODE_GEMINI); - } - return false; - - case STN__MIN...STN__MAX: - if (!process_steno_user(keycode, record)) { - return false; - } - switch(mode) { - case STENO_MODE_BOLT: - update_state_bolt(keycode - QK_STENO, IS_PRESSED(record->event)); - break; - case STENO_MODE_GEMINI: - update_state_gemini(keycode - QK_STENO, IS_PRESSED(record->event)); - break; - } - // allow postprocessing hooks - if (postprocess_steno_user(keycode, record, mode, chord, pressed)) { - if (IS_PRESSED(record->event)) { - ++pressed; - } else { - --pressed; - if (pressed <= 0) { - pressed = 0; - send_steno_chord(); - } - } - } - return false; - } - return true; + switch (keycode) { + case QK_STENO_BOLT: + if (!process_steno_user(keycode, record)) { + return false; + } + if (IS_PRESSED(record->event)) { + steno_set_mode(STENO_MODE_BOLT); + } + return false; + + case QK_STENO_GEMINI: + if (!process_steno_user(keycode, record)) { + return false; + } + if (IS_PRESSED(record->event)) { + steno_set_mode(STENO_MODE_GEMINI); + } + return false; + + case STN__MIN ... STN__MAX: + if (!process_steno_user(keycode, record)) { + return false; + } + switch (mode) { + case STENO_MODE_BOLT: + update_state_bolt(keycode - QK_STENO, IS_PRESSED(record->event)); + break; + case STENO_MODE_GEMINI: + update_state_gemini(keycode - QK_STENO, IS_PRESSED(record->event)); + break; + } + // allow postprocessing hooks + if (postprocess_steno_user(keycode, record, mode, chord, pressed)) { + if (IS_PRESSED(record->event)) { + ++pressed; + } else { + --pressed; + if (pressed <= 0) { + pressed = 0; + send_steno_chord(); + } + } + } + return false; + } + return true; } diff --git a/quantum/process_keycode/process_steno.h b/quantum/process_keycode/process_steno.h index 71f9731224..3675423728 100644 --- a/quantum/process_keycode/process_steno.h +++ b/quantum/process_keycode/process_steno.h @@ -19,14 +19,14 @@ #include "quantum.h" #if defined(STENO_ENABLE) && !defined(VIRTSER_ENABLE) - #error "must have virtser enabled to use steno" +# error "must have virtser enabled to use steno" #endif typedef enum { STENO_MODE_BOLT, STENO_MODE_GEMINI } steno_mode_t; -bool process_steno(uint16_t keycode, keyrecord_t *record); -void steno_init(void); -void steno_set_mode(steno_mode_t mode); +bool process_steno(uint16_t keycode, keyrecord_t *record); +void steno_init(void); +void steno_set_mode(steno_mode_t mode); uint8_t *steno_get_state(void); uint8_t *steno_get_chord(void); diff --git a/quantum/process_keycode/process_tap_dance.c b/quantum/process_keycode/process_tap_dance.c index 16d33dddee..c27fe48347 100644 --- a/quantum/process_keycode/process_tap_dance.c +++ b/quantum/process_keycode/process_tap_dance.c @@ -17,7 +17,7 @@ #include "action_tapping.h" #ifndef TAPPING_TERM -#define TAPPING_TERM 200 +# define TAPPING_TERM 200 #endif #ifndef NO_ACTION_ONESHOT @@ -25,191 +25,173 @@ uint8_t get_oneshot_mods(void); #endif static uint16_t last_td; -static int8_t highest_td = -1; +static int8_t highest_td = -1; -void qk_tap_dance_pair_on_each_tap (qk_tap_dance_state_t *state, void *user_data) { - qk_tap_dance_pair_t *pair = (qk_tap_dance_pair_t *)user_data; +void qk_tap_dance_pair_on_each_tap(qk_tap_dance_state_t *state, void *user_data) { + qk_tap_dance_pair_t *pair = (qk_tap_dance_pair_t *)user_data; - if (state->count == 2) { - register_code16 (pair->kc2); - state->finished = true; - } + if (state->count == 2) { + register_code16(pair->kc2); + state->finished = true; + } } -void qk_tap_dance_pair_finished (qk_tap_dance_state_t *state, void *user_data) { - qk_tap_dance_pair_t *pair = (qk_tap_dance_pair_t *)user_data; +void qk_tap_dance_pair_finished(qk_tap_dance_state_t *state, void *user_data) { + qk_tap_dance_pair_t *pair = (qk_tap_dance_pair_t *)user_data; - if (state->count == 1) { - register_code16 (pair->kc1); - } else if (state->count == 2) { - register_code16 (pair->kc2); - } + if (state->count == 1) { + register_code16(pair->kc1); + } else if (state->count == 2) { + register_code16(pair->kc2); + } } -void qk_tap_dance_pair_reset (qk_tap_dance_state_t *state, void *user_data) { - qk_tap_dance_pair_t *pair = (qk_tap_dance_pair_t *)user_data; +void qk_tap_dance_pair_reset(qk_tap_dance_state_t *state, void *user_data) { + qk_tap_dance_pair_t *pair = (qk_tap_dance_pair_t *)user_data; - if (state->count == 1) { - unregister_code16 (pair->kc1); - } else if (state->count == 2) { - unregister_code16 (pair->kc2); - } + if (state->count == 1) { + unregister_code16(pair->kc1); + } else if (state->count == 2) { + unregister_code16(pair->kc2); + } } -void qk_tap_dance_dual_role_on_each_tap (qk_tap_dance_state_t *state, void *user_data) { - qk_tap_dance_dual_role_t *pair = (qk_tap_dance_dual_role_t *)user_data; +void qk_tap_dance_dual_role_on_each_tap(qk_tap_dance_state_t *state, void *user_data) { + qk_tap_dance_dual_role_t *pair = (qk_tap_dance_dual_role_t *)user_data; - if (state->count == 2) { - layer_move (pair->layer); - state->finished = true; - } + if (state->count == 2) { + layer_move(pair->layer); + state->finished = true; + } } -void qk_tap_dance_dual_role_finished (qk_tap_dance_state_t *state, void *user_data) { - qk_tap_dance_dual_role_t *pair = (qk_tap_dance_dual_role_t *)user_data; +void qk_tap_dance_dual_role_finished(qk_tap_dance_state_t *state, void *user_data) { + qk_tap_dance_dual_role_t *pair = (qk_tap_dance_dual_role_t *)user_data; - if (state->count == 1) { - register_code16 (pair->kc); - } else if (state->count == 2) { - layer_move (pair->layer); - } + if (state->count == 1) { + register_code16(pair->kc); + } else if (state->count == 2) { + layer_move(pair->layer); + } } -void qk_tap_dance_dual_role_reset (qk_tap_dance_state_t *state, void *user_data) { - qk_tap_dance_dual_role_t *pair = (qk_tap_dance_dual_role_t *)user_data; +void qk_tap_dance_dual_role_reset(qk_tap_dance_state_t *state, void *user_data) { + qk_tap_dance_dual_role_t *pair = (qk_tap_dance_dual_role_t *)user_data; - if (state->count == 1) { - unregister_code16 (pair->kc); - } + if (state->count == 1) { + unregister_code16(pair->kc); + } } -static inline void _process_tap_dance_action_fn (qk_tap_dance_state_t *state, - void *user_data, - qk_tap_dance_user_fn_t fn) -{ - if (fn) { - fn(state, user_data); - } +static inline void _process_tap_dance_action_fn(qk_tap_dance_state_t *state, void *user_data, qk_tap_dance_user_fn_t fn) { + if (fn) { + fn(state, user_data); + } } -static inline void process_tap_dance_action_on_each_tap (qk_tap_dance_action_t *action) -{ - _process_tap_dance_action_fn (&action->state, action->user_data, action->fn.on_each_tap); -} +static inline void process_tap_dance_action_on_each_tap(qk_tap_dance_action_t *action) { _process_tap_dance_action_fn(&action->state, action->user_data, action->fn.on_each_tap); } -static inline void process_tap_dance_action_on_dance_finished (qk_tap_dance_action_t *action) -{ - if (action->state.finished) - return; - action->state.finished = true; - add_mods(action->state.oneshot_mods); - add_weak_mods(action->state.weak_mods); - send_keyboard_report(); - _process_tap_dance_action_fn (&action->state, action->user_data, action->fn.on_dance_finished); +static inline void process_tap_dance_action_on_dance_finished(qk_tap_dance_action_t *action) { + if (action->state.finished) return; + action->state.finished = true; + add_mods(action->state.oneshot_mods); + add_weak_mods(action->state.weak_mods); + send_keyboard_report(); + _process_tap_dance_action_fn(&action->state, action->user_data, action->fn.on_dance_finished); } -static inline void process_tap_dance_action_on_reset (qk_tap_dance_action_t *action) -{ - _process_tap_dance_action_fn (&action->state, action->user_data, action->fn.on_reset); - del_mods(action->state.oneshot_mods); - del_weak_mods(action->state.weak_mods); - send_keyboard_report(); +static inline void process_tap_dance_action_on_reset(qk_tap_dance_action_t *action) { + _process_tap_dance_action_fn(&action->state, action->user_data, action->fn.on_reset); + del_mods(action->state.oneshot_mods); + del_weak_mods(action->state.weak_mods); + send_keyboard_report(); } void preprocess_tap_dance(uint16_t keycode, keyrecord_t *record) { - qk_tap_dance_action_t *action; - - if (!record->event.pressed) - return; - - if (highest_td == -1) - return; - - for (int i = 0; i <= highest_td; i++) { - action = &tap_dance_actions[i]; - if (action->state.count) { - if (keycode == action->state.keycode && keycode == last_td) - continue; - action->state.interrupted = true; - action->state.interrupting_keycode = keycode; - process_tap_dance_action_on_dance_finished (action); - reset_tap_dance (&action->state); + qk_tap_dance_action_t *action; + + if (!record->event.pressed) return; + + if (highest_td == -1) return; + + for (int i = 0; i <= highest_td; i++) { + action = &tap_dance_actions[i]; + if (action->state.count) { + if (keycode == action->state.keycode && keycode == last_td) continue; + action->state.interrupted = true; + action->state.interrupting_keycode = keycode; + process_tap_dance_action_on_dance_finished(action); + reset_tap_dance(&action->state); + } } - } } bool process_tap_dance(uint16_t keycode, keyrecord_t *record) { - uint16_t idx = keycode - QK_TAP_DANCE; - qk_tap_dance_action_t *action; - - switch(keycode) { - case QK_TAP_DANCE ... QK_TAP_DANCE_MAX: - if ((int16_t)idx > highest_td) - highest_td = idx; - action = &tap_dance_actions[idx]; - - action->state.pressed = record->event.pressed; - if (record->event.pressed) { - action->state.keycode = keycode; - action->state.count++; - action->state.timer = timer_read(); + uint16_t idx = keycode - QK_TAP_DANCE; + qk_tap_dance_action_t *action; + + switch (keycode) { + case QK_TAP_DANCE ... QK_TAP_DANCE_MAX: + if ((int16_t)idx > highest_td) highest_td = idx; + action = &tap_dance_actions[idx]; + + action->state.pressed = record->event.pressed; + if (record->event.pressed) { + action->state.keycode = keycode; + action->state.count++; + action->state.timer = timer_read(); #ifndef NO_ACTION_ONESHOT - action->state.oneshot_mods = get_oneshot_mods(); + action->state.oneshot_mods = get_oneshot_mods(); #else - action->state.oneshot_mods = 0; + action->state.oneshot_mods = 0; #endif - action->state.weak_mods = get_mods(); - action->state.weak_mods |= get_weak_mods(); - process_tap_dance_action_on_each_tap (action); - - last_td = keycode; - } else { - if (action->state.count && action->state.finished) { - reset_tap_dance (&action->state); - } + action->state.weak_mods = get_mods(); + action->state.weak_mods |= get_weak_mods(); + process_tap_dance_action_on_each_tap(action); + + last_td = keycode; + } else { + if (action->state.count && action->state.finished) { + reset_tap_dance(&action->state); + } + } + + break; } - break; - } - - return true; + return true; } - - -void matrix_scan_tap_dance () { - if (highest_td == -1) - return; - uint16_t tap_user_defined; - - for (uint8_t i = 0; i <= highest_td; i++) { - qk_tap_dance_action_t *action = &tap_dance_actions[i]; - if(action->custom_tapping_term > 0 ) { - tap_user_defined = action->custom_tapping_term; - } - else{ - tap_user_defined = TAPPING_TERM; - } - if (action->state.count && timer_elapsed (action->state.timer) > tap_user_defined) { - process_tap_dance_action_on_dance_finished (action); - reset_tap_dance (&action->state); +void matrix_scan_tap_dance() { + if (highest_td == -1) return; + uint16_t tap_user_defined; + + for (uint8_t i = 0; i <= highest_td; i++) { + qk_tap_dance_action_t *action = &tap_dance_actions[i]; + if (action->custom_tapping_term > 0) { + tap_user_defined = action->custom_tapping_term; + } else { + tap_user_defined = TAPPING_TERM; + } + if (action->state.count && timer_elapsed(action->state.timer) > tap_user_defined) { + process_tap_dance_action_on_dance_finished(action); + reset_tap_dance(&action->state); + } } - } } -void reset_tap_dance (qk_tap_dance_state_t *state) { - qk_tap_dance_action_t *action; +void reset_tap_dance(qk_tap_dance_state_t *state) { + qk_tap_dance_action_t *action; - if (state->pressed) - return; + if (state->pressed) return; - action = &tap_dance_actions[state->keycode - QK_TAP_DANCE]; + action = &tap_dance_actions[state->keycode - QK_TAP_DANCE]; - process_tap_dance_action_on_reset (action); + process_tap_dance_action_on_reset(action); - state->count = 0; - state->interrupted = false; - state->finished = false; - state->interrupting_keycode = 0; - last_td = 0; + state->count = 0; + state->interrupted = false; + state->finished = false; + state->interrupting_keycode = 0; + last_td = 0; } diff --git a/quantum/process_keycode/process_tap_dance.h b/quantum/process_keycode/process_tap_dance.h index 00d70cbc59..b2d0cb8297 100644 --- a/quantum/process_keycode/process_tap_dance.h +++ b/quantum/process_keycode/process_tap_dance.h @@ -18,75 +18,60 @@ #ifdef TAP_DANCE_ENABLE -#include -#include - -typedef struct -{ - uint8_t count; - uint8_t oneshot_mods; - uint8_t weak_mods; - uint16_t keycode; - uint16_t interrupting_keycode; - uint16_t timer; - bool interrupted; - bool pressed; - bool finished; +# include +# include + +typedef struct { + uint8_t count; + uint8_t oneshot_mods; + uint8_t weak_mods; + uint16_t keycode; + uint16_t interrupting_keycode; + uint16_t timer; + bool interrupted; + bool pressed; + bool finished; } qk_tap_dance_state_t; -#define TD(n) (QK_TAP_DANCE | ((n) & 0xFF)) +# define TD(n) (QK_TAP_DANCE | ((n)&0xFF)) -typedef void (*qk_tap_dance_user_fn_t) (qk_tap_dance_state_t *state, void *user_data); +typedef void (*qk_tap_dance_user_fn_t)(qk_tap_dance_state_t *state, void *user_data); -typedef struct -{ - struct { - qk_tap_dance_user_fn_t on_each_tap; - qk_tap_dance_user_fn_t on_dance_finished; - qk_tap_dance_user_fn_t on_reset; - } fn; - qk_tap_dance_state_t state; - uint16_t custom_tapping_term; - void *user_data; +typedef struct { + struct { + qk_tap_dance_user_fn_t on_each_tap; + qk_tap_dance_user_fn_t on_dance_finished; + qk_tap_dance_user_fn_t on_reset; + } fn; + qk_tap_dance_state_t state; + uint16_t custom_tapping_term; + void * user_data; } qk_tap_dance_action_t; -typedef struct -{ - uint16_t kc1; - uint16_t kc2; +typedef struct { + uint16_t kc1; + uint16_t kc2; } qk_tap_dance_pair_t; -typedef struct -{ - uint16_t kc; - uint8_t layer; +typedef struct { + uint16_t kc; + uint8_t layer; } qk_tap_dance_dual_role_t; -#define ACTION_TAP_DANCE_DOUBLE(kc1, kc2) { \ - .fn = { qk_tap_dance_pair_on_each_tap, qk_tap_dance_pair_finished, qk_tap_dance_pair_reset }, \ - .user_data = (void *)&((qk_tap_dance_pair_t) { kc1, kc2 }), \ - } +# define ACTION_TAP_DANCE_DOUBLE(kc1, kc2) \ + { .fn = {qk_tap_dance_pair_on_each_tap, qk_tap_dance_pair_finished, qk_tap_dance_pair_reset}, .user_data = (void *)&((qk_tap_dance_pair_t){kc1, kc2}), } -#define ACTION_TAP_DANCE_DUAL_ROLE(kc, layer) { \ - .fn = { qk_tap_dance_dual_role_on_each_tap, qk_tap_dance_dual_role_finished, qk_tap_dance_dual_role_reset }, \ - .user_data = (void *)&((qk_tap_dance_dual_role_t) { kc, layer }), \ - } +# define ACTION_TAP_DANCE_DUAL_ROLE(kc, layer) \ + { .fn = {qk_tap_dance_dual_role_on_each_tap, qk_tap_dance_dual_role_finished, qk_tap_dance_dual_role_reset}, .user_data = (void *)&((qk_tap_dance_dual_role_t){kc, layer}), } -#define ACTION_TAP_DANCE_FN(user_fn) { \ - .fn = { NULL, user_fn, NULL }, \ - .user_data = NULL, \ - } +# define ACTION_TAP_DANCE_FN(user_fn) \ + { .fn = {NULL, user_fn, NULL}, .user_data = NULL, } -#define ACTION_TAP_DANCE_FN_ADVANCED(user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_dance_reset) { \ - .fn = { user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_dance_reset }, \ - .user_data = NULL, \ - } +# define ACTION_TAP_DANCE_FN_ADVANCED(user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_dance_reset) \ + { .fn = {user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_dance_reset}, .user_data = NULL, } -#define ACTION_TAP_DANCE_FN_ADVANCED_TIME(user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_dance_reset, tap_specific_tapping_term) { \ - .fn = { user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_dance_reset }, \ - .user_data = NULL, \ - .custom_tapping_term = tap_specific_tapping_term, \ - } +# define ACTION_TAP_DANCE_FN_ADVANCED_TIME(user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_dance_reset, tap_specific_tapping_term) \ + { .fn = {user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_dance_reset}, .user_data = NULL, .custom_tapping_term = tap_specific_tapping_term, } extern qk_tap_dance_action_t tap_dance_actions[]; @@ -94,20 +79,20 @@ extern qk_tap_dance_action_t tap_dance_actions[]; void preprocess_tap_dance(uint16_t keycode, keyrecord_t *record); bool process_tap_dance(uint16_t keycode, keyrecord_t *record); -void matrix_scan_tap_dance (void); -void reset_tap_dance (qk_tap_dance_state_t *state); +void matrix_scan_tap_dance(void); +void reset_tap_dance(qk_tap_dance_state_t *state); -void qk_tap_dance_pair_on_each_tap (qk_tap_dance_state_t *state, void *user_data); -void qk_tap_dance_pair_finished (qk_tap_dance_state_t *state, void *user_data); -void qk_tap_dance_pair_reset (qk_tap_dance_state_t *state, void *user_data); +void qk_tap_dance_pair_on_each_tap(qk_tap_dance_state_t *state, void *user_data); +void qk_tap_dance_pair_finished(qk_tap_dance_state_t *state, void *user_data); +void qk_tap_dance_pair_reset(qk_tap_dance_state_t *state, void *user_data); -void qk_tap_dance_dual_role_on_each_tap (qk_tap_dance_state_t *state, void *user_data); -void qk_tap_dance_dual_role_finished (qk_tap_dance_state_t *state, void *user_data); -void qk_tap_dance_dual_role_reset (qk_tap_dance_state_t *state, void *user_data); +void qk_tap_dance_dual_role_on_each_tap(qk_tap_dance_state_t *state, void *user_data); +void qk_tap_dance_dual_role_finished(qk_tap_dance_state_t *state, void *user_data); +void qk_tap_dance_dual_role_reset(qk_tap_dance_state_t *state, void *user_data); #else -#define TD(n) KC_NO +# define TD(n) KC_NO #endif diff --git a/quantum/process_keycode/process_terminal.c b/quantum/process_keycode/process_terminal.c index e791deffc1..f48f3d702d 100644 --- a/quantum/process_keycode/process_terminal.c +++ b/quantum/process_keycode/process_terminal.c @@ -21,62 +21,45 @@ #include #ifndef CMD_BUFF_SIZE - #define CMD_BUFF_SIZE 5 +# define CMD_BUFF_SIZE 5 #endif - bool terminal_enabled = false; -char buffer[80] = ""; +char buffer[80] = ""; char cmd_buffer[CMD_BUFF_SIZE][80]; -bool cmd_buffer_enabled = true; //replace with ifdef? -char newline[2] = "\n"; +bool cmd_buffer_enabled = true; // replace with ifdef? +char newline[2] = "\n"; char arguments[6][20]; bool firstTime = true; -short int current_cmd_buffer_pos = 0; //used for up/down arrows - keeps track of where you are in the command buffer +short int current_cmd_buffer_pos = 0; // used for up/down arrows - keeps track of where you are in the command buffer -__attribute__ ((weak)) -const char terminal_prompt[8] = "> "; +__attribute__((weak)) const char terminal_prompt[8] = "> "; #ifdef AUDIO_ENABLE - #ifndef TERMINAL_SONG - #define TERMINAL_SONG SONG(TERMINAL_SOUND) - #endif - float terminal_song[][2] = TERMINAL_SONG; - #define TERMINAL_BELL() PLAY_SONG(terminal_song) +# ifndef TERMINAL_SONG +# define TERMINAL_SONG SONG(TERMINAL_SOUND) +# endif +float terminal_song[][2] = TERMINAL_SONG; +# define TERMINAL_BELL() PLAY_SONG(terminal_song) #else - #define TERMINAL_BELL() +# define TERMINAL_BELL() #endif -__attribute__ ((weak)) -const char keycode_to_ascii_lut[58] = { - 0, 0, 0, 0, - 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', - 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', - '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 0, 0, 0, '\t', - ' ', '-', '=', '[', ']', '\\', 0, ';', '\'', '`', ',', '.', '/' -}; - -__attribute__ ((weak)) -const char shifted_keycode_to_ascii_lut[58] = { - 0, 0, 0, 0, - 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', - 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', - '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', 0, 0, 0, '\t', - ' ', '_', '+', '{', '}', '|', 0, ':', '\'', '~', '<', '>', '?' -}; +__attribute__((weak)) const char keycode_to_ascii_lut[58] = {0, 0, 0, 0, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 0, 0, 0, '\t', ' ', '-', '=', '[', ']', '\\', 0, ';', '\'', '`', ',', '.', '/'}; + +__attribute__((weak)) const char shifted_keycode_to_ascii_lut[58] = {0, 0, 0, 0, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', 0, 0, 0, '\t', ' ', '_', '+', '{', '}', '|', 0, ':', '\'', '~', '<', '>', '?'}; struct stringcase { - char* string; + char *string; void (*func)(void); } typedef stringcase; void enable_terminal(void) { terminal_enabled = true; strcpy(buffer, ""); - memset(cmd_buffer,0,CMD_BUFF_SIZE * 80); - for (int i = 0; i < 6; i++) - strcpy(arguments[i], ""); + memset(cmd_buffer, 0, CMD_BUFF_SIZE * 80); + for (int i = 0; i < 6; i++) strcpy(arguments[i], ""); // select all text to start over // SEND_STRING(SS_LCTRL("a")); send_string(terminal_prompt); @@ -88,41 +71,41 @@ void disable_terminal(void) { } void push_to_cmd_buffer(void) { -if (cmd_buffer_enabled) { - if (cmd_buffer == NULL) { - return; - } else { - if (firstTime) { - firstTime = false; - strcpy(cmd_buffer[0],buffer); - return; - } + if (cmd_buffer_enabled) { + if (cmd_buffer == NULL) { + return; + } else { + if (firstTime) { + firstTime = false; + strcpy(cmd_buffer[0], buffer); + return; + } - for (int i= CMD_BUFF_SIZE - 1;i > 0 ;--i) { - strncpy(cmd_buffer[i],cmd_buffer[i-1],80); - } + for (int i = CMD_BUFF_SIZE - 1; i > 0; --i) { + strncpy(cmd_buffer[i], cmd_buffer[i - 1], 80); + } - strcpy(cmd_buffer[0],buffer); + strcpy(cmd_buffer[0], buffer); - return; + return; + } } - } } void terminal_about(void) { SEND_STRING("QMK Firmware\n"); SEND_STRING(" v"); SEND_STRING(QMK_VERSION); - SEND_STRING("\n"SS_TAP(X_HOME)" Built: "); + SEND_STRING("\n" SS_TAP(X_HOME) " Built: "); SEND_STRING(QMK_BUILDDATE); send_string(newline); - #ifdef TERMINAL_HELP - if (strlen(arguments[1]) != 0) { - SEND_STRING("You entered: "); - send_string(arguments[1]); - send_string(newline); - } - #endif +#ifdef TERMINAL_HELP + if (strlen(arguments[1]) != 0) { + SEND_STRING("You entered: "); + send_string(arguments[1]); + send_string(newline); + } +#endif } void terminal_help(void); @@ -131,11 +114,11 @@ extern const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS]; void terminal_keycode(void) { if (strlen(arguments[1]) != 0 && strlen(arguments[2]) != 0 && strlen(arguments[3]) != 0) { - char keycode_dec[5]; - char keycode_hex[5]; - uint16_t layer = strtol(arguments[1], (char **)NULL, 10); - uint16_t row = strtol(arguments[2], (char **)NULL, 10); - uint16_t col = strtol(arguments[3], (char **)NULL, 10); + char keycode_dec[5]; + char keycode_hex[5]; + uint16_t layer = strtol(arguments[1], (char **)NULL, 10); + uint16_t row = strtol(arguments[2], (char **)NULL, 10); + uint16_t col = strtol(arguments[3], (char **)NULL, 10); uint16_t keycode = pgm_read_word(&keymaps[layer][row][col]); itoa(keycode, keycode_dec, 10); itoa(keycode, keycode_hex, 16); @@ -145,9 +128,9 @@ void terminal_keycode(void) { send_string(keycode_dec); SEND_STRING(")\n"); } else { - #ifdef TERMINAL_HELP - SEND_STRING("usage: keycode \n"); - #endif +#ifdef TERMINAL_HELP + SEND_STRING("usage: keycode \n"); +#endif } } @@ -157,53 +140,44 @@ void terminal_keymap(void) { for (int r = 0; r < MATRIX_ROWS; r++) { for (int c = 0; c < MATRIX_COLS; c++) { uint16_t keycode = pgm_read_word(&keymaps[layer][r][c]); - char keycode_s[8]; + char keycode_s[8]; sprintf(keycode_s, "0x%04x,", keycode); send_string(keycode_s); } send_string(newline); } } else { - #ifdef TERMINAL_HELP - SEND_STRING("usage: keymap \n"); - #endif +#ifdef TERMINAL_HELP + SEND_STRING("usage: keymap \n"); +#endif } } void print_cmd_buff(void) { - /* without the below wait, a race condition can occur wherein the - buffer can be printed before it has been fully moved */ - wait_ms(250); - for(int i=0;istring); SEND_STRING(" "); } @@ -211,7 +185,7 @@ void terminal_help(void) { } void command_not_found(void) { - wait_ms(50); //sometimes buffer isnt grabbed quick enough + wait_ms(50); // sometimes buffer isnt grabbed quick enough SEND_STRING("command \""); send_string(buffer); SEND_STRING("\" not found\n"); @@ -221,9 +195,9 @@ void process_terminal_command(void) { // we capture return bc of the order of events, so we need to manually send a newline send_string(newline); - char * pch; + char * pch; uint8_t i = 0; - pch = strtok(buffer, " "); + pch = strtok(buffer, " "); while (pch != NULL) { strcpy(arguments[i], pch); pch = strtok(NULL, " "); @@ -231,38 +205,32 @@ void process_terminal_command(void) { } bool command_found = false; - for( stringcase* case_p = terminal_cases; case_p != terminal_cases + sizeof( terminal_cases ) / sizeof( terminal_cases[0] ); case_p++ ) { - if( 0 == strcmp( case_p->string, buffer ) ) { + for (stringcase *case_p = terminal_cases; case_p != terminal_cases + sizeof(terminal_cases) / sizeof(terminal_cases[0]); case_p++) { + if (0 == strcmp(case_p->string, buffer)) { command_found = true; (*case_p->func)(); break; } } - if (!command_found) - command_not_found(); + if (!command_found) command_not_found(); if (terminal_enabled) { strcpy(buffer, ""); - for (int i = 0; i < 6; i++) - strcpy(arguments[i], ""); + for (int i = 0; i < 6; i++) strcpy(arguments[i], ""); SEND_STRING(SS_TAP(X_HOME)); send_string(terminal_prompt); } } void check_pos(void) { - if (current_cmd_buffer_pos >= CMD_BUFF_SIZE) { //if over the top, move it back down to the top of the buffer so you can climb back down... - current_cmd_buffer_pos = CMD_BUFF_SIZE - 1; - } else if (current_cmd_buffer_pos < 0) { //...and if you fall under the bottom of the buffer, reset back to 0 so you can climb back up - current_cmd_buffer_pos = 0; - } + if (current_cmd_buffer_pos >= CMD_BUFF_SIZE) { // if over the top, move it back down to the top of the buffer so you can climb back down... + current_cmd_buffer_pos = CMD_BUFF_SIZE - 1; + } else if (current_cmd_buffer_pos < 0) { //...and if you fall under the bottom of the buffer, reset back to 0 so you can climb back up + current_cmd_buffer_pos = 0; + } } - - - bool process_terminal(uint16_t keycode, keyrecord_t *record) { - if (keycode == TERM_ON && record->event.pressed) { enable_terminal(); return false; @@ -280,59 +248,66 @@ bool process_terminal(uint16_t keycode, keyrecord_t *record) { if (keycode < 256) { uint8_t str_len; - char char_to_add; + char char_to_add; switch (keycode) { case KC_ENTER: case KC_KP_ENTER: push_to_cmd_buffer(); current_cmd_buffer_pos = 0; process_terminal_command(); - return false; break; + return false; + break; case KC_ESC: SEND_STRING("\n"); enable_terminal(); - return false; break; + return false; + break; case KC_BSPC: str_len = strlen(buffer); if (str_len > 0) { - buffer[str_len-1] = 0; + buffer[str_len - 1] = 0; return true; } else { TERMINAL_BELL(); return false; - } break; + } + break; case KC_LEFT: - return false; break; + return false; + break; case KC_RIGHT: - return false; break; - case KC_UP: // 0 = recent - check_pos(); //check our current buffer position is valid - if (current_cmd_buffer_pos <= CMD_BUFF_SIZE - 1) { //once we get to the top, dont do anything - str_len = strlen(buffer); - for(int i= 0;i < str_len ;++i) { - send_string(SS_TAP(X_BSPACE)); //clear w/e is on the line already - //process_terminal(KC_BSPC,record); - } - strncpy(buffer,cmd_buffer[current_cmd_buffer_pos],80); + return false; + break; + case KC_UP: // 0 = recent + check_pos(); // check our current buffer position is valid + if (current_cmd_buffer_pos <= CMD_BUFF_SIZE - 1) { // once we get to the top, dont do anything + str_len = strlen(buffer); + for (int i = 0; i < str_len; ++i) { + send_string(SS_TAP(X_BSPACE)); // clear w/e is on the line already + // process_terminal(KC_BSPC,record); + } + strncpy(buffer, cmd_buffer[current_cmd_buffer_pos], 80); - send_string(buffer); - ++current_cmd_buffer_pos; //get ready to access the above cmd if up/down is pressed again - } - return false; break; + send_string(buffer); + ++current_cmd_buffer_pos; // get ready to access the above cmd if up/down is pressed again + } + return false; + break; case KC_DOWN: - check_pos(); - if (current_cmd_buffer_pos >= 0) { //once we get to the bottom, dont do anything - str_len = strlen(buffer); - for(int i= 0;i < str_len ;++i) { - send_string(SS_TAP(X_BSPACE)); //clear w/e is on the line already - //process_terminal(KC_BSPC,record); - } - strncpy(buffer,cmd_buffer[current_cmd_buffer_pos],79); - - send_string(buffer); - --current_cmd_buffer_pos; //get ready to access the above cmd if down/up is pressed again + check_pos(); + if (current_cmd_buffer_pos >= 0) { // once we get to the bottom, dont do anything + str_len = strlen(buffer); + for (int i = 0; i < str_len; ++i) { + send_string(SS_TAP(X_BSPACE)); // clear w/e is on the line already + // process_terminal(KC_BSPC,record); + } + strncpy(buffer, cmd_buffer[current_cmd_buffer_pos], 79); + + send_string(buffer); + --current_cmd_buffer_pos; // get ready to access the above cmd if down/up is pressed again } - return false; break; + return false; + break; default: if (keycode <= 58) { char_to_add = 0; @@ -344,11 +319,9 @@ bool process_terminal(uint16_t keycode, keyrecord_t *record) { if (char_to_add != 0) { strncat(buffer, &char_to_add, 1); } - } break; + } + break; } - - - } } return true; diff --git a/quantum/process_keycode/process_terminal.h b/quantum/process_keycode/process_terminal.h index d945949a41..8426f442b6 100644 --- a/quantum/process_keycode/process_terminal.h +++ b/quantum/process_keycode/process_terminal.h @@ -22,6 +22,6 @@ extern const char keycode_to_ascii_lut[58]; extern const char shifted_keycode_to_ascii_lut[58]; extern const char terminal_prompt[8]; -bool process_terminal(uint16_t keycode, keyrecord_t *record); +bool process_terminal(uint16_t keycode, keyrecord_t *record); #endif \ No newline at end of file diff --git a/quantum/process_keycode/process_ucis.c b/quantum/process_keycode/process_ucis.c index fd4508b535..024077317f 100644 --- a/quantum/process_keycode/process_ucis.c +++ b/quantum/process_keycode/process_ucis.c @@ -19,144 +19,133 @@ qk_ucis_state_t qk_ucis_state; void qk_ucis_start(void) { - qk_ucis_state.count = 0; - qk_ucis_state.in_progress = true; + qk_ucis_state.count = 0; + qk_ucis_state.in_progress = true; - qk_ucis_start_user(); + qk_ucis_start_user(); } -__attribute__((weak)) -void qk_ucis_start_user(void) { - unicode_input_start(); - register_hex(0x2328); - unicode_input_finish(); +__attribute__((weak)) void qk_ucis_start_user(void) { + unicode_input_start(); + register_hex(0x2328); + unicode_input_finish(); } -__attribute__((weak)) -void qk_ucis_success(uint8_t symbol_index) { -} +__attribute__((weak)) void qk_ucis_success(uint8_t symbol_index) {} static bool is_uni_seq(char *seq) { - uint8_t i; + uint8_t i; - for (i = 0; seq[i]; i++) { - uint16_t code; - if (('1' <= seq[i]) && (seq[i] <= '0')) - code = seq[i] - '1' + KC_1; - else - code = seq[i] - 'a' + KC_A; + for (i = 0; seq[i]; i++) { + uint16_t code; + if (('1' <= seq[i]) && (seq[i] <= '0')) + code = seq[i] - '1' + KC_1; + else + code = seq[i] - 'a' + KC_A; - if (i > qk_ucis_state.count || qk_ucis_state.codes[i] != code) - return false; - } + if (i > qk_ucis_state.count || qk_ucis_state.codes[i] != code) return false; + } - return (qk_ucis_state.codes[i] == KC_ENT || - qk_ucis_state.codes[i] == KC_SPC); + return (qk_ucis_state.codes[i] == KC_ENT || qk_ucis_state.codes[i] == KC_SPC); } -__attribute__((weak)) -void qk_ucis_symbol_fallback (void) { - for (uint8_t i = 0; i < qk_ucis_state.count - 1; i++) { - uint8_t code = qk_ucis_state.codes[i]; - register_code(code); - unregister_code(code); - wait_ms(UNICODE_TYPE_DELAY); - } +__attribute__((weak)) void qk_ucis_symbol_fallback(void) { + for (uint8_t i = 0; i < qk_ucis_state.count - 1; i++) { + uint8_t code = qk_ucis_state.codes[i]; + register_code(code); + unregister_code(code); + wait_ms(UNICODE_TYPE_DELAY); + } } -__attribute__((weak)) -void qk_ucis_cancel(void) { -} +__attribute__((weak)) void qk_ucis_cancel(void) {} void register_ucis(const char *hex) { - for(int i = 0; hex[i]; i++) { - uint8_t kc = 0; - char c = hex[i]; - - switch (c) { - case '0': - kc = KC_0; - break; - case '1' ... '9': - kc = c - '1' + KC_1; - break; - case 'a' ... 'f': - kc = c - 'a' + KC_A; - break; - case 'A' ... 'F': - kc = c - 'A' + KC_A; - break; + for (int i = 0; hex[i]; i++) { + uint8_t kc = 0; + char c = hex[i]; + + switch (c) { + case '0': + kc = KC_0; + break; + case '1' ... '9': + kc = c - '1' + KC_1; + break; + case 'a' ... 'f': + kc = c - 'a' + KC_A; + break; + case 'A' ... 'F': + kc = c - 'A' + KC_A; + break; + } + + if (kc) { + register_code(kc); + unregister_code(kc); + wait_ms(UNICODE_TYPE_DELAY); + } } - - if (kc) { - register_code (kc); - unregister_code (kc); - wait_ms (UNICODE_TYPE_DELAY); - } - } } -bool process_ucis (uint16_t keycode, keyrecord_t *record) { - uint8_t i; +bool process_ucis(uint16_t keycode, keyrecord_t *record) { + uint8_t i; - if (!qk_ucis_state.in_progress) - return true; + if (!qk_ucis_state.in_progress) return true; - if (qk_ucis_state.count >= UCIS_MAX_SYMBOL_LENGTH && - !(keycode == KC_BSPC || keycode == KC_ESC || keycode == KC_SPC || keycode == KC_ENT)) { - return false; - } - - if (!record->event.pressed) - return true; - - qk_ucis_state.codes[qk_ucis_state.count] = keycode; - qk_ucis_state.count++; - - if (keycode == KC_BSPC) { - if (qk_ucis_state.count >= 2) { - qk_ucis_state.count -= 2; - return true; - } else { - qk_ucis_state.count--; - return false; + if (qk_ucis_state.count >= UCIS_MAX_SYMBOL_LENGTH && !(keycode == KC_BSPC || keycode == KC_ESC || keycode == KC_SPC || keycode == KC_ENT)) { + return false; } - } - if (keycode == KC_ENT || keycode == KC_SPC || keycode == KC_ESC) { - bool symbol_found = false; + if (!record->event.pressed) return true; - for (i = qk_ucis_state.count; i > 0; i--) { - register_code (KC_BSPC); - unregister_code (KC_BSPC); - wait_ms(UNICODE_TYPE_DELAY); - } - - if (keycode == KC_ESC) { - qk_ucis_state.in_progress = false; - qk_ucis_cancel(); - return false; - } + qk_ucis_state.codes[qk_ucis_state.count] = keycode; + qk_ucis_state.count++; - unicode_input_start(); - for (i = 0; ucis_symbol_table[i].symbol; i++) { - if (is_uni_seq (ucis_symbol_table[i].symbol)) { - symbol_found = true; - register_ucis(ucis_symbol_table[i].code + 2); - break; - } - } - if (!symbol_found) { - qk_ucis_symbol_fallback(); + if (keycode == KC_BSPC) { + if (qk_ucis_state.count >= 2) { + qk_ucis_state.count -= 2; + return true; + } else { + qk_ucis_state.count--; + return false; + } } - unicode_input_finish(); - if (symbol_found) { - qk_ucis_success(i); + if (keycode == KC_ENT || keycode == KC_SPC || keycode == KC_ESC) { + bool symbol_found = false; + + for (i = qk_ucis_state.count; i > 0; i--) { + register_code(KC_BSPC); + unregister_code(KC_BSPC); + wait_ms(UNICODE_TYPE_DELAY); + } + + if (keycode == KC_ESC) { + qk_ucis_state.in_progress = false; + qk_ucis_cancel(); + return false; + } + + unicode_input_start(); + for (i = 0; ucis_symbol_table[i].symbol; i++) { + if (is_uni_seq(ucis_symbol_table[i].symbol)) { + symbol_found = true; + register_ucis(ucis_symbol_table[i].code + 2); + break; + } + } + if (!symbol_found) { + qk_ucis_symbol_fallback(); + } + unicode_input_finish(); + + if (symbol_found) { + qk_ucis_success(i); + } + + qk_ucis_state.in_progress = false; + return false; } - - qk_ucis_state.in_progress = false; - return false; - } - return true; + return true; } diff --git a/quantum/process_keycode/process_ucis.h b/quantum/process_keycode/process_ucis.h index b114d839ab..0f93a198bb 100644 --- a/quantum/process_keycode/process_ucis.h +++ b/quantum/process_keycode/process_ucis.h @@ -20,30 +20,34 @@ #include "process_unicode_common.h" #ifndef UCIS_MAX_SYMBOL_LENGTH -#define UCIS_MAX_SYMBOL_LENGTH 32 +# define UCIS_MAX_SYMBOL_LENGTH 32 #endif typedef struct { - char *symbol; - char *code; + char *symbol; + char *code; } qk_ucis_symbol_t; typedef struct { - uint8_t count; - uint16_t codes[UCIS_MAX_SYMBOL_LENGTH]; - bool in_progress:1; + uint8_t count; + uint16_t codes[UCIS_MAX_SYMBOL_LENGTH]; + bool in_progress : 1; } qk_ucis_state_t; extern qk_ucis_state_t qk_ucis_state; -#define UCIS_TABLE(...) {__VA_ARGS__, {NULL, NULL}} -#define UCIS_SYM(name, code) {name, #code} +#define UCIS_TABLE(...) \ + { \ + __VA_ARGS__, { NULL, NULL } \ + } +#define UCIS_SYM(name, code) \ + { name, #code } extern const qk_ucis_symbol_t ucis_symbol_table[]; void qk_ucis_start(void); void qk_ucis_start_user(void); -void qk_ucis_symbol_fallback (void); +void qk_ucis_symbol_fallback(void); void qk_ucis_success(uint8_t symbol_index); void register_ucis(const char *hex); -bool process_ucis (uint16_t keycode, keyrecord_t *record); +bool process_ucis(uint16_t keycode, keyrecord_t *record); diff --git a/quantum/process_keycode/process_unicode.c b/quantum/process_keycode/process_unicode.c index 2c914013ac..18a1d8bc1f 100644 --- a/quantum/process_keycode/process_unicode.c +++ b/quantum/process_keycode/process_unicode.c @@ -19,10 +19,10 @@ #include "eeprom.h" bool process_unicode(uint16_t keycode, keyrecord_t *record) { - if (keycode >= QK_UNICODE && keycode <= QK_UNICODE_MAX && record->event.pressed) { - unicode_input_start(); - register_hex(keycode & 0x7FFF); - unicode_input_finish(); - } - return true; + if (keycode >= QK_UNICODE && keycode <= QK_UNICODE_MAX && record->event.pressed) { + unicode_input_start(); + register_hex(keycode & 0x7FFF); + unicode_input_finish(); + } + return true; } diff --git a/quantum/process_keycode/process_unicode_common.c b/quantum/process_keycode/process_unicode_common.c index 21ac2291db..94383f19b7 100644 --- a/quantum/process_keycode/process_unicode_common.c +++ b/quantum/process_keycode/process_unicode_common.c @@ -23,220 +23,215 @@ unicode_config_t unicode_config; uint8_t unicode_saved_mods; #if UNICODE_SELECTED_MODES != -1 -static uint8_t selected[] = { UNICODE_SELECTED_MODES }; +static uint8_t selected[] = {UNICODE_SELECTED_MODES}; static uint8_t selected_count = sizeof selected / sizeof *selected; static uint8_t selected_index; #endif void unicode_input_mode_init(void) { - unicode_config.raw = eeprom_read_byte(EECONFIG_UNICODEMODE); + unicode_config.raw = eeprom_read_byte(EECONFIG_UNICODEMODE); #if UNICODE_SELECTED_MODES != -1 - #if UNICODE_CYCLE_PERSIST - // Find input_mode in selected modes - uint8_t i; - for (i = 0; i < selected_count; i++) { - if (selected[i] == unicode_config.input_mode) { - selected_index = i; - break; +# if UNICODE_CYCLE_PERSIST + // Find input_mode in selected modes + uint8_t i; + for (i = 0; i < selected_count; i++) { + if (selected[i] == unicode_config.input_mode) { + selected_index = i; + break; + } } - } - if (i == selected_count) { - // Not found: input_mode isn't selected, change to one that is + if (i == selected_count) { + // Not found: input_mode isn't selected, change to one that is + unicode_config.input_mode = selected[selected_index = 0]; + } +# else + // Always change to the first selected input mode unicode_config.input_mode = selected[selected_index = 0]; - } - #else - // Always change to the first selected input mode - unicode_config.input_mode = selected[selected_index = 0]; - #endif +# endif #endif - dprintf("Unicode input mode init to: %u\n", unicode_config.input_mode); + dprintf("Unicode input mode init to: %u\n", unicode_config.input_mode); } -uint8_t get_unicode_input_mode(void) { - return unicode_config.input_mode; -} +uint8_t get_unicode_input_mode(void) { return unicode_config.input_mode; } void set_unicode_input_mode(uint8_t mode) { - unicode_config.input_mode = mode; - persist_unicode_input_mode(); - dprintf("Unicode input mode set to: %u\n", unicode_config.input_mode); + unicode_config.input_mode = mode; + persist_unicode_input_mode(); + dprintf("Unicode input mode set to: %u\n", unicode_config.input_mode); } void cycle_unicode_input_mode(uint8_t offset) { #if UNICODE_SELECTED_MODES != -1 - selected_index = (selected_index + offset) % selected_count; - unicode_config.input_mode = selected[selected_index]; - #if UNICODE_CYCLE_PERSIST - persist_unicode_input_mode(); - #endif - dprintf("Unicode input mode cycle to: %u\n", unicode_config.input_mode); + selected_index = (selected_index + offset) % selected_count; + unicode_config.input_mode = selected[selected_index]; +# if UNICODE_CYCLE_PERSIST + persist_unicode_input_mode(); +# endif + dprintf("Unicode input mode cycle to: %u\n", unicode_config.input_mode); #endif } -void persist_unicode_input_mode(void) { - eeprom_update_byte(EECONFIG_UNICODEMODE, unicode_config.input_mode); -} +void persist_unicode_input_mode(void) { eeprom_update_byte(EECONFIG_UNICODEMODE, unicode_config.input_mode); } + +__attribute__((weak)) void unicode_input_start(void) { + unicode_saved_mods = get_mods(); // Save current mods + clear_mods(); // Unregister mods to start from a clean state + + switch (unicode_config.input_mode) { + case UC_OSX: + register_code(UNICODE_KEY_OSX); + break; + case UC_LNX: + tap_code16(UNICODE_KEY_LNX); + break; + case UC_WIN: + register_code(KC_LALT); + tap_code(KC_PPLS); + break; + case UC_WINC: + tap_code(UNICODE_KEY_WINC); + tap_code(KC_U); + break; + } -__attribute__((weak)) -void unicode_input_start(void) { - unicode_saved_mods = get_mods(); // Save current mods - clear_mods(); // Unregister mods to start from a clean state - - switch (unicode_config.input_mode) { - case UC_OSX: - register_code(UNICODE_KEY_OSX); - break; - case UC_LNX: - tap_code16(UNICODE_KEY_LNX); - break; - case UC_WIN: - register_code(KC_LALT); - tap_code(KC_PPLS); - break; - case UC_WINC: - tap_code(UNICODE_KEY_WINC); - tap_code(KC_U); - break; - } - - wait_ms(UNICODE_TYPE_DELAY); + wait_ms(UNICODE_TYPE_DELAY); } -__attribute__((weak)) -void unicode_input_finish(void) { - switch (unicode_config.input_mode) { - case UC_OSX: - unregister_code(UNICODE_KEY_OSX); - break; - case UC_LNX: - tap_code(KC_SPC); - break; - case UC_WIN: - unregister_code(KC_LALT); - break; - case UC_WINC: - tap_code(KC_ENTER); - break; - } - - set_mods(unicode_saved_mods); // Reregister previously set mods +__attribute__((weak)) void unicode_input_finish(void) { + switch (unicode_config.input_mode) { + case UC_OSX: + unregister_code(UNICODE_KEY_OSX); + break; + case UC_LNX: + tap_code(KC_SPC); + break; + case UC_WIN: + unregister_code(KC_LALT); + break; + case UC_WINC: + tap_code(KC_ENTER); + break; + } + + set_mods(unicode_saved_mods); // Reregister previously set mods } -__attribute__((weak)) -void unicode_input_cancel(void) { - switch (unicode_config.input_mode) { - case UC_OSX: - unregister_code(UNICODE_KEY_OSX); - break; - case UC_LNX: - case UC_WINC: - tap_code(KC_ESC); - break; - case UC_WIN: - unregister_code(KC_LALT); - break; - } - - set_mods(unicode_saved_mods); // Reregister previously set mods +__attribute__((weak)) void unicode_input_cancel(void) { + switch (unicode_config.input_mode) { + case UC_OSX: + unregister_code(UNICODE_KEY_OSX); + break; + case UC_LNX: + case UC_WINC: + tap_code(KC_ESC); + break; + case UC_WIN: + unregister_code(KC_LALT); + break; + } + + set_mods(unicode_saved_mods); // Reregister previously set mods } -__attribute__((weak)) -uint16_t hex_to_keycode(uint8_t hex) { - if (hex == 0x0) { - return KC_0; - } else if (hex < 0xA) { - return KC_1 + (hex - 0x1); - } else { - return KC_A + (hex - 0xA); - } +__attribute__((weak)) uint16_t hex_to_keycode(uint8_t hex) { + if (hex == 0x0) { + return KC_0; + } else if (hex < 0xA) { + return KC_1 + (hex - 0x1); + } else { + return KC_A + (hex - 0xA); + } } void register_hex(uint16_t hex) { - for(int i = 3; i >= 0; i--) { - uint8_t digit = ((hex >> (i*4)) & 0xF); - tap_code(hex_to_keycode(digit)); - } + for (int i = 3; i >= 0; i--) { + uint8_t digit = ((hex >> (i * 4)) & 0xF); + tap_code(hex_to_keycode(digit)); + } } void send_unicode_hex_string(const char *str) { - if (!str) { return; } - - while (*str) { - // Find the next code point (token) in the string - for (; *str == ' '; str++); - size_t n = strcspn(str, " "); // Length of the current token - char code_point[n+1]; - strncpy(code_point, str, n); - code_point[n] = '\0'; // Make sure it's null-terminated - - // Normalize the code point: make all hex digits lowercase - for (char *p = code_point; *p; p++) { - *p = tolower((unsigned char)*p); + if (!str) { + return; } - // Send the code point as a Unicode input string - unicode_input_start(); - send_string(code_point); - unicode_input_finish(); - - str += n; // Move to the first ' ' (or '\0') after the current token - } + while (*str) { + // Find the next code point (token) in the string + for (; *str == ' '; str++) + ; + size_t n = strcspn(str, " "); // Length of the current token + char code_point[n + 1]; + strncpy(code_point, str, n); + code_point[n] = '\0'; // Make sure it's null-terminated + + // Normalize the code point: make all hex digits lowercase + for (char *p = code_point; *p; p++) { + *p = tolower((unsigned char)*p); + } + + // Send the code point as a Unicode input string + unicode_input_start(); + send_string(code_point); + unicode_input_finish(); + + str += n; // Move to the first ' ' (or '\0') after the current token + } } bool process_unicode_common(uint16_t keycode, keyrecord_t *record) { - if (record->event.pressed) { - switch (keycode) { - case UNICODE_MODE_FORWARD: - cycle_unicode_input_mode(+1); - break; - case UNICODE_MODE_REVERSE: - cycle_unicode_input_mode(-1); - break; - - case UNICODE_MODE_OSX: - set_unicode_input_mode(UC_OSX); + if (record->event.pressed) { + switch (keycode) { + case UNICODE_MODE_FORWARD: + cycle_unicode_input_mode(+1); + break; + case UNICODE_MODE_REVERSE: + cycle_unicode_input_mode(-1); + break; + + case UNICODE_MODE_OSX: + set_unicode_input_mode(UC_OSX); #if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_OSX) - static float song_osx[][2] = UNICODE_SONG_OSX; - PLAY_SONG(song_osx); + static float song_osx[][2] = UNICODE_SONG_OSX; + PLAY_SONG(song_osx); #endif - break; - case UNICODE_MODE_LNX: - set_unicode_input_mode(UC_LNX); + break; + case UNICODE_MODE_LNX: + set_unicode_input_mode(UC_LNX); #if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_LNX) - static float song_lnx[][2] = UNICODE_SONG_LNX; - PLAY_SONG(song_lnx); + static float song_lnx[][2] = UNICODE_SONG_LNX; + PLAY_SONG(song_lnx); #endif - break; - case UNICODE_MODE_WIN: - set_unicode_input_mode(UC_WIN); + break; + case UNICODE_MODE_WIN: + set_unicode_input_mode(UC_WIN); #if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_WIN) - static float song_win[][2] = UNICODE_SONG_WIN; - PLAY_SONG(song_win); + static float song_win[][2] = UNICODE_SONG_WIN; + PLAY_SONG(song_win); #endif - break; - case UNICODE_MODE_BSD: - set_unicode_input_mode(UC_BSD); + break; + case UNICODE_MODE_BSD: + set_unicode_input_mode(UC_BSD); #if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_BSD) - static float song_bsd[][2] = UNICODE_SONG_BSD; - PLAY_SONG(song_bsd); + static float song_bsd[][2] = UNICODE_SONG_BSD; + PLAY_SONG(song_bsd); #endif - break; - case UNICODE_MODE_WINC: - set_unicode_input_mode(UC_WINC); + break; + case UNICODE_MODE_WINC: + set_unicode_input_mode(UC_WINC); #if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_WINC) - static float song_winc[][2] = UNICODE_SONG_WINC; - PLAY_SONG(song_winc); + static float song_winc[][2] = UNICODE_SONG_WINC; + PLAY_SONG(song_winc); #endif - break; + break; + } } - } -#if defined(UNICODE_ENABLE) - return process_unicode(keycode, record); +#if defined(UNICODE_ENABLE) + return process_unicode(keycode, record); #elif defined(UNICODEMAP_ENABLE) - return process_unicodemap(keycode, record); + return process_unicodemap(keycode, record); #elif defined(UCIS_ENABLE) - return process_ucis(keycode, record); + return process_ucis(keycode, record); #else - return true; + return true; #endif } diff --git a/quantum/process_keycode/process_unicode_common.h b/quantum/process_keycode/process_unicode_common.h index 7340800e56..cab6eea6ea 100644 --- a/quantum/process_keycode/process_unicode_common.h +++ b/quantum/process_keycode/process_unicode_common.h @@ -19,60 +19,60 @@ #include "quantum.h" #if defined(UNICODE_ENABLE) + defined(UNICODEMAP_ENABLE) + defined(UCIS_ENABLE) > 1 - #error "Cannot enable more than one Unicode method (UNICODE, UNICODEMAP, UCIS) at the same time" +# error "Cannot enable more than one Unicode method (UNICODE, UNICODEMAP, UCIS) at the same time" #endif // Keycodes used for starting Unicode input on different platforms #ifndef UNICODE_KEY_OSX - #define UNICODE_KEY_OSX KC_LALT +# define UNICODE_KEY_OSX KC_LALT #endif #ifndef UNICODE_KEY_LNX - #define UNICODE_KEY_LNX LCTL(LSFT(KC_U)) +# define UNICODE_KEY_LNX LCTL(LSFT(KC_U)) #endif #ifndef UNICODE_KEY_WINC - #define UNICODE_KEY_WINC KC_RALT +# define UNICODE_KEY_WINC KC_RALT #endif // Comma-delimited, ordered list of input modes selected for use (e.g. in cycle) // Example: #define UNICODE_SELECTED_MODES UC_WINC, UC_LNX #ifndef UNICODE_SELECTED_MODES - #define UNICODE_SELECTED_MODES -1 +# define UNICODE_SELECTED_MODES -1 #endif // Whether input mode changes in cycle should be written to EEPROM #ifndef UNICODE_CYCLE_PERSIST - #define UNICODE_CYCLE_PERSIST true +# define UNICODE_CYCLE_PERSIST true #endif // Delay between starting Unicode input and sending a sequence, in ms #ifndef UNICODE_TYPE_DELAY - #define UNICODE_TYPE_DELAY 10 +# define UNICODE_TYPE_DELAY 10 #endif enum unicode_input_modes { - UC_OSX, // Mac OS X using Unicode Hex Input - UC_LNX, // Linux using IBus - UC_WIN, // Windows using EnableHexNumpad - UC_BSD, // BSD (not implemented) - UC_WINC, // Windows using WinCompose (https://github.com/samhocevar/wincompose) - UC__COUNT // Number of available input modes (always leave at the end) + UC_OSX, // Mac OS X using Unicode Hex Input + UC_LNX, // Linux using IBus + UC_WIN, // Windows using EnableHexNumpad + UC_BSD, // BSD (not implemented) + UC_WINC, // Windows using WinCompose (https://github.com/samhocevar/wincompose) + UC__COUNT // Number of available input modes (always leave at the end) }; typedef union { - uint32_t raw; - struct { - uint8_t input_mode : 8; - }; + uint32_t raw; + struct { + uint8_t input_mode : 8; + }; } unicode_config_t; extern unicode_config_t unicode_config; extern uint8_t unicode_saved_mods; -void unicode_input_mode_init(void); +void unicode_input_mode_init(void); uint8_t get_unicode_input_mode(void); -void set_unicode_input_mode(uint8_t mode); -void cycle_unicode_input_mode(uint8_t offset); -void persist_unicode_input_mode(void); +void set_unicode_input_mode(uint8_t mode); +void cycle_unicode_input_mode(uint8_t offset); +void persist_unicode_input_mode(void); void unicode_input_start(void); void unicode_input_finish(void); @@ -83,108 +83,108 @@ void send_unicode_hex_string(const char *str); bool process_unicode_common(uint16_t keycode, keyrecord_t *record); -#define UC_BSPC UC(0x0008) -#define UC_SPC UC(0x0020) - -#define UC_EXLM UC(0x0021) -#define UC_DQUT UC(0x0022) -#define UC_HASH UC(0x0023) -#define UC_DLR UC(0x0024) -#define UC_PERC UC(0x0025) -#define UC_AMPR UC(0x0026) -#define UC_QUOT UC(0x0027) -#define UC_LPRN UC(0x0028) -#define UC_RPRN UC(0x0029) -#define UC_ASTR UC(0x002A) -#define UC_PLUS UC(0x002B) -#define UC_COMM UC(0x002C) -#define UC_DASH UC(0x002D) -#define UC_DOT UC(0x002E) -#define UC_SLSH UC(0x002F) - -#define UC_0 UC(0x0030) -#define UC_1 UC(0x0031) -#define UC_2 UC(0x0032) -#define UC_3 UC(0x0033) -#define UC_4 UC(0x0034) -#define UC_5 UC(0x0035) -#define UC_6 UC(0x0036) -#define UC_7 UC(0x0037) -#define UC_8 UC(0x0038) -#define UC_9 UC(0x0039) +#define UC_BSPC UC(0x0008) +#define UC_SPC UC(0x0020) + +#define UC_EXLM UC(0x0021) +#define UC_DQUT UC(0x0022) +#define UC_HASH UC(0x0023) +#define UC_DLR UC(0x0024) +#define UC_PERC UC(0x0025) +#define UC_AMPR UC(0x0026) +#define UC_QUOT UC(0x0027) +#define UC_LPRN UC(0x0028) +#define UC_RPRN UC(0x0029) +#define UC_ASTR UC(0x002A) +#define UC_PLUS UC(0x002B) +#define UC_COMM UC(0x002C) +#define UC_DASH UC(0x002D) +#define UC_DOT UC(0x002E) +#define UC_SLSH UC(0x002F) + +#define UC_0 UC(0x0030) +#define UC_1 UC(0x0031) +#define UC_2 UC(0x0032) +#define UC_3 UC(0x0033) +#define UC_4 UC(0x0034) +#define UC_5 UC(0x0035) +#define UC_6 UC(0x0036) +#define UC_7 UC(0x0037) +#define UC_8 UC(0x0038) +#define UC_9 UC(0x0039) #define UC_COLN UC(0x003A) #define UC_SCLN UC(0x003B) -#define UC_LT UC(0x003C) -#define UC_EQL UC(0x003D) -#define UC_GT UC(0x003E) -#define UC_QUES UC(0x003F) -#define UC_AT UC(0x0040) - -#define UC_A UC(0x0041) -#define UC_B UC(0x0042) -#define UC_C UC(0x0043) -#define UC_D UC(0x0044) -#define UC_E UC(0x0045) -#define UC_F UC(0x0046) -#define UC_G UC(0x0047) -#define UC_H UC(0x0048) -#define UC_I UC(0x0049) -#define UC_J UC(0x004A) -#define UC_K UC(0x004B) -#define UC_L UC(0x004C) -#define UC_M UC(0x004D) -#define UC_N UC(0x004E) -#define UC_O UC(0x004F) -#define UC_P UC(0x0050) -#define UC_Q UC(0x0051) -#define UC_R UC(0x0052) -#define UC_S UC(0x0053) -#define UC_T UC(0x0054) -#define UC_U UC(0x0055) -#define UC_V UC(0x0056) -#define UC_W UC(0x0057) -#define UC_X UC(0x0058) -#define UC_Y UC(0x0059) -#define UC_Z UC(0x005A) - -#define UC_LBRC UC(0x005B) -#define UC_BSLS UC(0x005C) -#define UC_RBRC UC(0x005D) -#define UC_CIRM UC(0x005E) -#define UC_UNDR UC(0x005F) - -#define UC_GRV UC(0x0060) - -#define UC_a UC(0x0061) -#define UC_b UC(0x0062) -#define UC_c UC(0x0063) -#define UC_d UC(0x0064) -#define UC_e UC(0x0065) -#define UC_f UC(0x0066) -#define UC_g UC(0x0067) -#define UC_h UC(0x0068) -#define UC_i UC(0x0069) -#define UC_j UC(0x006A) -#define UC_k UC(0x006B) -#define UC_l UC(0x006C) -#define UC_m UC(0x006D) -#define UC_n UC(0x006E) -#define UC_o UC(0x006F) -#define UC_p UC(0x0070) -#define UC_q UC(0x0071) -#define UC_r UC(0x0072) -#define UC_s UC(0x0073) -#define UC_t UC(0x0074) -#define UC_u UC(0x0075) -#define UC_v UC(0x0076) -#define UC_w UC(0x0077) -#define UC_x UC(0x0078) -#define UC_y UC(0x0079) -#define UC_z UC(0x007A) - -#define UC_LCBR UC(0x007B) -#define UC_PIPE UC(0x007C) -#define UC_RCBR UC(0x007D) -#define UC_TILD UC(0x007E) -#define UC_DEL UC(0x007F) +#define UC_LT UC(0x003C) +#define UC_EQL UC(0x003D) +#define UC_GT UC(0x003E) +#define UC_QUES UC(0x003F) +#define UC_AT UC(0x0040) + +#define UC_A UC(0x0041) +#define UC_B UC(0x0042) +#define UC_C UC(0x0043) +#define UC_D UC(0x0044) +#define UC_E UC(0x0045) +#define UC_F UC(0x0046) +#define UC_G UC(0x0047) +#define UC_H UC(0x0048) +#define UC_I UC(0x0049) +#define UC_J UC(0x004A) +#define UC_K UC(0x004B) +#define UC_L UC(0x004C) +#define UC_M UC(0x004D) +#define UC_N UC(0x004E) +#define UC_O UC(0x004F) +#define UC_P UC(0x0050) +#define UC_Q UC(0x0051) +#define UC_R UC(0x0052) +#define UC_S UC(0x0053) +#define UC_T UC(0x0054) +#define UC_U UC(0x0055) +#define UC_V UC(0x0056) +#define UC_W UC(0x0057) +#define UC_X UC(0x0058) +#define UC_Y UC(0x0059) +#define UC_Z UC(0x005A) + +#define UC_LBRC UC(0x005B) +#define UC_BSLS UC(0x005C) +#define UC_RBRC UC(0x005D) +#define UC_CIRM UC(0x005E) +#define UC_UNDR UC(0x005F) + +#define UC_GRV UC(0x0060) + +#define UC_a UC(0x0061) +#define UC_b UC(0x0062) +#define UC_c UC(0x0063) +#define UC_d UC(0x0064) +#define UC_e UC(0x0065) +#define UC_f UC(0x0066) +#define UC_g UC(0x0067) +#define UC_h UC(0x0068) +#define UC_i UC(0x0069) +#define UC_j UC(0x006A) +#define UC_k UC(0x006B) +#define UC_l UC(0x006C) +#define UC_m UC(0x006D) +#define UC_n UC(0x006E) +#define UC_o UC(0x006F) +#define UC_p UC(0x0070) +#define UC_q UC(0x0071) +#define UC_r UC(0x0072) +#define UC_s UC(0x0073) +#define UC_t UC(0x0074) +#define UC_u UC(0x0075) +#define UC_v UC(0x0076) +#define UC_w UC(0x0077) +#define UC_x UC(0x0078) +#define UC_y UC(0x0079) +#define UC_z UC(0x007A) + +#define UC_LCBR UC(0x007B) +#define UC_PIPE UC(0x007C) +#define UC_RCBR UC(0x007D) +#define UC_TILD UC(0x007E) +#define UC_DEL UC(0x007F) diff --git a/quantum/process_keycode/process_unicodemap.c b/quantum/process_keycode/process_unicodemap.c index b887879860..4364f156c4 100644 --- a/quantum/process_keycode/process_unicodemap.c +++ b/quantum/process_keycode/process_unicodemap.c @@ -17,62 +17,63 @@ #include "process_unicodemap.h" void register_hex32(uint32_t hex) { - bool onzerostart = true; - for(int i = 7; i >= 0; i--) { - if (i <= 3) { - onzerostart = false; + bool onzerostart = true; + for (int i = 7; i >= 0; i--) { + if (i <= 3) { + onzerostart = false; + } + uint8_t digit = ((hex >> (i * 4)) & 0xF); + if (digit == 0) { + if (!onzerostart) { + register_code(hex_to_keycode(digit)); + unregister_code(hex_to_keycode(digit)); + } + } else { + register_code(hex_to_keycode(digit)); + unregister_code(hex_to_keycode(digit)); + onzerostart = false; + } } - uint8_t digit = ((hex >> (i*4)) & 0xF); - if (digit == 0) { - if (!onzerostart) { - register_code(hex_to_keycode(digit)); - unregister_code(hex_to_keycode(digit)); - } - } else { - register_code(hex_to_keycode(digit)); - unregister_code(hex_to_keycode(digit)); - onzerostart = false; - } - } } -__attribute__((weak)) -uint16_t unicodemap_index(uint16_t keycode) { - if (keycode >= QK_UNICODEMAP_PAIR) { - // Keycode is a pair: extract index based on Shift / Caps Lock state - uint16_t index = keycode - QK_UNICODEMAP_PAIR; +__attribute__((weak)) uint16_t unicodemap_index(uint16_t keycode) { + if (keycode >= QK_UNICODEMAP_PAIR) { + // Keycode is a pair: extract index based on Shift / Caps Lock state + uint16_t index = keycode - QK_UNICODEMAP_PAIR; - bool shift = unicode_saved_mods & MOD_MASK_SHIFT, caps = IS_HOST_LED_ON(USB_LED_CAPS_LOCK); - if (shift ^ caps) { index >>= 7; } + bool shift = unicode_saved_mods & MOD_MASK_SHIFT, caps = IS_HOST_LED_ON(USB_LED_CAPS_LOCK); + if (shift ^ caps) { + index >>= 7; + } - return index & 0x7F; - } else { - // Keycode is a regular index - return keycode - QK_UNICODEMAP; - } + return index & 0x7F; + } else { + // Keycode is a regular index + return keycode - QK_UNICODEMAP; + } } bool process_unicodemap(uint16_t keycode, keyrecord_t *record) { - if (keycode >= QK_UNICODEMAP && keycode <= QK_UNICODEMAP_PAIR_MAX && record->event.pressed) { - unicode_input_start(); + if (keycode >= QK_UNICODEMAP && keycode <= QK_UNICODEMAP_PAIR_MAX && record->event.pressed) { + unicode_input_start(); - uint32_t code = pgm_read_dword(unicode_map + unicodemap_index(keycode)); - uint8_t input_mode = get_unicode_input_mode(); + uint32_t code = pgm_read_dword(unicode_map + unicodemap_index(keycode)); + uint8_t input_mode = get_unicode_input_mode(); - if (code > 0x10FFFF || (code > 0xFFFF && input_mode == UC_WIN)) { - // Character is out of range supported by the platform - unicode_input_cancel(); - } else if (code > 0xFFFF && input_mode == UC_OSX) { - // Convert to UTF-16 surrogate pair on Mac - code -= 0x10000; - uint32_t lo = code & 0x3FF, hi = (code & 0xFFC00) >> 10; - register_hex32(hi + 0xD800); - register_hex32(lo + 0xDC00); - unicode_input_finish(); - } else { - register_hex32(code); - unicode_input_finish(); + if (code > 0x10FFFF || (code > 0xFFFF && input_mode == UC_WIN)) { + // Character is out of range supported by the platform + unicode_input_cancel(); + } else if (code > 0xFFFF && input_mode == UC_OSX) { + // Convert to UTF-16 surrogate pair on Mac + code -= 0x10000; + uint32_t lo = code & 0x3FF, hi = (code & 0xFFC00) >> 10; + register_hex32(hi + 0xD800); + register_hex32(lo + 0xDC00); + unicode_input_finish(); + } else { + register_hex32(code); + unicode_input_finish(); + } } - } - return true; + return true; } diff --git a/quantum/process_keycode/process_unicodemap.h b/quantum/process_keycode/process_unicodemap.h index 51709c5dc8..a4b6d77f3a 100644 --- a/quantum/process_keycode/process_unicodemap.h +++ b/quantum/process_keycode/process_unicodemap.h @@ -20,6 +20,6 @@ extern const uint32_t PROGMEM unicode_map[]; -void register_hex32(uint32_t hex); +void register_hex32(uint32_t hex); uint16_t unicodemap_index(uint16_t keycode); -bool process_unicodemap(uint16_t keycode, keyrecord_t *record); +bool process_unicodemap(uint16_t keycode, keyrecord_t *record); -- cgit v1.2.3 From f069e9fc09859baf03d940b6db47e95c50a24936 Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Sat, 21 Sep 2019 11:22:27 -0700 Subject: Generalize Tap Dance Layer functions (#6629) * made tapdance dual_role general * updated original dual_role functionality * added toggling layer example * Fix dual role and add alias * Update docs about new layer tap dances * Fix up based on feedback --- quantum/process_keycode/process_tap_dance.c | 2 +- quantum/process_keycode/process_tap_dance.h | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_tap_dance.c b/quantum/process_keycode/process_tap_dance.c index c27fe48347..16756e59c2 100644 --- a/quantum/process_keycode/process_tap_dance.c +++ b/quantum/process_keycode/process_tap_dance.c @@ -71,7 +71,7 @@ void qk_tap_dance_dual_role_finished(qk_tap_dance_state_t *state, void *user_dat if (state->count == 1) { register_code16(pair->kc); } else if (state->count == 2) { - layer_move(pair->layer); + pair->layer_function(pair->layer); } } diff --git a/quantum/process_keycode/process_tap_dance.h b/quantum/process_keycode/process_tap_dance.h index b2d0cb8297..8d227dfd70 100644 --- a/quantum/process_keycode/process_tap_dance.h +++ b/quantum/process_keycode/process_tap_dance.h @@ -56,13 +56,19 @@ typedef struct { typedef struct { uint16_t kc; uint8_t layer; + void (*layer_function)(uint8_t); } qk_tap_dance_dual_role_t; # define ACTION_TAP_DANCE_DOUBLE(kc1, kc2) \ { .fn = {qk_tap_dance_pair_on_each_tap, qk_tap_dance_pair_finished, qk_tap_dance_pair_reset}, .user_data = (void *)&((qk_tap_dance_pair_t){kc1, kc2}), } # define ACTION_TAP_DANCE_DUAL_ROLE(kc, layer) \ - { .fn = {qk_tap_dance_dual_role_on_each_tap, qk_tap_dance_dual_role_finished, qk_tap_dance_dual_role_reset}, .user_data = (void *)&((qk_tap_dance_dual_role_t){kc, layer}), } + { .fn = { qk_tap_dance_dual_role_on_each_tap, qk_tap_dance_dual_role_finished, qk_tap_dance_dual_role_reset }, .user_data = (void *)&((qk_tap_dance_dual_role_t) { kc, layer, layer_move }), } + +# define ACTION_TAP_DANCE_TOGGLE_LAYER(kc, layer) \ + { .fn = { NULL, qk_tap_dance_dual_role_finished, qk_tap_dance_dual_role_reset }, .user_data = (void *)&((qk_tap_dance_dual_role_t) { kc, layer, layer_invert }), } + +# define ACTION_TAP_DANCE_LAYER_MOVE(kc, layer) ACTION_TAP_DANCE_DUAL_ROLE(kc, layer) # define ACTION_TAP_DANCE_FN(user_fn) \ { .fn = {NULL, user_fn, NULL}, .user_data = NULL, } @@ -73,6 +79,8 @@ typedef struct { # define ACTION_TAP_DANCE_FN_ADVANCED_TIME(user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_dance_reset, tap_specific_tapping_term) \ { .fn = {user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_dance_reset}, .user_data = NULL, .custom_tapping_term = tap_specific_tapping_term, } + + extern qk_tap_dance_action_t tap_dance_actions[]; /* To be used internally */ -- cgit v1.2.3 From 335dd0271e344fec1a0f086b34da6f8ae0d8bd60 Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Thu, 24 Oct 2019 12:08:29 -0700 Subject: Fix Tap Dance name for consistency and to match docs (#7136) --- quantum/process_keycode/process_tap_dance.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_tap_dance.h b/quantum/process_keycode/process_tap_dance.h index 8d227dfd70..8f3f3ff3c6 100644 --- a/quantum/process_keycode/process_tap_dance.h +++ b/quantum/process_keycode/process_tap_dance.h @@ -65,7 +65,7 @@ typedef struct { # define ACTION_TAP_DANCE_DUAL_ROLE(kc, layer) \ { .fn = { qk_tap_dance_dual_role_on_each_tap, qk_tap_dance_dual_role_finished, qk_tap_dance_dual_role_reset }, .user_data = (void *)&((qk_tap_dance_dual_role_t) { kc, layer, layer_move }), } -# define ACTION_TAP_DANCE_TOGGLE_LAYER(kc, layer) \ +# define ACTION_TAP_DANCE_LAYER_TOGGLE(kc, layer) \ { .fn = { NULL, qk_tap_dance_dual_role_finished, qk_tap_dance_dual_role_reset }, .user_data = (void *)&((qk_tap_dance_dual_role_t) { kc, layer, layer_invert }), } # define ACTION_TAP_DANCE_LAYER_MOVE(kc, layer) ACTION_TAP_DANCE_DUAL_ROLE(kc, layer) -- cgit v1.2.3 From e9c44e396d21df990b1d08e8b4c30e288797dffe Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Sun, 3 Nov 2019 09:52:01 -0800 Subject: Smallish overhaul of Auto-Shift feature (#6067) * Fix edge case when using One Shot Layer with Auto Shift, and it not triggering the cleanup * Remove junk code (no longer used) * Replace `(un)register_code` calls with `tap_code` where appropriate * Fixed up Switch check to be more readable (less verbose) * Simplified modifier check (if it comes back non-zero, there are mods) * Add additional function calls for autoshift settings * Made all variables static, since there are function calls to get their status * Fixed up documentation * Re-add special characters that were missed * formatting pass --- quantum/process_keycode/process_auto_shift.c | 114 +++++++-------------------- quantum/process_keycode/process_auto_shift.h | 15 ++-- 2 files changed, 34 insertions(+), 95 deletions(-) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_auto_shift.c b/quantum/process_keycode/process_auto_shift.c index 4ae3fe446e..b474bda691 100644 --- a/quantum/process_keycode/process_auto_shift.c +++ b/quantum/process_keycode/process_auto_shift.c @@ -20,19 +20,10 @@ # include "process_auto_shift.h" -# define TAP(key) \ - register_code(key); \ - unregister_code(key) - -# define TAP_WITH_MOD(mod, key) \ - register_code(mod); \ - register_code(key); \ - unregister_code(key); \ - unregister_code(mod) - -uint16_t autoshift_time = 0; -uint16_t autoshift_timeout = AUTO_SHIFT_TIMEOUT; -uint16_t autoshift_lastkey = KC_NO; +static bool autoshift_enabled = true; +static uint16_t autoshift_time = 0; +static uint16_t autoshift_timeout = AUTO_SHIFT_TIMEOUT; +static uint16_t autoshift_lastkey = KC_NO; void autoshift_timer_report(void) { char display[8]; @@ -52,14 +43,9 @@ void autoshift_flush(void) { uint16_t elapsed = timer_elapsed(autoshift_time); if (elapsed > autoshift_timeout) { - register_code(KC_LSFT); - } - - register_code(autoshift_lastkey); - unregister_code(autoshift_lastkey); - - if (elapsed > autoshift_timeout) { - unregister_code(KC_LSFT); + tap_code16(LSFT(autoshift_lastkey)); + } else { + tap_code(autoshift_lastkey); } autoshift_time = 0; @@ -67,8 +53,6 @@ void autoshift_flush(void) { } } -bool autoshift_enabled = true; - void autoshift_enable(void) { autoshift_enabled = true; } void autoshift_disable(void) { autoshift_enabled = false; @@ -84,106 +68,62 @@ void autoshift_toggle(void) { } } -bool autoshift_state(void) { return autoshift_enabled; } +bool get_autoshift_state(void) { return autoshift_enabled; } -bool process_auto_shift(uint16_t keycode, keyrecord_t *record) { -# ifndef AUTO_SHIFT_MODIFIERS - static uint8_t any_mod_pressed; -# endif +uint16_t get_autoshift_timeout(void) { return autoshift_timeout; } +void set_autoshift_timeout(uint16_t timeout) { autoshift_timeout = timeout; } + +bool process_auto_shift(uint16_t keycode, keyrecord_t *record) { if (record->event.pressed) { switch (keycode) { case KC_ASUP: autoshift_timeout += 5; - return false; + return true; case KC_ASDN: autoshift_timeout -= 5; - return false; + return true; case KC_ASRP: autoshift_timer_report(); - return false; + return true; case KC_ASTG: autoshift_toggle(); - return false; + return true; case KC_ASON: autoshift_enable(); - return false; + return true; case KC_ASOFF: autoshift_disable(); - return false; + return true; # ifndef NO_AUTO_SHIFT_ALPHA - case KC_A: - case KC_B: - case KC_C: - case KC_D: - case KC_E: - case KC_F: - case KC_G: - case KC_H: - case KC_I: - case KC_J: - case KC_K: - case KC_L: - case KC_M: - case KC_N: - case KC_O: - case KC_P: - case KC_Q: - case KC_R: - case KC_S: - case KC_T: - case KC_U: - case KC_V: - case KC_W: - case KC_X: - case KC_Y: - case KC_Z: + case KC_A ... KC_Z: # endif # ifndef NO_AUTO_SHIFT_NUMERIC - case KC_1: - case KC_2: - case KC_3: - case KC_4: - case KC_5: - case KC_6: - case KC_7: - case KC_8: - case KC_9: - case KC_0: + case KC_1 ... KC_0: # endif # ifndef NO_AUTO_SHIFT_SPECIAL - case KC_MINUS: - case KC_EQL: case KC_TAB: - case KC_LBRC: - case KC_RBRC: - case KC_BSLS: - case KC_SCLN: - case KC_QUOT: - case KC_COMM: - case KC_DOT: - case KC_SLSH: - case KC_GRAVE: + case KC_MINUS ... KC_SLASH: case KC_NONUS_BSLASH: - case KC_NONUS_HASH: # endif - autoshift_flush(); if (!autoshift_enabled) return true; # ifndef AUTO_SHIFT_MODIFIERS - any_mod_pressed = get_mods() & (MOD_BIT(KC_LGUI) | MOD_BIT(KC_RGUI) | MOD_BIT(KC_LALT) | MOD_BIT(KC_RALT) | MOD_BIT(KC_LCTL) | MOD_BIT(KC_RCTL) | MOD_BIT(KC_LSFT) | MOD_BIT(KC_RSFT)); - - if (any_mod_pressed) { + if (get_mods()) { return true; } # endif - autoshift_on(keycode); + + // We need some extra handling here for OSL edge cases +# if !defined(NO_ACTION_ONESHOT) && !defined(NO_ACTION_TAPPING) + clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED); +# endif return false; default: diff --git a/quantum/process_keycode/process_auto_shift.h b/quantum/process_keycode/process_auto_shift.h index 083325d8e3..e86c4658e9 100644 --- a/quantum/process_keycode/process_auto_shift.h +++ b/quantum/process_keycode/process_auto_shift.h @@ -14,8 +14,7 @@ * along with this program. If not, see . */ -#ifndef PROCESS_AUTO_SHIFT_H -#define PROCESS_AUTO_SHIFT_H +#pragma once #include "quantum.h" @@ -25,9 +24,9 @@ bool process_auto_shift(uint16_t keycode, keyrecord_t *record); -void autoshift_enable(void); -void autoshift_disable(void); -void autoshift_toggle(void); -bool autoshift_state(void); - -#endif +void autoshift_enable(void); +void autoshift_disable(void); +void autoshift_toggle(void); +bool get_autoshift_state(void); +uint16_t get_autoshift_timeout(void); +void set_autoshift_timeout(uint16_t timeout); -- cgit v1.2.3 From 542cb0a8ce3f324c6bd46751d733daf86384a8f6 Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Mon, 4 Nov 2019 22:59:13 -0800 Subject: [Core] Convert Dynamic Macro to a Core Feature (#5948) * Convert Dynamic Macro to a Core Feature This imports the code from Dynamic Macro into the core code, and handles it, as such. This deprecates the old method but does not remove it, for legacy support. This way, no existing user files need to be touched. Additionally, this reorganizes the documentation to better reflect the changes. Also, it adds user hooks to the feature so users can customize the existing functionality. Based heavily on and closes #2976 * Apply suggestions from code review Co-Authored-By: fauxpark Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Cleanup based on feedback * Add short-form keycodes and document them - add short-form keycodes to quantum/quantum_keycodes.h - document the new aliases in docs/feature_dynamic_macros.md * Add Dynamic Macros section and keycodes to docs/keycodes.md * Make anti-nesting optional * Add documentation for DYNAMIC_MACRO_NO_NESTING option * Fix Merge artifacts * Fix formatting typo in docs Co-Authored-By: James Young <18669334+noroadsleft@users.noreply.github.com> * Remove DYNAMIC_MACRO_RANGE as it's not needed * Fix includes and layer var type --- quantum/process_keycode/process_dynamic_macro.c | 257 ++++++++++++++++++++++++ quantum/process_keycode/process_dynamic_macro.h | 41 ++++ 2 files changed, 298 insertions(+) create mode 100644 quantum/process_keycode/process_dynamic_macro.c create mode 100644 quantum/process_keycode/process_dynamic_macro.h (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_dynamic_macro.c b/quantum/process_keycode/process_dynamic_macro.c new file mode 100644 index 0000000000..2065f242db --- /dev/null +++ b/quantum/process_keycode/process_dynamic_macro.c @@ -0,0 +1,257 @@ +/* Copyright 2016 Jack Humbert + * Copyright 2019 Drashna Jael're (@drashna, aka Christopher Courtney) + * + * 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 . + */ + +/* Author: Wojciech Siewierski < wojciech dot siewierski at onet dot pl > */ +#include "process_dynamic_macro.h" + +// default feedback method +void dynamic_macro_led_blink(void) { +#ifdef BACKLIGHT_ENABLE + backlight_toggle(); + wait_ms(100); + backlight_toggle(); +#endif +} + +/* User hooks for Dynamic Macros */ + +__attribute__((weak)) void dynamic_macro_record_start_user(void) { dynamic_macro_led_blink(); } + +__attribute__((weak)) void dynamic_macro_play_user(int8_t direction) { dynamic_macro_led_blink(); } + +__attribute__((weak)) void dynamic_macro_record_key_user(int8_t direction, keyrecord_t *record) { dynamic_macro_led_blink(); } + +__attribute__((weak)) void dynamic_macro_record_end_user(int8_t direction) { dynamic_macro_led_blink(); } + +/* Convenience macros used for retrieving the debug info. All of them + * need a `direction` variable accessible at the call site. + */ +#define DYNAMIC_MACRO_CURRENT_SLOT() (direction > 0 ? 1 : 2) +#define DYNAMIC_MACRO_CURRENT_LENGTH(BEGIN, POINTER) ((int)(direction * ((POINTER) - (BEGIN)))) +#define DYNAMIC_MACRO_CURRENT_CAPACITY(BEGIN, END2) ((int)(direction * ((END2) - (BEGIN)) + 1)) + +/** + * Start recording of the dynamic macro. + * + * @param[out] macro_pointer The new macro buffer iterator. + * @param[in] macro_buffer The macro buffer used to initialize macro_pointer. + */ +void dynamic_macro_record_start(keyrecord_t **macro_pointer, keyrecord_t *macro_buffer) { + dprintln("dynamic macro recording: started"); + + dynamic_macro_record_start_user(); + + clear_keyboard(); + layer_clear(); + *macro_pointer = macro_buffer; +} + +/** + * Play the dynamic macro. + * + * @param macro_buffer[in] The beginning of the macro buffer being played. + * @param macro_end[in] The element after the last macro buffer element. + * @param direction[in] Either +1 or -1, which way to iterate the buffer. + */ +void dynamic_macro_play(keyrecord_t *macro_buffer, keyrecord_t *macro_end, int8_t direction) { + dprintf("dynamic macro: slot %d playback\n", DYNAMIC_MACRO_CURRENT_SLOT()); + + layer_state_t saved_layer_state = layer_state; + + clear_keyboard(); + layer_clear(); + + while (macro_buffer != macro_end) { + process_record(macro_buffer); + macro_buffer += direction; + } + + clear_keyboard(); + + layer_state = saved_layer_state; + + dynamic_macro_play_user(direction); +} + +/** + * Record a single key in a dynamic macro. + * + * @param macro_buffer[in] The start of the used macro buffer. + * @param macro_pointer[in,out] The current buffer position. + * @param macro2_end[in] The end of the other macro. + * @param direction[in] Either +1 or -1, which way to iterate the buffer. + * @param record[in] The current keypress. + */ +void dynamic_macro_record_key(keyrecord_t *macro_buffer, keyrecord_t **macro_pointer, keyrecord_t *macro2_end, int8_t direction, keyrecord_t *record) { + /* If we've just started recording, ignore all the key releases. */ + if (!record->event.pressed && *macro_pointer == macro_buffer) { + dprintln("dynamic macro: ignoring a leading key-up event"); + return; + } + + /* The other end of the other macro is the last buffer element it + * is safe to use before overwriting the other macro. + */ + if (*macro_pointer - direction != macro2_end) { + **macro_pointer = *record; + *macro_pointer += direction; + } else { + dynamic_macro_record_key_user(direction, record); + } + + dprintf("dynamic macro: slot %d length: %d/%d\n", DYNAMIC_MACRO_CURRENT_SLOT(), DYNAMIC_MACRO_CURRENT_LENGTH(macro_buffer, *macro_pointer), DYNAMIC_MACRO_CURRENT_CAPACITY(macro_buffer, macro2_end)); +} + +/** + * End recording of the dynamic macro. Essentially just update the + * pointer to the end of the macro. + */ +void dynamic_macro_record_end(keyrecord_t *macro_buffer, keyrecord_t *macro_pointer, int8_t direction, keyrecord_t **macro_end) { + dynamic_macro_record_end_user(direction); + + /* Do not save the keys being held when stopping the recording, + * i.e. the keys used to access the layer DYN_REC_STOP is on. + */ + while (macro_pointer != macro_buffer && (macro_pointer - direction)->event.pressed) { + dprintln("dynamic macro: trimming a trailing key-down event"); + macro_pointer -= direction; + } + + dprintf("dynamic macro: slot %d saved, length: %d\n", DYNAMIC_MACRO_CURRENT_SLOT(), DYNAMIC_MACRO_CURRENT_LENGTH(macro_buffer, macro_pointer)); + + *macro_end = macro_pointer; +} + +/* Handle the key events related to the dynamic macros. Should be + * called from process_record_user() like this: + * + * bool process_record_user(uint16_t keycode, keyrecord_t *record) { + * if (!process_record_dynamic_macro(keycode, record)) { + * return false; + * } + * <...THE REST OF THE FUNCTION...> + * } + */ +bool process_dynamic_macro(uint16_t keycode, keyrecord_t *record) { + /* Both macros use the same buffer but read/write on different + * ends of it. + * + * Macro1 is written left-to-right starting from the beginning of + * the buffer. + * + * Macro2 is written right-to-left starting from the end of the + * buffer. + * + * ¯o_buffer macro_end + * v v + * +------------------------------------------------------------+ + * |>>>>>> MACRO1 >>>>>> <<<<<<<<<<<<< MACRO2 <<<<<<<<<<<<<| + * +------------------------------------------------------------+ + * ^ ^ + * r_macro_end r_macro_buffer + * + * During the recording when one macro encounters the end of the + * other macro, the recording is stopped. Apart from this, there + * are no arbitrary limits for the macros' length in relation to + * each other: for example one can either have two medium sized + * macros or one long macro and one short macro. Or even one empty + * and one using the whole buffer. + */ + static keyrecord_t macro_buffer[DYNAMIC_MACRO_SIZE]; + + /* Pointer to the first buffer element after the first macro. + * Initially points to the very beginning of the buffer since the + * macro is empty. */ + static keyrecord_t *macro_end = macro_buffer; + + /* The other end of the macro buffer. Serves as the beginning of + * the second macro. */ + static keyrecord_t *const r_macro_buffer = macro_buffer + DYNAMIC_MACRO_SIZE - 1; + + /* Like macro_end but for the second macro. */ + static keyrecord_t *r_macro_end = r_macro_buffer; + + /* A persistent pointer to the current macro position (iterator) + * used during the recording. */ + static keyrecord_t *macro_pointer = NULL; + + /* 0 - no macro is being recorded right now + * 1,2 - either macro 1 or 2 is being recorded */ + static uint8_t macro_id = 0; + + if (macro_id == 0) { + /* No macro recording in progress. */ + if (!record->event.pressed) { + switch (keycode) { + case DYN_REC_START1: + dynamic_macro_record_start(¯o_pointer, macro_buffer); + macro_id = 1; + return false; + case DYN_REC_START2: + dynamic_macro_record_start(¯o_pointer, r_macro_buffer); + macro_id = 2; + return false; + case DYN_MACRO_PLAY1: + dynamic_macro_play(macro_buffer, macro_end, +1); + return false; + case DYN_MACRO_PLAY2: + dynamic_macro_play(r_macro_buffer, r_macro_end, -1); + return false; + } + } + } else { + /* A macro is being recorded right now. */ + switch (keycode) { + case DYN_REC_STOP: + /* Stop the macro recording. */ + if (record->event.pressed) { /* Ignore the initial release + * just after the recoding + * starts. */ + switch (macro_id) { + case 1: + dynamic_macro_record_end(macro_buffer, macro_pointer, +1, ¯o_end); + break; + case 2: + dynamic_macro_record_end(r_macro_buffer, macro_pointer, -1, &r_macro_end); + break; + } + macro_id = 0; + } + return false; +#ifdef DYNAMIC_MACRO_NO_NESTING + case DYN_MACRO_PLAY1: + case DYN_MACRO_PLAY2: + dprintln("dynamic macro: ignoring macro play key while recording"); + return false; +#endif + default: + /* Store the key in the macro buffer and process it normally. */ + switch (macro_id) { + case 1: + dynamic_macro_record_key(macro_buffer, ¯o_pointer, r_macro_end, +1, record); + break; + case 2: + dynamic_macro_record_key(r_macro_buffer, ¯o_pointer, macro_end, -1, record); + break; + } + return true; + break; + } + } + + return true; +} diff --git a/quantum/process_keycode/process_dynamic_macro.h b/quantum/process_keycode/process_dynamic_macro.h new file mode 100644 index 0000000000..39036541b8 --- /dev/null +++ b/quantum/process_keycode/process_dynamic_macro.h @@ -0,0 +1,41 @@ +/* Copyright 2016 Jack Humbert + * Copyright 2019 Drashna Jael're (@drashna, aka Christopher Courtney) + * + * 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 . + */ + +/* Author: Wojciech Siewierski < wojciech dot siewierski at onet dot pl > */ +#pragma once + +#include "quantum.h" + +/* May be overridden with a custom value. Be aware that the effective + * macro length is half of this value: each keypress is recorded twice + * because of the down-event and up-event. This is not a bug, it's the + * intended behavior. + * + * Usually it should be fine to set the macro size to at least 256 but + * there have been reports of it being too much in some users' cases, + * so 128 is considered a safe default. + */ +#ifndef DYNAMIC_MACRO_SIZE +# define DYNAMIC_MACRO_SIZE 128 +#endif + +void dynamic_macro_led_blink(void); +bool process_dynamic_macro(uint16_t keycode, keyrecord_t *record); +void dynamic_macro_record_start_user(void); +void dynamic_macro_play_user(int8_t direction); +void dynamic_macro_record_key_user(int8_t direction, keyrecord_t *record); +void dynamic_macro_record_end_user(int8_t direction); -- cgit v1.2.3 From a91c0c476507cb8c12840abb59bff34ab0de3c03 Mon Sep 17 00:00:00 2001 From: zvecr Date: Sun, 17 Nov 2019 14:02:26 +0000 Subject: Run clang-format manually to fix recently changed files --- quantum/process_keycode/process_tap_dance.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_tap_dance.h b/quantum/process_keycode/process_tap_dance.h index 8f3f3ff3c6..09ceef74d8 100644 --- a/quantum/process_keycode/process_tap_dance.h +++ b/quantum/process_keycode/process_tap_dance.h @@ -63,10 +63,10 @@ typedef struct { { .fn = {qk_tap_dance_pair_on_each_tap, qk_tap_dance_pair_finished, qk_tap_dance_pair_reset}, .user_data = (void *)&((qk_tap_dance_pair_t){kc1, kc2}), } # define ACTION_TAP_DANCE_DUAL_ROLE(kc, layer) \ - { .fn = { qk_tap_dance_dual_role_on_each_tap, qk_tap_dance_dual_role_finished, qk_tap_dance_dual_role_reset }, .user_data = (void *)&((qk_tap_dance_dual_role_t) { kc, layer, layer_move }), } + { .fn = {qk_tap_dance_dual_role_on_each_tap, qk_tap_dance_dual_role_finished, qk_tap_dance_dual_role_reset}, .user_data = (void *)&((qk_tap_dance_dual_role_t){kc, layer, layer_move}), } # define ACTION_TAP_DANCE_LAYER_TOGGLE(kc, layer) \ - { .fn = { NULL, qk_tap_dance_dual_role_finished, qk_tap_dance_dual_role_reset }, .user_data = (void *)&((qk_tap_dance_dual_role_t) { kc, layer, layer_invert }), } + { .fn = {NULL, qk_tap_dance_dual_role_finished, qk_tap_dance_dual_role_reset}, .user_data = (void *)&((qk_tap_dance_dual_role_t){kc, layer, layer_invert}), } # define ACTION_TAP_DANCE_LAYER_MOVE(kc, layer) ACTION_TAP_DANCE_DUAL_ROLE(kc, layer) @@ -79,8 +79,6 @@ typedef struct { # define ACTION_TAP_DANCE_FN_ADVANCED_TIME(user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_dance_reset, tap_specific_tapping_term) \ { .fn = {user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_dance_reset}, .user_data = NULL, .custom_tapping_term = tap_specific_tapping_term, } - - extern qk_tap_dance_action_t tap_dance_actions[]; /* To be used internally */ -- cgit v1.2.3 From 5a6737a778cfa828e4fdb5d382a84a41e5210d8e Mon Sep 17 00:00:00 2001 From: fauxpark Date: Tue, 26 Nov 2019 18:16:58 +1100 Subject: Send string keycode tweaks (#7471) --- quantum/process_keycode/process_terminal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_terminal.c b/quantum/process_keycode/process_terminal.c index f48f3d702d..7d1eefa9ed 100644 --- a/quantum/process_keycode/process_terminal.c +++ b/quantum/process_keycode/process_terminal.c @@ -61,7 +61,7 @@ void enable_terminal(void) { memset(cmd_buffer, 0, CMD_BUFF_SIZE * 80); for (int i = 0; i < 6; i++) strcpy(arguments[i], ""); // select all text to start over - // SEND_STRING(SS_LCTRL("a")); + // SEND_STRING(SS_LCTL("a")); send_string(terminal_prompt); } -- cgit v1.2.3 From d598f01cb7b9d4d9e8fc7bbc951b70be7726a468 Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Tue, 3 Dec 2019 19:48:55 +0000 Subject: Relocate magic keycode processing (#7512) * Move magic keycode processing to own file * Save some bytes * Update comments * Update define to one thats not already used... * Fix audio --- quantum/process_keycode/process_magic.c | 176 ++++++++++++++++++++++++++++++++ quantum/process_keycode/process_magic.h | 20 ++++ 2 files changed, 196 insertions(+) create mode 100644 quantum/process_keycode/process_magic.c create mode 100644 quantum/process_keycode/process_magic.h (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_magic.c b/quantum/process_keycode/process_magic.c new file mode 100644 index 0000000000..9668a50f7f --- /dev/null +++ b/quantum/process_keycode/process_magic.c @@ -0,0 +1,176 @@ +/* Copyright 2019 Jack Humbert + * + * 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 . + */ +#include "process_magic.h" + +#ifdef AUDIO_ENABLE +# ifndef AG_NORM_SONG +# define AG_NORM_SONG SONG(AG_NORM_SOUND) +# endif +# ifndef AG_SWAP_SONG +# define AG_SWAP_SONG SONG(AG_SWAP_SOUND) +# endif +# ifndef CG_NORM_SONG +# define CG_NORM_SONG SONG(AG_NORM_SOUND) +# endif +# ifndef CG_SWAP_SONG +# define CG_SWAP_SONG SONG(AG_SWAP_SOUND) +# endif +float ag_norm_song[][2] = AG_NORM_SONG; +float ag_swap_song[][2] = AG_SWAP_SONG; +float cg_norm_song[][2] = CG_NORM_SONG; +float cg_swap_song[][2] = CG_SWAP_SONG; +#endif + +/** + * MAGIC actions (BOOTMAGIC without the boot) + */ +bool process_magic(uint16_t keycode, keyrecord_t *record) { + // skip anything that isn't a keyup + if (!record->event.pressed) { + return true; + } + + /* keymap config */ + keymap_config.raw = eeconfig_read_keymap(); + switch (keycode) { + case MAGIC_SWAP_CONTROL_CAPSLOCK: + keymap_config.swap_control_capslock = true; + break; + case MAGIC_CAPSLOCK_TO_CONTROL: + keymap_config.capslock_to_control = true; + break; + case MAGIC_SWAP_LALT_LGUI: + keymap_config.swap_lalt_lgui = true; + break; + case MAGIC_SWAP_RALT_RGUI: + keymap_config.swap_ralt_rgui = true; + break; + case MAGIC_SWAP_LCTL_LGUI: + keymap_config.swap_lctl_lgui = true; + break; + case MAGIC_SWAP_RCTL_RGUI: + keymap_config.swap_rctl_rgui = true; + break; + case MAGIC_NO_GUI: + keymap_config.no_gui = true; + break; + case MAGIC_SWAP_GRAVE_ESC: + keymap_config.swap_grave_esc = true; + break; + case MAGIC_SWAP_BACKSLASH_BACKSPACE: + keymap_config.swap_backslash_backspace = true; + break; + case MAGIC_HOST_NKRO: + clear_keyboard(); // clear first buffer to prevent stuck keys + keymap_config.nkro = true; + break; + case MAGIC_SWAP_ALT_GUI: + keymap_config.swap_lalt_lgui = keymap_config.swap_ralt_rgui = true; +#ifdef AUDIO_ENABLE + PLAY_SONG(ag_swap_song); +#endif + break; + case MAGIC_SWAP_CTL_GUI: + keymap_config.swap_lctl_lgui = keymap_config.swap_rctl_rgui = true; +#ifdef AUDIO_ENABLE + PLAY_SONG(cg_swap_song); +#endif + break; + case MAGIC_UNSWAP_CONTROL_CAPSLOCK: + keymap_config.swap_control_capslock = false; + break; + case MAGIC_UNCAPSLOCK_TO_CONTROL: + keymap_config.capslock_to_control = false; + break; + case MAGIC_UNSWAP_LALT_LGUI: + keymap_config.swap_lalt_lgui = false; + break; + case MAGIC_UNSWAP_RALT_RGUI: + keymap_config.swap_ralt_rgui = false; + break; + case MAGIC_UNSWAP_LCTL_LGUI: + keymap_config.swap_lctl_lgui = false; + break; + case MAGIC_UNSWAP_RCTL_RGUI: + keymap_config.swap_rctl_rgui = false; + break; + case MAGIC_UNNO_GUI: + keymap_config.no_gui = false; + break; + case MAGIC_UNSWAP_GRAVE_ESC: + keymap_config.swap_grave_esc = false; + break; + case MAGIC_UNSWAP_BACKSLASH_BACKSPACE: + keymap_config.swap_backslash_backspace = false; + break; + case MAGIC_UNHOST_NKRO: + clear_keyboard(); // clear first buffer to prevent stuck keys + keymap_config.nkro = false; + break; + case MAGIC_UNSWAP_ALT_GUI: + keymap_config.swap_lalt_lgui = keymap_config.swap_ralt_rgui = false; +#ifdef AUDIO_ENABLE + PLAY_SONG(ag_norm_song); +#endif + break; + case MAGIC_UNSWAP_CTL_GUI: + keymap_config.swap_lctl_lgui = keymap_config.swap_rctl_rgui = false; +#ifdef AUDIO_ENABLE + PLAY_SONG(cg_norm_song); +#endif + break; + case MAGIC_TOGGLE_ALT_GUI: + keymap_config.swap_lalt_lgui = !keymap_config.swap_lalt_lgui; + keymap_config.swap_ralt_rgui = keymap_config.swap_lalt_lgui; +#ifdef AUDIO_ENABLE + if (keymap_config.swap_ralt_rgui) { + PLAY_SONG(ag_swap_song); + } else { + PLAY_SONG(ag_norm_song); + } +#endif + break; + case MAGIC_TOGGLE_CTL_GUI: + keymap_config.swap_lctl_lgui = !keymap_config.swap_lctl_lgui; + keymap_config.swap_rctl_rgui = keymap_config.swap_lctl_lgui; +#ifdef AUDIO_ENABLE + if (keymap_config.swap_rctl_rgui) { + PLAY_SONG(cg_swap_song); + } else { + PLAY_SONG(cg_norm_song); + } +#endif + break; + case MAGIC_TOGGLE_NKRO: + clear_keyboard(); // clear first buffer to prevent stuck keys + keymap_config.nkro = !keymap_config.nkro; + break; + case MAGIC_EE_HANDS_LEFT: + eeconfig_update_handedness(true); + break; + case MAGIC_EE_HANDS_RIGHT: + eeconfig_update_handedness(false); + break; + default: + // Not a magic keycode so continue processing + return true; + } + + eeconfig_update_keymap(keymap_config.raw); + clear_keyboard(); // clear to prevent stuck keys + + return false; +} diff --git a/quantum/process_keycode/process_magic.h b/quantum/process_keycode/process_magic.h new file mode 100644 index 0000000000..1eb39f1455 --- /dev/null +++ b/quantum/process_keycode/process_magic.h @@ -0,0 +1,20 @@ +/* Copyright 2019 + * + * 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 . + */ +#pragma once + +#include "quantum.h" + +bool process_magic(uint16_t keycode, keyrecord_t *record); -- cgit v1.2.3 From efb21c00ce8090303456dc9c22665a69c3fc298a Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Wed, 11 Dec 2019 19:39:30 +0000 Subject: Fix FORCE_NKRO handling (#7601) --- quantum/process_keycode/process_magic.c | 242 ++++++++++++++++---------------- 1 file changed, 122 insertions(+), 120 deletions(-) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_magic.c b/quantum/process_keycode/process_magic.c index 9668a50f7f..44dd5f0579 100644 --- a/quantum/process_keycode/process_magic.c +++ b/quantum/process_keycode/process_magic.c @@ -39,138 +39,140 @@ float cg_swap_song[][2] = CG_SWAP_SONG; */ bool process_magic(uint16_t keycode, keyrecord_t *record) { // skip anything that isn't a keyup - if (!record->event.pressed) { - return true; - } - - /* keymap config */ - keymap_config.raw = eeconfig_read_keymap(); - switch (keycode) { - case MAGIC_SWAP_CONTROL_CAPSLOCK: - keymap_config.swap_control_capslock = true; - break; - case MAGIC_CAPSLOCK_TO_CONTROL: - keymap_config.capslock_to_control = true; - break; - case MAGIC_SWAP_LALT_LGUI: - keymap_config.swap_lalt_lgui = true; - break; - case MAGIC_SWAP_RALT_RGUI: - keymap_config.swap_ralt_rgui = true; - break; - case MAGIC_SWAP_LCTL_LGUI: - keymap_config.swap_lctl_lgui = true; - break; - case MAGIC_SWAP_RCTL_RGUI: - keymap_config.swap_rctl_rgui = true; - break; - case MAGIC_NO_GUI: - keymap_config.no_gui = true; - break; - case MAGIC_SWAP_GRAVE_ESC: - keymap_config.swap_grave_esc = true; - break; - case MAGIC_SWAP_BACKSLASH_BACKSPACE: - keymap_config.swap_backslash_backspace = true; - break; - case MAGIC_HOST_NKRO: - clear_keyboard(); // clear first buffer to prevent stuck keys - keymap_config.nkro = true; - break; - case MAGIC_SWAP_ALT_GUI: - keymap_config.swap_lalt_lgui = keymap_config.swap_ralt_rgui = true; + if (record->event.pressed) { + switch (keycode) { + case MAGIC_SWAP_CONTROL_CAPSLOCK ... MAGIC_TOGGLE_ALT_GUI: + case MAGIC_SWAP_LCTL_LGUI ... MAGIC_EE_HANDS_RIGHT: + /* keymap config */ + keymap_config.raw = eeconfig_read_keymap(); + switch (keycode) { + case MAGIC_SWAP_CONTROL_CAPSLOCK: + keymap_config.swap_control_capslock = true; + break; + case MAGIC_CAPSLOCK_TO_CONTROL: + keymap_config.capslock_to_control = true; + break; + case MAGIC_SWAP_LALT_LGUI: + keymap_config.swap_lalt_lgui = true; + break; + case MAGIC_SWAP_RALT_RGUI: + keymap_config.swap_ralt_rgui = true; + break; + case MAGIC_SWAP_LCTL_LGUI: + keymap_config.swap_lctl_lgui = true; + break; + case MAGIC_SWAP_RCTL_RGUI: + keymap_config.swap_rctl_rgui = true; + break; + case MAGIC_NO_GUI: + keymap_config.no_gui = true; + break; + case MAGIC_SWAP_GRAVE_ESC: + keymap_config.swap_grave_esc = true; + break; + case MAGIC_SWAP_BACKSLASH_BACKSPACE: + keymap_config.swap_backslash_backspace = true; + break; + case MAGIC_HOST_NKRO: + clear_keyboard(); // clear first buffer to prevent stuck keys + keymap_config.nkro = true; + break; + case MAGIC_SWAP_ALT_GUI: + keymap_config.swap_lalt_lgui = keymap_config.swap_ralt_rgui = true; #ifdef AUDIO_ENABLE - PLAY_SONG(ag_swap_song); + PLAY_SONG(ag_swap_song); #endif - break; - case MAGIC_SWAP_CTL_GUI: - keymap_config.swap_lctl_lgui = keymap_config.swap_rctl_rgui = true; + break; + case MAGIC_SWAP_CTL_GUI: + keymap_config.swap_lctl_lgui = keymap_config.swap_rctl_rgui = true; #ifdef AUDIO_ENABLE - PLAY_SONG(cg_swap_song); + PLAY_SONG(cg_swap_song); #endif - break; - case MAGIC_UNSWAP_CONTROL_CAPSLOCK: - keymap_config.swap_control_capslock = false; - break; - case MAGIC_UNCAPSLOCK_TO_CONTROL: - keymap_config.capslock_to_control = false; - break; - case MAGIC_UNSWAP_LALT_LGUI: - keymap_config.swap_lalt_lgui = false; - break; - case MAGIC_UNSWAP_RALT_RGUI: - keymap_config.swap_ralt_rgui = false; - break; - case MAGIC_UNSWAP_LCTL_LGUI: - keymap_config.swap_lctl_lgui = false; - break; - case MAGIC_UNSWAP_RCTL_RGUI: - keymap_config.swap_rctl_rgui = false; - break; - case MAGIC_UNNO_GUI: - keymap_config.no_gui = false; - break; - case MAGIC_UNSWAP_GRAVE_ESC: - keymap_config.swap_grave_esc = false; - break; - case MAGIC_UNSWAP_BACKSLASH_BACKSPACE: - keymap_config.swap_backslash_backspace = false; - break; - case MAGIC_UNHOST_NKRO: - clear_keyboard(); // clear first buffer to prevent stuck keys - keymap_config.nkro = false; - break; - case MAGIC_UNSWAP_ALT_GUI: - keymap_config.swap_lalt_lgui = keymap_config.swap_ralt_rgui = false; + break; + case MAGIC_UNSWAP_CONTROL_CAPSLOCK: + keymap_config.swap_control_capslock = false; + break; + case MAGIC_UNCAPSLOCK_TO_CONTROL: + keymap_config.capslock_to_control = false; + break; + case MAGIC_UNSWAP_LALT_LGUI: + keymap_config.swap_lalt_lgui = false; + break; + case MAGIC_UNSWAP_RALT_RGUI: + keymap_config.swap_ralt_rgui = false; + break; + case MAGIC_UNSWAP_LCTL_LGUI: + keymap_config.swap_lctl_lgui = false; + break; + case MAGIC_UNSWAP_RCTL_RGUI: + keymap_config.swap_rctl_rgui = false; + break; + case MAGIC_UNNO_GUI: + keymap_config.no_gui = false; + break; + case MAGIC_UNSWAP_GRAVE_ESC: + keymap_config.swap_grave_esc = false; + break; + case MAGIC_UNSWAP_BACKSLASH_BACKSPACE: + keymap_config.swap_backslash_backspace = false; + break; + case MAGIC_UNHOST_NKRO: + clear_keyboard(); // clear first buffer to prevent stuck keys + keymap_config.nkro = false; + break; + case MAGIC_UNSWAP_ALT_GUI: + keymap_config.swap_lalt_lgui = keymap_config.swap_ralt_rgui = false; #ifdef AUDIO_ENABLE - PLAY_SONG(ag_norm_song); + PLAY_SONG(ag_norm_song); #endif - break; - case MAGIC_UNSWAP_CTL_GUI: - keymap_config.swap_lctl_lgui = keymap_config.swap_rctl_rgui = false; + break; + case MAGIC_UNSWAP_CTL_GUI: + keymap_config.swap_lctl_lgui = keymap_config.swap_rctl_rgui = false; #ifdef AUDIO_ENABLE - PLAY_SONG(cg_norm_song); + PLAY_SONG(cg_norm_song); #endif - break; - case MAGIC_TOGGLE_ALT_GUI: - keymap_config.swap_lalt_lgui = !keymap_config.swap_lalt_lgui; - keymap_config.swap_ralt_rgui = keymap_config.swap_lalt_lgui; + break; + case MAGIC_TOGGLE_ALT_GUI: + keymap_config.swap_lalt_lgui = !keymap_config.swap_lalt_lgui; + keymap_config.swap_ralt_rgui = keymap_config.swap_lalt_lgui; #ifdef AUDIO_ENABLE - if (keymap_config.swap_ralt_rgui) { - PLAY_SONG(ag_swap_song); - } else { - PLAY_SONG(ag_norm_song); - } + if (keymap_config.swap_ralt_rgui) { + PLAY_SONG(ag_swap_song); + } else { + PLAY_SONG(ag_norm_song); + } #endif - break; - case MAGIC_TOGGLE_CTL_GUI: - keymap_config.swap_lctl_lgui = !keymap_config.swap_lctl_lgui; - keymap_config.swap_rctl_rgui = keymap_config.swap_lctl_lgui; + break; + case MAGIC_TOGGLE_CTL_GUI: + keymap_config.swap_lctl_lgui = !keymap_config.swap_lctl_lgui; + keymap_config.swap_rctl_rgui = keymap_config.swap_lctl_lgui; #ifdef AUDIO_ENABLE - if (keymap_config.swap_rctl_rgui) { - PLAY_SONG(cg_swap_song); - } else { - PLAY_SONG(cg_norm_song); - } + if (keymap_config.swap_rctl_rgui) { + PLAY_SONG(cg_swap_song); + } else { + PLAY_SONG(cg_norm_song); + } #endif - break; - case MAGIC_TOGGLE_NKRO: - clear_keyboard(); // clear first buffer to prevent stuck keys - keymap_config.nkro = !keymap_config.nkro; - break; - case MAGIC_EE_HANDS_LEFT: - eeconfig_update_handedness(true); - break; - case MAGIC_EE_HANDS_RIGHT: - eeconfig_update_handedness(false); - break; - default: - // Not a magic keycode so continue processing - return true; - } + break; + case MAGIC_TOGGLE_NKRO: + clear_keyboard(); // clear first buffer to prevent stuck keys + keymap_config.nkro = !keymap_config.nkro; + break; + case MAGIC_EE_HANDS_LEFT: + eeconfig_update_handedness(true); + break; + case MAGIC_EE_HANDS_RIGHT: + eeconfig_update_handedness(false); + break; + } - eeconfig_update_keymap(keymap_config.raw); - clear_keyboard(); // clear to prevent stuck keys + eeconfig_update_keymap(keymap_config.raw); + clear_keyboard(); // clear to prevent stuck keys + + return false; + } + } - return false; + // Not a magic keycode so continue processing + return true; } -- cgit v1.2.3 From ae40fc498b185d3d23908780a3d3425eb5ff05b5 Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Mon, 16 Dec 2019 20:27:53 +0000 Subject: Relocate RGB keycode processing (#7508) * Move rgb keycode logic to process_keycode * Fixes for rgb matrix * Fixes for mxss * Fix inc/dec logic, add comments * Fix return RAINBOW_SWIRL logic * stop external use of rgb helper functions * merge fix * Fix 'defined but not used' when all animations are disabled --- quantum/process_keycode/process_rgb.c | 141 ++++++++++++++++++++++++++++++++++ quantum/process_keycode/process_rgb.h | 20 +++++ 2 files changed, 161 insertions(+) create mode 100644 quantum/process_keycode/process_rgb.c create mode 100644 quantum/process_keycode/process_rgb.h (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_rgb.c b/quantum/process_keycode/process_rgb.c new file mode 100644 index 0000000000..c76166342f --- /dev/null +++ b/quantum/process_keycode/process_rgb.c @@ -0,0 +1,141 @@ +/* Copyright 2019 + * + * 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 . + */ +#include "process_rgb.h" +#include "rgb.h" + +typedef void (*rgb_func_pointer)(void); + +/** + * Wrapper for inc/dec rgb keycode + * + * noinline to optimise for firmware size not speed (not in hot path) + */ +static void __attribute__((noinline)) handleKeycodeRGB(const uint8_t is_shifted, const rgb_func_pointer inc_func, const rgb_func_pointer dec_func) { + if (is_shifted) { + dec_func(); + } else { + inc_func(); + } +} + +/** + * Wrapper for animation mode + * - if not in animation family -> jump to that animation + * - otherwise -> wrap round animation speed + * + * noinline to optimise for firmware size not speed (not in hot path) + */ +static void __attribute__((noinline,unused)) handleKeycodeRGBMode(const uint8_t start, const uint8_t end) { + if ((start <= rgblight_get_mode()) && (rgblight_get_mode() < end)) { + rgblight_step(); + } else { + rgblight_mode(start); + } +} + +/** + * Handle keycodes for both rgblight and rgbmatrix + */ +bool process_rgb(const uint16_t keycode, const keyrecord_t *record) { +#ifndef SPLIT_KEYBOARD + if (record->event.pressed) { +#else + // Split keyboards need to trigger on key-up for edge-case issue + if (!record->event.pressed) { +#endif + uint8_t shifted = get_mods() & (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)); + switch (keycode) { + case RGB_TOG: + rgblight_toggle(); + return false; + case RGB_MODE_FORWARD: + handleKeycodeRGB(shifted, rgblight_step, rgblight_step_reverse); + return false; + case RGB_MODE_REVERSE: + handleKeycodeRGB(shifted, rgblight_step_reverse, rgblight_step); + return false; + case RGB_HUI: + handleKeycodeRGB(shifted, rgblight_increase_hue, rgblight_decrease_hue); + return false; + case RGB_HUD: + handleKeycodeRGB(shifted, rgblight_decrease_hue, rgblight_increase_hue); + return false; + case RGB_SAI: + handleKeycodeRGB(shifted, rgblight_increase_sat, rgblight_decrease_sat); + return false; + case RGB_SAD: + handleKeycodeRGB(shifted, rgblight_decrease_sat, rgblight_increase_sat); + return false; + case RGB_VAI: + handleKeycodeRGB(shifted, rgblight_increase_val, rgblight_decrease_val); + return false; + case RGB_VAD: + handleKeycodeRGB(shifted, rgblight_decrease_val, rgblight_increase_val); + return false; + case RGB_SPI: + handleKeycodeRGB(shifted, rgblight_increase_speed, rgblight_decrease_speed); + return false; + case RGB_SPD: + handleKeycodeRGB(shifted, rgblight_decrease_speed, rgblight_increase_speed); + return false; + case RGB_MODE_PLAIN: + rgblight_mode(RGBLIGHT_MODE_STATIC_LIGHT); + return false; + case RGB_MODE_BREATHE: +#ifdef RGBLIGHT_EFFECT_BREATHING + handleKeycodeRGBMode(RGBLIGHT_MODE_BREATHING, RGBLIGHT_MODE_BREATHING_end); +#endif + return false; + case RGB_MODE_RAINBOW: +#ifdef RGBLIGHT_EFFECT_RAINBOW_MOOD + handleKeycodeRGBMode(RGBLIGHT_MODE_RAINBOW_MOOD, RGBLIGHT_MODE_RAINBOW_MOOD_end); +#endif + return false; + case RGB_MODE_SWIRL: +#ifdef RGBLIGHT_EFFECT_RAINBOW_SWIRL + handleKeycodeRGBMode(RGBLIGHT_MODE_RAINBOW_SWIRL, RGBLIGHT_MODE_RAINBOW_SWIRL_end); +#endif + return false; + case RGB_MODE_SNAKE: +#ifdef RGBLIGHT_EFFECT_SNAKE + handleKeycodeRGBMode(RGBLIGHT_MODE_SNAKE, RGBLIGHT_MODE_SNAKE_end); +#endif + return false; + case RGB_MODE_KNIGHT: +#ifdef RGBLIGHT_EFFECT_KNIGHT + handleKeycodeRGBMode(RGBLIGHT_MODE_KNIGHT, RGBLIGHT_MODE_KNIGHT_end); +#endif + return false; + case RGB_MODE_XMAS: +#ifdef RGBLIGHT_EFFECT_CHRISTMAS + rgblight_mode(RGBLIGHT_MODE_CHRISTMAS); +#endif + return false; + case RGB_MODE_GRADIENT: +#ifdef RGBLIGHT_EFFECT_STATIC_GRADIENT + handleKeycodeRGBMode(RGBLIGHT_MODE_STATIC_GRADIENT, RGBLIGHT_MODE_STATIC_GRADIENT_end); +#endif + return false; + case RGB_MODE_RGBTEST: +#ifdef RGBLIGHT_EFFECT_RGB_TEST + rgblight_mode(RGBLIGHT_MODE_RGB_TEST); +#endif + return false; + } + } + + return true; +} diff --git a/quantum/process_keycode/process_rgb.h b/quantum/process_keycode/process_rgb.h new file mode 100644 index 0000000000..26aca46896 --- /dev/null +++ b/quantum/process_keycode/process_rgb.h @@ -0,0 +1,20 @@ +/* Copyright 2019 + * + * 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 . + */ +#pragma once + +#include "quantum.h" + +bool process_rgb(const uint16_t keycode, const keyrecord_t *record); -- cgit v1.2.3 From d11238f748554d66718b8fc13caa6e3da93fdf16 Mon Sep 17 00:00:00 2001 From: Jeremy Bernhardt Date: Fri, 17 Jan 2020 15:15:58 -0600 Subject: switching to you know whats up mode (#7921) --- quantum/process_keycode/process_steno.c | 4 ++++ quantum/process_keycode/process_steno.h | 4 ---- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_steno.c b/quantum/process_keycode/process_steno.c index e0b33ec861..57e279f211 100644 --- a/quantum/process_keycode/process_steno.c +++ b/quantum/process_keycode/process_steno.c @@ -73,7 +73,9 @@ static void steno_clear_state(void) { static void send_steno_state(uint8_t size, bool send_empty) { for (uint8_t i = 0; i < size; ++i) { if (chord[i] || send_empty) { +#ifdef VIRTSER_ENABLE virtser_send(chord[i]); +#endif } } } @@ -105,7 +107,9 @@ static void send_steno_chord(void) { switch (mode) { case STENO_MODE_BOLT: send_steno_state(BOLT_STATE_SIZE, false); +#ifdef VIRTSER_ENABLE virtser_send(0); // terminating byte +#endif break; case STENO_MODE_GEMINI: chord[0] |= 0x80; // Indicate start of packet diff --git a/quantum/process_keycode/process_steno.h b/quantum/process_keycode/process_steno.h index 3675423728..ed049eb13f 100644 --- a/quantum/process_keycode/process_steno.h +++ b/quantum/process_keycode/process_steno.h @@ -18,10 +18,6 @@ #include "quantum.h" -#if defined(STENO_ENABLE) && !defined(VIRTSER_ENABLE) -# error "must have virtser enabled to use steno" -#endif - typedef enum { STENO_MODE_BOLT, STENO_MODE_GEMINI } steno_mode_t; bool process_steno(uint16_t keycode, keyrecord_t *record); -- cgit v1.2.3 From 667045b4928badaedb38f535d885a46ff8a454fb Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Sun, 19 Jan 2020 16:30:34 +0000 Subject: Run clang-format manually to fix recently changed files (#7934) * Run clang-format manually to fix recently changed files * Run clang-format manually to fix recently changed files - revert template files * Run clang-format manually to fix recently changed files - format off for ascii_to_keycode_lut --- quantum/process_keycode/process_rgb.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_rgb.c b/quantum/process_keycode/process_rgb.c index c76166342f..627e5986fb 100644 --- a/quantum/process_keycode/process_rgb.c +++ b/quantum/process_keycode/process_rgb.c @@ -20,8 +20,8 @@ typedef void (*rgb_func_pointer)(void); /** * Wrapper for inc/dec rgb keycode - * - * noinline to optimise for firmware size not speed (not in hot path) + * + * noinline to optimise for firmware size not speed (not in hot path) */ static void __attribute__((noinline)) handleKeycodeRGB(const uint8_t is_shifted, const rgb_func_pointer inc_func, const rgb_func_pointer dec_func) { if (is_shifted) { @@ -35,10 +35,10 @@ static void __attribute__((noinline)) handleKeycodeRGB(const uint8_t is_shifted, * Wrapper for animation mode * - if not in animation family -> jump to that animation * - otherwise -> wrap round animation speed - * - * noinline to optimise for firmware size not speed (not in hot path) + * + * noinline to optimise for firmware size not speed (not in hot path) */ -static void __attribute__((noinline,unused)) handleKeycodeRGBMode(const uint8_t start, const uint8_t end) { +static void __attribute__((noinline, unused)) handleKeycodeRGBMode(const uint8_t start, const uint8_t end) { if ((start <= rgblight_get_mode()) && (rgblight_get_mode() < end)) { rgblight_step(); } else { -- cgit v1.2.3 From 393937b43fe37a9faceb3a40e5f6fcc604659fb0 Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Wed, 5 Feb 2020 02:49:10 +0000 Subject: Relocate grave keycode processing (#8082) * Relocate grave keycode processing * Tidy up code * Refactor grave -> grave_esc --- quantum/process_keycode/process_grave_esc.c | 71 +++++++++++++++++++++++++++++ quantum/process_keycode/process_grave_esc.h | 20 ++++++++ 2 files changed, 91 insertions(+) create mode 100644 quantum/process_keycode/process_grave_esc.c create mode 100644 quantum/process_keycode/process_grave_esc.h (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_grave_esc.c b/quantum/process_keycode/process_grave_esc.c new file mode 100644 index 0000000000..41c50f5cb8 --- /dev/null +++ b/quantum/process_keycode/process_grave_esc.c @@ -0,0 +1,71 @@ +/* Copyright 2020 + * + * 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 . + */ +#include "process_grave_esc.h" + +/* true if the last press of GRAVE_ESC was shifted (i.e. GUI or SHIFT were pressed), false otherwise. + * Used to ensure that the correct keycode is released if the key is released. + */ +static bool grave_esc_was_shifted = false; + +bool process_grave_esc(uint16_t keycode, keyrecord_t *record) { + if (keycode == GRAVE_ESC) { + const uint8_t mods = get_mods(); + uint8_t shifted = mods & MOD_MASK_SG; + +#ifdef GRAVE_ESC_ALT_OVERRIDE + // if ALT is pressed, ESC is always sent + // this is handy for the cmd+opt+esc shortcut on macOS, among other things. + if (mods & MOD_MASK_ALT) { + shifted = 0; + } +#endif + +#ifdef GRAVE_ESC_CTRL_OVERRIDE + // if CTRL is pressed, ESC is always sent + // this is handy for the ctrl+shift+esc shortcut on windows, among other things. + if (mods & MOD_MASK_CTRL) { + shifted = 0; + } +#endif + +#ifdef GRAVE_ESC_GUI_OVERRIDE + // if GUI is pressed, ESC is always sent + if (mods & MOD_MASK_GUI) { + shifted = 0; + } +#endif + +#ifdef GRAVE_ESC_SHIFT_OVERRIDE + // if SHIFT is pressed, ESC is always sent + if (mods & MOD_MASK_SHIFT) { + shifted = 0; + } +#endif + + if (record->event.pressed) { + grave_esc_was_shifted = shifted; + add_key(shifted ? KC_GRAVE : KC_ESCAPE); + } else { + del_key(grave_esc_was_shifted ? KC_GRAVE : KC_ESCAPE); + } + + send_keyboard_report(); + return false; + } + + // Not a grave keycode so continue processing + return true; +} diff --git a/quantum/process_keycode/process_grave_esc.h b/quantum/process_keycode/process_grave_esc.h new file mode 100644 index 0000000000..bbf4483763 --- /dev/null +++ b/quantum/process_keycode/process_grave_esc.h @@ -0,0 +1,20 @@ +/* Copyright 2020 + * + * 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 . + */ +#pragma once + +#include "quantum.h" + +bool process_grave_esc(uint16_t keycode, keyrecord_t *record); -- cgit v1.2.3 From 371ff9dd6f9c4feada34622d9a43480495b07e50 Mon Sep 17 00:00:00 2001 From: Ryan Date: Mon, 24 Feb 2020 10:27:25 +1100 Subject: A proper `send_string()` for the Unicode feature (#8155) --- quantum/process_keycode/process_unicode_common.c | 49 ++++++++++++++++++++++++ quantum/process_keycode/process_unicode_common.h | 1 + 2 files changed, 50 insertions(+) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_unicode_common.c b/quantum/process_keycode/process_unicode_common.c index 94383f19b7..4ac305e661 100644 --- a/quantum/process_keycode/process_unicode_common.c +++ b/quantum/process_keycode/process_unicode_common.c @@ -178,6 +178,55 @@ void send_unicode_hex_string(const char *str) { } } +// Borrowed from https://nullprogram.com/blog/2017/10/06/ +const char *decode_utf8(const char *str, int32_t *code_point) { + const char *next; + + if (str[0] < 0x80) { // U+0000-007F + *code_point = str[0]; + next = str + 1; + } else if ((str[0] & 0xE0) == 0xC0) { // U+0080-07FF + *code_point = ((int32_t)(str[0] & 0x1F) << 6) | ((int32_t)(str[1] & 0x3F) << 0); + next = str + 2; + } else if ((str[0] & 0xF0) == 0xE0) { // U+0800-FFFF + *code_point = ((int32_t)(str[0] & 0x0F) << 12) | ((int32_t)(str[1] & 0x3F) << 6) | ((int32_t)(str[2] & 0x3F) << 0); + next = str + 3; + } else if ((str[0] & 0xF8) == 0xF0 && (str[0] <= 0xF4)) { // U+10000-10FFFF + // Skip for now - register_hex() only takes a uint16 + //*code_point = ((int32_t)(str[0] & 0x07) << 18) | ((int32_t)(str[1] & 0x3F) << 12) | ((int32_t)(str[2] & 0x3F) << 6) | ((int32_t)(str[3] & 0x3F) << 0); + *code_point = -1; + next = str + 4; + } else { + *code_point = -1; + next = str + 1; + } + + // part of a UTF-16 surrogate pair - invalid + if (*code_point >= 0xD800 && *code_point <= 0xDFFF) { + *code_point = -1; + } + + return next; +} + +void send_unicode_string(const char *str) { + if (!str) { + return; + } + + int32_t code_point = 0; + + while (*str) { + str = decode_utf8(str, &code_point); + + if (code_point >= 0) { + unicode_input_start(); + register_hex(code_point); + unicode_input_finish(); + } + } +} + bool process_unicode_common(uint16_t keycode, keyrecord_t *record) { if (record->event.pressed) { switch (keycode) { diff --git a/quantum/process_keycode/process_unicode_common.h b/quantum/process_keycode/process_unicode_common.h index cab6eea6ea..393db2d99e 100644 --- a/quantum/process_keycode/process_unicode_common.h +++ b/quantum/process_keycode/process_unicode_common.h @@ -80,6 +80,7 @@ void unicode_input_cancel(void); void register_hex(uint16_t hex); void send_unicode_hex_string(const char *str); +void send_unicode_string(const char *str); bool process_unicode_common(uint16_t keycode, keyrecord_t *record); -- cgit v1.2.3 From bb8d4b4d23ee04f6034f8880b8a9f93fa4673c38 Mon Sep 17 00:00:00 2001 From: Ryan Date: Tue, 25 Feb 2020 12:54:51 +1100 Subject: `send_unicode_string()`: Add support for code points > 0xFFFF (#8236) --- quantum/process_keycode/process_unicode_common.c | 24 ++++++++++++++++++++---- quantum/process_keycode/process_unicode_common.h | 1 + quantum/process_keycode/process_unicodemap.c | 20 -------------------- quantum/process_keycode/process_unicodemap.h | 1 - 4 files changed, 21 insertions(+), 25 deletions(-) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_unicode_common.c b/quantum/process_keycode/process_unicode_common.c index 4ac305e661..fc392813ae 100644 --- a/quantum/process_keycode/process_unicode_common.c +++ b/quantum/process_keycode/process_unicode_common.c @@ -150,6 +150,24 @@ void register_hex(uint16_t hex) { } } +void register_hex32(uint32_t hex) { + bool onzerostart = true; + for (int i = 7; i >= 0; i--) { + if (i <= 3) { + onzerostart = false; + } + uint8_t digit = ((hex >> (i * 4)) & 0xF); + if (digit == 0) { + if (!onzerostart) { + tap_code(hex_to_keycode(digit)); + } + } else { + tap_code(hex_to_keycode(digit)); + onzerostart = false; + } + } +} + void send_unicode_hex_string(const char *str) { if (!str) { return; @@ -192,9 +210,7 @@ const char *decode_utf8(const char *str, int32_t *code_point) { *code_point = ((int32_t)(str[0] & 0x0F) << 12) | ((int32_t)(str[1] & 0x3F) << 6) | ((int32_t)(str[2] & 0x3F) << 0); next = str + 3; } else if ((str[0] & 0xF8) == 0xF0 && (str[0] <= 0xF4)) { // U+10000-10FFFF - // Skip for now - register_hex() only takes a uint16 - //*code_point = ((int32_t)(str[0] & 0x07) << 18) | ((int32_t)(str[1] & 0x3F) << 12) | ((int32_t)(str[2] & 0x3F) << 6) | ((int32_t)(str[3] & 0x3F) << 0); - *code_point = -1; + *code_point = ((int32_t)(str[0] & 0x07) << 18) | ((int32_t)(str[1] & 0x3F) << 12) | ((int32_t)(str[2] & 0x3F) << 6) | ((int32_t)(str[3] & 0x3F) << 0); next = str + 4; } else { *code_point = -1; @@ -221,7 +237,7 @@ void send_unicode_string(const char *str) { if (code_point >= 0) { unicode_input_start(); - register_hex(code_point); + register_hex32(code_point); unicode_input_finish(); } } diff --git a/quantum/process_keycode/process_unicode_common.h b/quantum/process_keycode/process_unicode_common.h index 393db2d99e..13b6431bf0 100644 --- a/quantum/process_keycode/process_unicode_common.h +++ b/quantum/process_keycode/process_unicode_common.h @@ -79,6 +79,7 @@ void unicode_input_finish(void); void unicode_input_cancel(void); void register_hex(uint16_t hex); +void register_hex32(uint32_t hex); void send_unicode_hex_string(const char *str); void send_unicode_string(const char *str); diff --git a/quantum/process_keycode/process_unicodemap.c b/quantum/process_keycode/process_unicodemap.c index 4364f156c4..1be51a995c 100644 --- a/quantum/process_keycode/process_unicodemap.c +++ b/quantum/process_keycode/process_unicodemap.c @@ -16,26 +16,6 @@ #include "process_unicodemap.h" -void register_hex32(uint32_t hex) { - bool onzerostart = true; - for (int i = 7; i >= 0; i--) { - if (i <= 3) { - onzerostart = false; - } - uint8_t digit = ((hex >> (i * 4)) & 0xF); - if (digit == 0) { - if (!onzerostart) { - register_code(hex_to_keycode(digit)); - unregister_code(hex_to_keycode(digit)); - } - } else { - register_code(hex_to_keycode(digit)); - unregister_code(hex_to_keycode(digit)); - onzerostart = false; - } - } -} - __attribute__((weak)) uint16_t unicodemap_index(uint16_t keycode) { if (keycode >= QK_UNICODEMAP_PAIR) { // Keycode is a pair: extract index based on Shift / Caps Lock state diff --git a/quantum/process_keycode/process_unicodemap.h b/quantum/process_keycode/process_unicodemap.h index a4b6d77f3a..c429859bbb 100644 --- a/quantum/process_keycode/process_unicodemap.h +++ b/quantum/process_keycode/process_unicodemap.h @@ -20,6 +20,5 @@ extern const uint32_t PROGMEM unicode_map[]; -void register_hex32(uint32_t hex); uint16_t unicodemap_index(uint16_t keycode); bool process_unicodemap(uint16_t keycode, keyrecord_t *record); -- cgit v1.2.3 From 26eef35f07698d23aafae90e1c230b52e100a334 Mon Sep 17 00:00:00 2001 From: James Young Date: Sat, 29 Feb 2020 12:00:00 -0800 Subject: 2020 February 29 Breaking Changes Update (#8064) --- quantum/process_keycode/process_backlight.c | 51 +++++++++++++++++++++++++++++ quantum/process_keycode/process_backlight.h | 21 ++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 quantum/process_keycode/process_backlight.c create mode 100644 quantum/process_keycode/process_backlight.h (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_backlight.c b/quantum/process_keycode/process_backlight.c new file mode 100644 index 0000000000..4d12f6813a --- /dev/null +++ b/quantum/process_keycode/process_backlight.c @@ -0,0 +1,51 @@ +/* Copyright 2019 + * + * 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 . + */ + +#include "process_backlight.h" + +#include "backlight.h" + +bool process_backlight(uint16_t keycode, keyrecord_t *record) { + if (record->event.pressed) { + switch (keycode) { + case BL_ON: + backlight_level(BACKLIGHT_LEVELS); + return false; + case BL_OFF: + backlight_level(0); + return false; + case BL_DEC: + backlight_decrease(); + return false; + case BL_INC: + backlight_increase(); + return false; + case BL_TOGG: + backlight_toggle(); + return false; + case BL_STEP: + backlight_step(); + return false; +#ifdef BACKLIGHT_BREATHING + case BL_BRTG: + backlight_toggle_breathing(); + return false; +#endif + } + } + + return true; +} diff --git a/quantum/process_keycode/process_backlight.h b/quantum/process_keycode/process_backlight.h new file mode 100644 index 0000000000..7fe887ae67 --- /dev/null +++ b/quantum/process_keycode/process_backlight.h @@ -0,0 +1,21 @@ +/* Copyright 2019 + * + * 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 . + */ + +#pragma once + +#include "quantum.h" + +bool process_backlight(uint16_t keycode, keyrecord_t *record); -- cgit v1.2.3 From e5d34fd084a7bdde0867749470b27c50e8144eb8 Mon Sep 17 00:00:00 2001 From: Jeremy Bernhardt Date: Sun, 22 Mar 2020 07:17:26 -0600 Subject: Variable combo (#8120) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * keymap(gergo): colemak * added flipped numbers * add STENO_DISABLE_VIRTSER * add STENO_DISABLE_VIRTSER * Added GergoPlex and Faunchpad * push retab * push retab * added variable option for combos * removed accidental commit * removed accidental commit * More accidental deletions! (╯°□°)╯︵ ┻━┻ Co-authored-by: Damien Rajon <145502+pyrho@users.noreply.github.com> --- quantum/process_keycode/process_combo.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_combo.c b/quantum/process_keycode/process_combo.c index f40ca74525..25a6060639 100644 --- a/quantum/process_keycode/process_combo.c +++ b/quantum/process_keycode/process_combo.c @@ -17,9 +17,12 @@ #include "print.h" #include "process_combo.h" -__attribute__((weak)) combo_t key_combos[COMBO_COUNT] = { - -}; +#ifndef COMBO_VARIABLE_LEN +__attribute__((weak)) combo_t key_combos[COMBO_COUNT] = {}; +#else +extern combo_t key_combos[]; +extern int COMBO_LEN; +#endif __attribute__((weak)) void process_combo_event(uint8_t combo_index, bool pressed) {} @@ -141,8 +144,11 @@ bool process_combo(uint16_t keycode, keyrecord_t *record) { if (!is_combo_enabled()) { return true; } - +#ifndef COMBO_VARIABLE_LEN for (current_combo_index = 0; current_combo_index < COMBO_COUNT; ++current_combo_index) { +#else + for (current_combo_index = 0; current_combo_index < COMBO_LEN; ++current_combo_index) { +#endif combo_t *combo = &key_combos[current_combo_index]; is_combo_key |= process_single_combo(combo, keycode, record); no_combo_keys_pressed = no_combo_keys_pressed && NO_COMBO_KEYS_ARE_DOWN; -- cgit v1.2.3 From 6ceaae30f519b63b4b56e0277dd459cccf2d0729 Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Wed, 25 Mar 2020 03:39:53 +0000 Subject: Run clang-format manually to fix recently changed files (#8552) --- quantum/process_keycode/process_combo.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_combo.c b/quantum/process_keycode/process_combo.c index 25a6060639..c4e299958a 100644 --- a/quantum/process_keycode/process_combo.c +++ b/quantum/process_keycode/process_combo.c @@ -20,8 +20,8 @@ #ifndef COMBO_VARIABLE_LEN __attribute__((weak)) combo_t key_combos[COMBO_COUNT] = {}; #else -extern combo_t key_combos[]; -extern int COMBO_LEN; +extern combo_t key_combos[]; +extern int COMBO_LEN; #endif __attribute__((weak)) void process_combo_event(uint8_t combo_index, bool pressed) {} @@ -146,7 +146,7 @@ bool process_combo(uint16_t keycode, keyrecord_t *record) { } #ifndef COMBO_VARIABLE_LEN for (current_combo_index = 0; current_combo_index < COMBO_COUNT; ++current_combo_index) { -#else +#else for (current_combo_index = 0; current_combo_index < COMBO_LEN; ++current_combo_index) { #endif combo_t *combo = &key_combos[current_combo_index]; -- cgit v1.2.3 From bdfdc506da7702960bf3f6167a3a95f1230b0397 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20=C4=90or=C4=91evi=C4=87?= Date: Tue, 31 Mar 2020 18:28:43 +0200 Subject: Rename UC_OSX (and related constants) to UC_MAC (#8589) * Rename UC_OSX (and related constants) to UC_MAC * Update UNICODE_SONG_OSX references to UNICODE_SONG_MAC * Update UC_M_OS references to UC_M_MA * Add UC_OSX alias for backwards compatibility * Add deprecation warning for UC_OSX to Unicode docs * Add UC_M_OS alias for backwards compatibility * Update newly found UC_M_OS and UNICODE_SONG_OSX references * Add legacy UNICODE_MODE_OSX alias, revert changes to user keymaps * Add legacy UNICODE_SONG_OSX alias, revert changes to user keymaps * Replace removed sounds in Unicode song doc examples --- quantum/process_keycode/process_unicode_common.c | 22 +++++++++++----------- quantum/process_keycode/process_unicode_common.h | 15 ++++++++++++--- quantum/process_keycode/process_unicodemap.c | 2 +- 3 files changed, 24 insertions(+), 15 deletions(-) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_unicode_common.c b/quantum/process_keycode/process_unicode_common.c index fc392813ae..48ce3961ad 100644 --- a/quantum/process_keycode/process_unicode_common.c +++ b/quantum/process_keycode/process_unicode_common.c @@ -78,8 +78,8 @@ __attribute__((weak)) void unicode_input_start(void) { clear_mods(); // Unregister mods to start from a clean state switch (unicode_config.input_mode) { - case UC_OSX: - register_code(UNICODE_KEY_OSX); + case UC_MAC: + register_code(UNICODE_KEY_MAC); break; case UC_LNX: tap_code16(UNICODE_KEY_LNX); @@ -99,8 +99,8 @@ __attribute__((weak)) void unicode_input_start(void) { __attribute__((weak)) void unicode_input_finish(void) { switch (unicode_config.input_mode) { - case UC_OSX: - unregister_code(UNICODE_KEY_OSX); + case UC_MAC: + unregister_code(UNICODE_KEY_MAC); break; case UC_LNX: tap_code(KC_SPC); @@ -118,8 +118,8 @@ __attribute__((weak)) void unicode_input_finish(void) { __attribute__((weak)) void unicode_input_cancel(void) { switch (unicode_config.input_mode) { - case UC_OSX: - unregister_code(UNICODE_KEY_OSX); + case UC_MAC: + unregister_code(UNICODE_KEY_MAC); break; case UC_LNX: case UC_WINC: @@ -253,11 +253,11 @@ bool process_unicode_common(uint16_t keycode, keyrecord_t *record) { cycle_unicode_input_mode(-1); break; - case UNICODE_MODE_OSX: - set_unicode_input_mode(UC_OSX); -#if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_OSX) - static float song_osx[][2] = UNICODE_SONG_OSX; - PLAY_SONG(song_osx); + case UNICODE_MODE_MAC: + set_unicode_input_mode(UC_MAC); +#if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_MAC) + static float song_mac[][2] = UNICODE_SONG_MAC; + PLAY_SONG(song_mac); #endif break; case UNICODE_MODE_LNX: diff --git a/quantum/process_keycode/process_unicode_common.h b/quantum/process_keycode/process_unicode_common.h index 13b6431bf0..5421c28c7f 100644 --- a/quantum/process_keycode/process_unicode_common.h +++ b/quantum/process_keycode/process_unicode_common.h @@ -23,8 +23,8 @@ #endif // Keycodes used for starting Unicode input on different platforms -#ifndef UNICODE_KEY_OSX -# define UNICODE_KEY_OSX KC_LALT +#ifndef UNICODE_KEY_MAC +# define UNICODE_KEY_MAC KC_LALT #endif #ifndef UNICODE_KEY_LNX # define UNICODE_KEY_LNX LCTL(LSFT(KC_U)) @@ -49,8 +49,17 @@ # define UNICODE_TYPE_DELAY 10 #endif +// Deprecated aliases +#if !defined(UNICODE_KEY_MAC) && defined(UNICODE_KEY_OSX) +# define UNICODE_KEY_MAC UNICODE_KEY_OSX +#endif +#if !defined(UNICODE_SONG_MAC) && defined(UNICODE_SONG_OSX) +# define UNICODE_SONG_MAC UNICODE_SONG_OSX +#endif +#define UC_OSX UC_MAC + enum unicode_input_modes { - UC_OSX, // Mac OS X using Unicode Hex Input + UC_MAC, // macOS using Unicode Hex Input UC_LNX, // Linux using IBus UC_WIN, // Windows using EnableHexNumpad UC_BSD, // BSD (not implemented) diff --git a/quantum/process_keycode/process_unicodemap.c b/quantum/process_keycode/process_unicodemap.c index 1be51a995c..5445cde129 100644 --- a/quantum/process_keycode/process_unicodemap.c +++ b/quantum/process_keycode/process_unicodemap.c @@ -43,7 +43,7 @@ bool process_unicodemap(uint16_t keycode, keyrecord_t *record) { if (code > 0x10FFFF || (code > 0xFFFF && input_mode == UC_WIN)) { // Character is out of range supported by the platform unicode_input_cancel(); - } else if (code > 0xFFFF && input_mode == UC_OSX) { + } else if (code > 0xFFFF && input_mode == UC_MAC) { // Convert to UTF-16 surrogate pair on Mac code -= 0x10000; uint32_t lo = code & 0x3FF, hi = (code & 0xFFC00) >> 10; -- cgit v1.2.3 From 94fc32f43135ac4afb14849c7fb5e99f95455078 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20=C4=90or=C4=91evi=C4=87?= Date: Sat, 9 May 2020 10:22:02 +0200 Subject: Fix bug in UC_RMOD, add shift and audio support for UC_MOD/UC_RMOD(#8674) * Invert UC_MOD/UC_RMOD direction when Shift is held Also use MOD_MASK_SHIFT in process_rgb.c * Allow audio to be played for UC_MOD, UC_RMOD keycodes as well * Fix signedness bug in reverse input mode cycling * Misc formatting in process_unicode_common.c * Address clang-format issues * Make decode_utf8 helper function file-local (static) --- quantum/process_keycode/process_rgb.c | 2 +- quantum/process_keycode/process_unicode_common.c | 118 ++++++++++++++--------- quantum/process_keycode/process_unicode_common.h | 2 +- quantum/process_keycode/process_unicodemap.c | 3 +- 4 files changed, 74 insertions(+), 51 deletions(-) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_rgb.c b/quantum/process_keycode/process_rgb.c index 627e5986fb..21164b8f9f 100644 --- a/quantum/process_keycode/process_rgb.c +++ b/quantum/process_keycode/process_rgb.c @@ -56,7 +56,7 @@ bool process_rgb(const uint16_t keycode, const keyrecord_t *record) { // Split keyboards need to trigger on key-up for edge-case issue if (!record->event.pressed) { #endif - uint8_t shifted = get_mods() & (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)); + uint8_t shifted = get_mods() & MOD_MASK_SHIFT; switch (keycode) { case RGB_TOG: rgblight_toggle(); diff --git a/quantum/process_keycode/process_unicode_common.c b/quantum/process_keycode/process_unicode_common.c index 48ce3961ad..fb50215012 100644 --- a/quantum/process_keycode/process_unicode_common.c +++ b/quantum/process_keycode/process_unicode_common.c @@ -24,8 +24,8 @@ uint8_t unicode_saved_mods; #if UNICODE_SELECTED_MODES != -1 static uint8_t selected[] = {UNICODE_SELECTED_MODES}; -static uint8_t selected_count = sizeof selected / sizeof *selected; -static uint8_t selected_index; +static int8_t selected_count = sizeof selected / sizeof *selected; +static int8_t selected_index; #endif void unicode_input_mode_init(void) { @@ -33,7 +33,7 @@ void unicode_input_mode_init(void) { #if UNICODE_SELECTED_MODES != -1 # if UNICODE_CYCLE_PERSIST // Find input_mode in selected modes - uint8_t i; + int8_t i; for (i = 0; i < selected_count; i++) { if (selected[i] == unicode_config.input_mode) { selected_index = i; @@ -60,9 +60,12 @@ void set_unicode_input_mode(uint8_t mode) { dprintf("Unicode input mode set to: %u\n", unicode_config.input_mode); } -void cycle_unicode_input_mode(uint8_t offset) { +void cycle_unicode_input_mode(int8_t offset) { #if UNICODE_SELECTED_MODES != -1 - selected_index = (selected_index + offset) % selected_count; + selected_index = (selected_index + offset) % selected_count; + if (selected_index < 0) { + selected_index += selected_count; + } unicode_config.input_mode = selected[selected_index]; # if UNICODE_CYCLE_PERSIST persist_unicode_input_mode(); @@ -168,6 +171,8 @@ void register_hex32(uint32_t hex) { } } +// clang-format off + void send_unicode_hex_string(const char *str) { if (!str) { return; @@ -175,12 +180,11 @@ void send_unicode_hex_string(const char *str) { while (*str) { // Find the next code point (token) in the string - for (; *str == ' '; str++) - ; + for (; *str == ' '; str++); // Skip leading spaces size_t n = strcspn(str, " "); // Length of the current token - char code_point[n + 1]; - strncpy(code_point, str, n); - code_point[n] = '\0'; // Make sure it's null-terminated + char code_point[n+1]; + strncpy(code_point, str, n); // Copy token into buffer + code_point[n] = '\0'; // Make sure it's null-terminated // Normalize the code point: make all hex digits lowercase for (char *p = code_point; *p; p++) { @@ -196,8 +200,10 @@ void send_unicode_hex_string(const char *str) { } } +// clang-format on + // Borrowed from https://nullprogram.com/blog/2017/10/06/ -const char *decode_utf8(const char *str, int32_t *code_point) { +static const char *decode_utf8(const char *str, int32_t *code_point) { const char *next; if (str[0] < 0x80) { // U+0000-007F @@ -231,7 +237,6 @@ void send_unicode_string(const char *str) { } int32_t code_point = 0; - while (*str) { str = decode_utf8(str, &code_point); @@ -243,53 +248,70 @@ void send_unicode_string(const char *str) { } } +// clang-format off + +static void audio_helper(void) { +#ifdef AUDIO_ENABLE + switch (get_unicode_input_mode()) { +# ifdef UNICODE_SONG_MAC + static float song_mac[][2] = UNICODE_SONG_MAC; + case UC_MAC: + PLAY_SONG(song_mac); + break; +# endif +# ifdef UNICODE_SONG_LNX + static float song_lnx[][2] = UNICODE_SONG_LNX; + case UC_LNX: + PLAY_SONG(song_lnx); + break; +# endif +# ifdef UNICODE_SONG_WIN + static float song_win[][2] = UNICODE_SONG_WIN; + case UC_WIN: + PLAY_SONG(song_win); + break; +# endif +# ifdef UNICODE_SONG_BSD + static float song_bsd[][2] = UNICODE_SONG_BSD; + case UC_BSD: + PLAY_SONG(song_bsd); + break; +# endif +# ifdef UNICODE_SONG_WINC + static float song_winc[][2] = UNICODE_SONG_WINC; + case UC_WINC: + PLAY_SONG(song_winc); + break; +# endif + } +#endif +} + +// clang-format on + bool process_unicode_common(uint16_t keycode, keyrecord_t *record) { if (record->event.pressed) { + bool shifted = get_mods() & MOD_MASK_SHIFT; switch (keycode) { case UNICODE_MODE_FORWARD: - cycle_unicode_input_mode(+1); + cycle_unicode_input_mode(shifted ? -1 : +1); + audio_helper(); break; case UNICODE_MODE_REVERSE: - cycle_unicode_input_mode(-1); + cycle_unicode_input_mode(shifted ? +1 : -1); + audio_helper(); break; - case UNICODE_MODE_MAC: - set_unicode_input_mode(UC_MAC); -#if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_MAC) - static float song_mac[][2] = UNICODE_SONG_MAC; - PLAY_SONG(song_mac); -#endif - break; - case UNICODE_MODE_LNX: - set_unicode_input_mode(UC_LNX); -#if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_LNX) - static float song_lnx[][2] = UNICODE_SONG_LNX; - PLAY_SONG(song_lnx); -#endif - break; - case UNICODE_MODE_WIN: - set_unicode_input_mode(UC_WIN); -#if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_WIN) - static float song_win[][2] = UNICODE_SONG_WIN; - PLAY_SONG(song_win); -#endif - break; - case UNICODE_MODE_BSD: - set_unicode_input_mode(UC_BSD); -#if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_BSD) - static float song_bsd[][2] = UNICODE_SONG_BSD; - PLAY_SONG(song_bsd); -#endif - break; - case UNICODE_MODE_WINC: - set_unicode_input_mode(UC_WINC); -#if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_WINC) - static float song_winc[][2] = UNICODE_SONG_WINC; - PLAY_SONG(song_winc); -#endif + case UNICODE_MODE_MAC ... UNICODE_MODE_WINC: { + // Keycodes and input modes follow the same ordering + uint8_t delta = keycode - UNICODE_MODE_MAC; + set_unicode_input_mode(UC_MAC + delta); + audio_helper(); break; + } } } + #if defined(UNICODE_ENABLE) return process_unicode(keycode, record); #elif defined(UNICODEMAP_ENABLE) diff --git a/quantum/process_keycode/process_unicode_common.h b/quantum/process_keycode/process_unicode_common.h index 5421c28c7f..4579fde8d5 100644 --- a/quantum/process_keycode/process_unicode_common.h +++ b/quantum/process_keycode/process_unicode_common.h @@ -80,7 +80,7 @@ extern uint8_t unicode_saved_mods; void unicode_input_mode_init(void); uint8_t get_unicode_input_mode(void); void set_unicode_input_mode(uint8_t mode); -void cycle_unicode_input_mode(uint8_t offset); +void cycle_unicode_input_mode(int8_t offset); void persist_unicode_input_mode(void); void unicode_input_start(void); diff --git a/quantum/process_keycode/process_unicodemap.c b/quantum/process_keycode/process_unicodemap.c index 5445cde129..2f402a2fd2 100644 --- a/quantum/process_keycode/process_unicodemap.c +++ b/quantum/process_keycode/process_unicodemap.c @@ -21,7 +21,8 @@ __attribute__((weak)) uint16_t unicodemap_index(uint16_t keycode) { // Keycode is a pair: extract index based on Shift / Caps Lock state uint16_t index = keycode - QK_UNICODEMAP_PAIR; - bool shift = unicode_saved_mods & MOD_MASK_SHIFT, caps = IS_HOST_LED_ON(USB_LED_CAPS_LOCK); + bool shift = unicode_saved_mods & MOD_MASK_SHIFT; + bool caps = IS_HOST_LED_ON(USB_LED_CAPS_LOCK); if (shift ^ caps) { index >>= 7; } -- cgit v1.2.3 From f7eb030e917a8fa360ad7cc7bb26d804cf4c5f6c Mon Sep 17 00:00:00 2001 From: Jason Laqua Date: Thu, 18 Jun 2020 02:07:34 -0500 Subject: Standardize how unicode is processed (fixes #8768) (#8770) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Konstantin Đorđević --- quantum/process_keycode/process_ucis.c | 97 ++++++++++-------------- quantum/process_keycode/process_ucis.h | 26 +++++-- quantum/process_keycode/process_unicode_common.c | 25 +++++- quantum/process_keycode/process_unicode_common.h | 2 + quantum/process_keycode/process_unicodemap.c | 21 +---- 5 files changed, 81 insertions(+), 90 deletions(-) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_ucis.c b/quantum/process_keycode/process_ucis.c index 024077317f..2541d6eb26 100644 --- a/quantum/process_keycode/process_ucis.c +++ b/quantum/process_keycode/process_ucis.c @@ -27,7 +27,7 @@ void qk_ucis_start(void) { __attribute__((weak)) void qk_ucis_start_user(void) { unicode_input_start(); - register_hex(0x2328); + register_hex(0x2328); // ⌨ unicode_input_finish(); } @@ -35,74 +35,54 @@ __attribute__((weak)) void qk_ucis_success(uint8_t symbol_index) {} static bool is_uni_seq(char *seq) { uint8_t i; - for (i = 0; seq[i]; i++) { - uint16_t code; - if (('1' <= seq[i]) && (seq[i] <= '0')) - code = seq[i] - '1' + KC_1; - else - code = seq[i] - 'a' + KC_A; - - if (i > qk_ucis_state.count || qk_ucis_state.codes[i] != code) return false; + uint16_t keycode; + if ('1' <= seq[i] && seq[i] <= '0') { + keycode = seq[i] - '1' + KC_1; + } else { + keycode = seq[i] - 'a' + KC_A; + } + if (i > qk_ucis_state.count || qk_ucis_state.codes[i] != keycode) { + return false; + } } - - return (qk_ucis_state.codes[i] == KC_ENT || qk_ucis_state.codes[i] == KC_SPC); + return qk_ucis_state.codes[i] == KC_ENT || qk_ucis_state.codes[i] == KC_SPC; } __attribute__((weak)) void qk_ucis_symbol_fallback(void) { for (uint8_t i = 0; i < qk_ucis_state.count - 1; i++) { - uint8_t code = qk_ucis_state.codes[i]; - register_code(code); - unregister_code(code); + uint8_t keycode = qk_ucis_state.codes[i]; + register_code(keycode); + unregister_code(keycode); wait_ms(UNICODE_TYPE_DELAY); } } __attribute__((weak)) void qk_ucis_cancel(void) {} -void register_ucis(const char *hex) { - for (int i = 0; hex[i]; i++) { - uint8_t kc = 0; - char c = hex[i]; - - switch (c) { - case '0': - kc = KC_0; - break; - case '1' ... '9': - kc = c - '1' + KC_1; - break; - case 'a' ... 'f': - kc = c - 'a' + KC_A; - break; - case 'A' ... 'F': - kc = c - 'A' + KC_A; - break; - } - - if (kc) { - register_code(kc); - unregister_code(kc); - wait_ms(UNICODE_TYPE_DELAY); - } +void register_ucis(const uint32_t *code_points) { + for (int i = 0; i < UCIS_MAX_CODE_POINTS && code_points[i]; i++) { + register_unicode(code_points[i]); + wait_ms(UNICODE_TYPE_DELAY); } } bool process_ucis(uint16_t keycode, keyrecord_t *record) { - uint8_t i; - - if (!qk_ucis_state.in_progress) return true; + if (!qk_ucis_state.in_progress || !record->event.pressed) { + return true; + } - if (qk_ucis_state.count >= UCIS_MAX_SYMBOL_LENGTH && !(keycode == KC_BSPC || keycode == KC_ESC || keycode == KC_SPC || keycode == KC_ENT)) { + bool special = keycode == KC_SPC || keycode == KC_ENT || + keycode == KC_ESC || keycode == KC_BSPC; + if (qk_ucis_state.count >= UCIS_MAX_SYMBOL_LENGTH && !special) { return false; } - if (!record->event.pressed) return true; - qk_ucis_state.codes[qk_ucis_state.count] = keycode; qk_ucis_state.count++; - if (keycode == KC_BSPC) { + switch (keycode) { + case KC_BSPC: if (qk_ucis_state.count >= 2) { qk_ucis_state.count -= 2; return true; @@ -110,12 +90,11 @@ bool process_ucis(uint16_t keycode, keyrecord_t *record) { qk_ucis_state.count--; return false; } - } - if (keycode == KC_ENT || keycode == KC_SPC || keycode == KC_ESC) { - bool symbol_found = false; - - for (i = qk_ucis_state.count; i > 0; i--) { + case KC_SPC: + case KC_ENT: + case KC_ESC: + for (uint8_t i = 0; i < qk_ucis_state.count; i++) { register_code(KC_BSPC); unregister_code(KC_BSPC); wait_ms(UNICODE_TYPE_DELAY); @@ -127,25 +106,25 @@ bool process_ucis(uint16_t keycode, keyrecord_t *record) { return false; } - unicode_input_start(); + uint8_t i; + bool symbol_found = false; for (i = 0; ucis_symbol_table[i].symbol; i++) { if (is_uni_seq(ucis_symbol_table[i].symbol)) { symbol_found = true; - register_ucis(ucis_symbol_table[i].code + 2); + register_ucis(ucis_symbol_table[i].code_points); break; } } - if (!symbol_found) { - qk_ucis_symbol_fallback(); - } - unicode_input_finish(); - if (symbol_found) { qk_ucis_success(i); + } else { + qk_ucis_symbol_fallback(); } qk_ucis_state.in_progress = false; return false; + + default: + return true; } - return true; } diff --git a/quantum/process_keycode/process_ucis.h b/quantum/process_keycode/process_ucis.h index 0f93a198bb..a667430bda 100644 --- a/quantum/process_keycode/process_ucis.h +++ b/quantum/process_keycode/process_ucis.h @@ -22,10 +22,13 @@ #ifndef UCIS_MAX_SYMBOL_LENGTH # define UCIS_MAX_SYMBOL_LENGTH 32 #endif +#ifndef UCIS_MAX_CODE_POINTS +# define UCIS_MAX_CODE_POINTS 3 +#endif typedef struct { - char *symbol; - char *code; + char * symbol; + uint32_t code_points[UCIS_MAX_CODE_POINTS]; } qk_ucis_symbol_t; typedef struct { @@ -36,12 +39,17 @@ typedef struct { extern qk_ucis_state_t qk_ucis_state; -#define UCIS_TABLE(...) \ - { \ - __VA_ARGS__, { NULL, NULL } \ +// clang-format off + +#define UCIS_TABLE(...) \ + { \ + __VA_ARGS__, \ + { NULL, {} } \ } -#define UCIS_SYM(name, code) \ - { name, #code } +#define UCIS_SYM(name, ...) \ + { name, {__VA_ARGS__} } + +// clang-format on extern const qk_ucis_symbol_t ucis_symbol_table[]; @@ -49,5 +57,7 @@ void qk_ucis_start(void); void qk_ucis_start_user(void); void qk_ucis_symbol_fallback(void); void qk_ucis_success(uint8_t symbol_index); -void register_ucis(const char *hex); + +void register_ucis(const uint32_t *code_points); + bool process_ucis(uint16_t keycode, keyrecord_t *record); diff --git a/quantum/process_keycode/process_unicode_common.c b/quantum/process_keycode/process_unicode_common.c index fb50215012..bea34c31ea 100644 --- a/quantum/process_keycode/process_unicode_common.c +++ b/quantum/process_keycode/process_unicode_common.c @@ -171,6 +171,25 @@ void register_hex32(uint32_t hex) { } } +void register_unicode(uint32_t code_point) { + if (code_point > 0x10FFFF || (code_point > 0xFFFF && unicode_config.input_mode == UC_WIN)) { + // Code point out of range, do nothing + return; + } + + unicode_input_start(); + if (code_point > 0xFFFF && unicode_config.input_mode == UC_MAC) { + // Convert code point to UTF-16 surrogate pair on macOS + code_point -= 0x10000; + uint32_t lo = code_point & 0x3FF, hi = (code_point & 0xFFC00) >> 10; + register_hex32(hi + 0xD800); + register_hex32(lo + 0xDC00); + } else { + register_hex32(code_point); + } + unicode_input_finish(); +} + // clang-format off void send_unicode_hex_string(const char *str) { @@ -236,14 +255,12 @@ void send_unicode_string(const char *str) { return; } - int32_t code_point = 0; while (*str) { + int32_t code_point = 0; str = decode_utf8(str, &code_point); if (code_point >= 0) { - unicode_input_start(); - register_hex32(code_point); - unicode_input_finish(); + register_unicode(code_point); } } } diff --git a/quantum/process_keycode/process_unicode_common.h b/quantum/process_keycode/process_unicode_common.h index 4579fde8d5..3082fbb5f0 100644 --- a/quantum/process_keycode/process_unicode_common.h +++ b/quantum/process_keycode/process_unicode_common.h @@ -89,6 +89,8 @@ void unicode_input_cancel(void); void register_hex(uint16_t hex); void register_hex32(uint32_t hex); +void register_unicode(uint32_t code_point); + void send_unicode_hex_string(const char *str); void send_unicode_string(const char *str); diff --git a/quantum/process_keycode/process_unicodemap.c b/quantum/process_keycode/process_unicodemap.c index 2f402a2fd2..789a90445b 100644 --- a/quantum/process_keycode/process_unicodemap.c +++ b/quantum/process_keycode/process_unicodemap.c @@ -36,25 +36,8 @@ __attribute__((weak)) uint16_t unicodemap_index(uint16_t keycode) { bool process_unicodemap(uint16_t keycode, keyrecord_t *record) { if (keycode >= QK_UNICODEMAP && keycode <= QK_UNICODEMAP_PAIR_MAX && record->event.pressed) { - unicode_input_start(); - - uint32_t code = pgm_read_dword(unicode_map + unicodemap_index(keycode)); - uint8_t input_mode = get_unicode_input_mode(); - - if (code > 0x10FFFF || (code > 0xFFFF && input_mode == UC_WIN)) { - // Character is out of range supported by the platform - unicode_input_cancel(); - } else if (code > 0xFFFF && input_mode == UC_MAC) { - // Convert to UTF-16 surrogate pair on Mac - code -= 0x10000; - uint32_t lo = code & 0x3FF, hi = (code & 0xFFC00) >> 10; - register_hex32(hi + 0xD800); - register_hex32(lo + 0xDC00); - unicode_input_finish(); - } else { - register_hex32(code); - unicode_input_finish(); - } + uint32_t code_point = pgm_read_dword(unicode_map + unicodemap_index(keycode)); + register_unicode(code_point); } return true; } -- cgit v1.2.3 From 3d6d89966614be1e80d9957fb83743934c5eb162 Mon Sep 17 00:00:00 2001 From: Nick Brassel Date: Mon, 22 Jun 2020 11:21:48 +1000 Subject: `qmk cformat` (#9500) --- quantum/process_keycode/process_ucis.c | 79 ++++++++++++------------ quantum/process_keycode/process_unicode_common.c | 2 +- quantum/process_keycode/process_unicodemap.c | 2 +- 3 files changed, 41 insertions(+), 42 deletions(-) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_ucis.c b/quantum/process_keycode/process_ucis.c index 2541d6eb26..12b0aba9bf 100644 --- a/quantum/process_keycode/process_ucis.c +++ b/quantum/process_keycode/process_ucis.c @@ -72,8 +72,7 @@ bool process_ucis(uint16_t keycode, keyrecord_t *record) { return true; } - bool special = keycode == KC_SPC || keycode == KC_ENT || - keycode == KC_ESC || keycode == KC_BSPC; + bool special = keycode == KC_SPC || keycode == KC_ENT || keycode == KC_ESC || keycode == KC_BSPC; if (qk_ucis_state.count >= UCIS_MAX_SYMBOL_LENGTH && !special) { return false; } @@ -82,49 +81,49 @@ bool process_ucis(uint16_t keycode, keyrecord_t *record) { qk_ucis_state.count++; switch (keycode) { - case KC_BSPC: - if (qk_ucis_state.count >= 2) { - qk_ucis_state.count -= 2; - return true; - } else { - qk_ucis_state.count--; - return false; - } + case KC_BSPC: + if (qk_ucis_state.count >= 2) { + qk_ucis_state.count -= 2; + return true; + } else { + qk_ucis_state.count--; + return false; + } - case KC_SPC: - case KC_ENT: - case KC_ESC: - for (uint8_t i = 0; i < qk_ucis_state.count; i++) { - register_code(KC_BSPC); - unregister_code(KC_BSPC); - wait_ms(UNICODE_TYPE_DELAY); - } + case KC_SPC: + case KC_ENT: + case KC_ESC: + for (uint8_t i = 0; i < qk_ucis_state.count; i++) { + register_code(KC_BSPC); + unregister_code(KC_BSPC); + wait_ms(UNICODE_TYPE_DELAY); + } - if (keycode == KC_ESC) { - qk_ucis_state.in_progress = false; - qk_ucis_cancel(); - return false; - } + if (keycode == KC_ESC) { + qk_ucis_state.in_progress = false; + qk_ucis_cancel(); + return false; + } - uint8_t i; - bool symbol_found = false; - for (i = 0; ucis_symbol_table[i].symbol; i++) { - if (is_uni_seq(ucis_symbol_table[i].symbol)) { - symbol_found = true; - register_ucis(ucis_symbol_table[i].code_points); - break; + uint8_t i; + bool symbol_found = false; + for (i = 0; ucis_symbol_table[i].symbol; i++) { + if (is_uni_seq(ucis_symbol_table[i].symbol)) { + symbol_found = true; + register_ucis(ucis_symbol_table[i].code_points); + break; + } + } + if (symbol_found) { + qk_ucis_success(i); + } else { + qk_ucis_symbol_fallback(); } - } - if (symbol_found) { - qk_ucis_success(i); - } else { - qk_ucis_symbol_fallback(); - } - qk_ucis_state.in_progress = false; - return false; + qk_ucis_state.in_progress = false; + return false; - default: - return true; + default: + return true; } } diff --git a/quantum/process_keycode/process_unicode_common.c b/quantum/process_keycode/process_unicode_common.c index bea34c31ea..84c44d9874 100644 --- a/quantum/process_keycode/process_unicode_common.c +++ b/quantum/process_keycode/process_unicode_common.c @@ -257,7 +257,7 @@ void send_unicode_string(const char *str) { while (*str) { int32_t code_point = 0; - str = decode_utf8(str, &code_point); + str = decode_utf8(str, &code_point); if (code_point >= 0) { register_unicode(code_point); diff --git a/quantum/process_keycode/process_unicodemap.c b/quantum/process_keycode/process_unicodemap.c index 789a90445b..fcf676c24e 100644 --- a/quantum/process_keycode/process_unicodemap.c +++ b/quantum/process_keycode/process_unicodemap.c @@ -22,7 +22,7 @@ __attribute__((weak)) uint16_t unicodemap_index(uint16_t keycode) { uint16_t index = keycode - QK_UNICODEMAP_PAIR; bool shift = unicode_saved_mods & MOD_MASK_SHIFT; - bool caps = IS_HOST_LED_ON(USB_LED_CAPS_LOCK); + bool caps = IS_HOST_LED_ON(USB_LED_CAPS_LOCK); if (shift ^ caps) { index >>= 7; } -- cgit v1.2.3 From 98642ca02878741531105bd879c0d61110198b62 Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Mon, 22 Jun 2020 01:38:58 -0700 Subject: Improve keycode handling for RGB (#7677) Co-authored-by: drashna Co-authored-by: noroadsleft <18669334+noroadsleft@users.noreply.github.com> --- quantum/process_keycode/process_rgb.c | 85 +++++++++++++++++++++++++++++++---- 1 file changed, 77 insertions(+), 8 deletions(-) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_rgb.c b/quantum/process_keycode/process_rgb.c index 21164b8f9f..a1e46e0348 100644 --- a/quantum/process_keycode/process_rgb.c +++ b/quantum/process_keycode/process_rgb.c @@ -59,78 +59,147 @@ bool process_rgb(const uint16_t keycode, const keyrecord_t *record) { uint8_t shifted = get_mods() & MOD_MASK_SHIFT; switch (keycode) { case RGB_TOG: +#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES) rgblight_toggle(); +#endif +#if defined(RGB_MATRIX_ENABLE) && !defined(RGB_MATRIX_DISABLE_KEYCODES) + rgb_matrix_toggle(); +#endif return false; case RGB_MODE_FORWARD: +#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES) handleKeycodeRGB(shifted, rgblight_step, rgblight_step_reverse); +#endif +#if defined(RGB_MATRIX_ENABLE) && !defined(RGB_MATRIX_DISABLE_KEYCODES) + handleKeycodeRGB(shifted, rgb_matrix_step, rgb_matrix_step_reverse); +#endif return false; case RGB_MODE_REVERSE: +#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES) handleKeycodeRGB(shifted, rgblight_step_reverse, rgblight_step); +#endif +#if defined(RGB_MATRIX_ENABLE) && !defined(RGB_MATRIX_DISABLE_KEYCODES) + handleKeycodeRGB(shifted, rgb_matrix_step_reverse, rgb_matrix_step); +#endif return false; case RGB_HUI: +#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES) handleKeycodeRGB(shifted, rgblight_increase_hue, rgblight_decrease_hue); +#endif +#if defined(RGB_MATRIX_ENABLE) && !defined(RGB_MATRIX_DISABLE_KEYCODES) + handleKeycodeRGB(shifted, rgb_matrix_increase_hue, rgb_matrix_decrease_hue); +#endif return false; case RGB_HUD: +#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES) handleKeycodeRGB(shifted, rgblight_decrease_hue, rgblight_increase_hue); +#endif +#if defined(RGB_MATRIX_ENABLE) && !defined(RGB_MATRIX_DISABLE_KEYCODES) + handleKeycodeRGB(shifted, rgb_matrix_decrease_hue, rgb_matrix_increase_hue); +#endif return false; case RGB_SAI: +#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES) handleKeycodeRGB(shifted, rgblight_increase_sat, rgblight_decrease_sat); +#endif +#if defined(RGB_MATRIX_ENABLE) && !defined(RGB_MATRIX_DISABLE_KEYCODES) + handleKeycodeRGB(shifted, rgb_matrix_increase_sat, rgb_matrix_decrease_sat); +#endif return false; case RGB_SAD: +#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES) handleKeycodeRGB(shifted, rgblight_decrease_sat, rgblight_increase_sat); +#endif +#if defined(RGB_MATRIX_ENABLE) && !defined(RGB_MATRIX_DISABLE_KEYCODES) + handleKeycodeRGB(shifted, rgb_matrix_decrease_sat, rgb_matrix_increase_sat); +#endif return false; case RGB_VAI: +#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES) handleKeycodeRGB(shifted, rgblight_increase_val, rgblight_decrease_val); +#endif +#if defined(RGB_MATRIX_ENABLE) && !defined(RGB_MATRIX_DISABLE_KEYCODES) + handleKeycodeRGB(shifted, rgb_matrix_increase_val, rgb_matrix_decrease_val); +#endif return false; case RGB_VAD: +#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES) handleKeycodeRGB(shifted, rgblight_decrease_val, rgblight_increase_val); +#endif +#if defined(RGB_MATRIX_ENABLE) && !defined(RGB_MATRIX_DISABLE_KEYCODES) + handleKeycodeRGB(shifted, rgb_matrix_decrease_val, rgb_matrix_increase_val); +#endif return false; case RGB_SPI: +#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES) handleKeycodeRGB(shifted, rgblight_increase_speed, rgblight_decrease_speed); +#endif +#if defined(RGB_MATRIX_ENABLE) && !defined(RGB_MATRIX_DISABLE_KEYCODES) + handleKeycodeRGB(shifted, rgb_matrix_increase_speed, rgb_matrix_decrease_speed); +#endif return false; case RGB_SPD: +#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES) handleKeycodeRGB(shifted, rgblight_decrease_speed, rgblight_increase_speed); +#endif +#if defined(RGB_MATRIX_ENABLE) && !defined(RGB_MATRIX_DISABLE_KEYCODES) + handleKeycodeRGB(shifted, rgb_matrix_decrease_speed, rgb_matrix_increase_speed); +#endif return false; case RGB_MODE_PLAIN: +#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES) rgblight_mode(RGBLIGHT_MODE_STATIC_LIGHT); +#endif +#if defined(RGB_MATRIX_ENABLE) && !defined(RGB_MATRIX_DISABLE_KEYCODES) + rgb_matrix_mode(RGB_MATRIX_SOLID_COLOR); +#endif return false; case RGB_MODE_BREATHE: -#ifdef RGBLIGHT_EFFECT_BREATHING +#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES) && defined(RGBLIGHT_EFFECT_BREATHING) handleKeycodeRGBMode(RGBLIGHT_MODE_BREATHING, RGBLIGHT_MODE_BREATHING_end); +#endif +#if defined(RGB_MATRIX_ENABLE) && !defined(RGB_MATRIX_DISABLE_KEYCODES) && !defined(DISABLE_RGB_MATRIX_BREATHING) + rgb_matrix_mode(RGB_MATRIX_BREATHING); #endif return false; case RGB_MODE_RAINBOW: -#ifdef RGBLIGHT_EFFECT_RAINBOW_MOOD +#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES) && defined( RGBLIGHT_EFFECT_RAINBOW_MOOD) handleKeycodeRGBMode(RGBLIGHT_MODE_RAINBOW_MOOD, RGBLIGHT_MODE_RAINBOW_MOOD_end); +#endif +#if defined(RGB_MATRIX_ENABLE) && !defined(RGB_MATRIX_DISABLE_KEYCODES) && !defined(DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT) + rgb_matrix_mode(RGB_MATRIX_CYCLE_LEFT_RIGHT); #endif return false; case RGB_MODE_SWIRL: -#ifdef RGBLIGHT_EFFECT_RAINBOW_SWIRL +#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES) && defined( RGBLIGHT_EFFECT_RAINBOW_SWIRL) handleKeycodeRGBMode(RGBLIGHT_MODE_RAINBOW_SWIRL, RGBLIGHT_MODE_RAINBOW_SWIRL_end); +#endif +#if defined(RGB_MATRIX_ENABLE) && !defined(RGB_MATRIX_DISABLE_KEYCODES) && !defined(DISABLE_RGB_MATRIX_CYCLE_PINWHEEL) + rgb_matrix_mode(RGB_MATRIX_CYCLE_PINWHEEL); #endif return false; case RGB_MODE_SNAKE: -#ifdef RGBLIGHT_EFFECT_SNAKE +#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES) && defined( RGBLIGHT_EFFECT_SNAKE) handleKeycodeRGBMode(RGBLIGHT_MODE_SNAKE, RGBLIGHT_MODE_SNAKE_end); #endif return false; case RGB_MODE_KNIGHT: -#ifdef RGBLIGHT_EFFECT_KNIGHT +#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES) && defined( RGBLIGHT_EFFECT_KNIGHT) handleKeycodeRGBMode(RGBLIGHT_MODE_KNIGHT, RGBLIGHT_MODE_KNIGHT_end); #endif return false; case RGB_MODE_XMAS: -#ifdef RGBLIGHT_EFFECT_CHRISTMAS +#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES) && defined( RGBLIGHT_EFFECT_CHRISTMAS) rgblight_mode(RGBLIGHT_MODE_CHRISTMAS); #endif return false; case RGB_MODE_GRADIENT: -#ifdef RGBLIGHT_EFFECT_STATIC_GRADIENT +#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES) && defined( RGBLIGHT_EFFECT_STATIC_GRADIENT) handleKeycodeRGBMode(RGBLIGHT_MODE_STATIC_GRADIENT, RGBLIGHT_MODE_STATIC_GRADIENT_end); #endif return false; case RGB_MODE_RGBTEST: -#ifdef RGBLIGHT_EFFECT_RGB_TEST +#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES) && defined( RGBLIGHT_EFFECT_RGB_TEST) rgblight_mode(RGBLIGHT_MODE_RGB_TEST); #endif return false; -- cgit v1.2.3 From 666cb44673c3db85e0141189319fc9aed394c56d Mon Sep 17 00:00:00 2001 From: Dongfeng Yu <60870777+blockader@users.noreply.github.com> Date: Wed, 8 Jul 2020 04:59:13 +0800 Subject: Allowing Pressing the Start Buttons Again to Stop Dynamic Macro Recording (#9446) --- quantum/process_keycode/process_dynamic_macro.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_dynamic_macro.c b/quantum/process_keycode/process_dynamic_macro.c index 2065f242db..df3a8a8120 100644 --- a/quantum/process_keycode/process_dynamic_macro.c +++ b/quantum/process_keycode/process_dynamic_macro.c @@ -216,11 +216,13 @@ bool process_dynamic_macro(uint16_t keycode, keyrecord_t *record) { } else { /* A macro is being recorded right now. */ switch (keycode) { + case DYN_REC_START1: + case DYN_REC_START2: case DYN_REC_STOP: /* Stop the macro recording. */ - if (record->event.pressed) { /* Ignore the initial release - * just after the recoding - * starts. */ + if (record->event.pressed ^ (keycode != DYN_REC_STOP)) { /* Ignore the initial release + * just after the recording + * starts for DYN_REC_STOP. */ switch (macro_id) { case 1: dynamic_macro_record_end(macro_buffer, macro_pointer, +1, ¯o_end); -- cgit v1.2.3 From 9ae15e8c79375f2ca2f315d8b24e8c51a6855039 Mon Sep 17 00:00:00 2001 From: QMK Bot Date: Tue, 7 Jul 2020 21:43:51 +0000 Subject: format code according to conventions [skip ci] --- quantum/process_keycode/process_dynamic_macro.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_dynamic_macro.c b/quantum/process_keycode/process_dynamic_macro.c index df3a8a8120..18c8d7ca2e 100644 --- a/quantum/process_keycode/process_dynamic_macro.c +++ b/quantum/process_keycode/process_dynamic_macro.c @@ -221,8 +221,8 @@ bool process_dynamic_macro(uint16_t keycode, keyrecord_t *record) { case DYN_REC_STOP: /* Stop the macro recording. */ if (record->event.pressed ^ (keycode != DYN_REC_STOP)) { /* Ignore the initial release - * just after the recording - * starts for DYN_REC_STOP. */ + * just after the recording + * starts for DYN_REC_STOP. */ switch (macro_id) { case 1: dynamic_macro_record_end(macro_buffer, macro_pointer, +1, ¯o_end); -- cgit v1.2.3 From b0335b273142ead24cb4177893fafdf2fda88810 Mon Sep 17 00:00:00 2001 From: Pete Sevander Date: Thu, 16 Jul 2020 15:39:01 +0300 Subject: Bigger combo index (#9318) * Add change log * Change combo index from uint8_t to uint16_t --- quantum/process_keycode/process_combo.c | 6 +++--- quantum/process_keycode/process_combo.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_combo.c b/quantum/process_keycode/process_combo.c index c4e299958a..1f715f43b9 100644 --- a/quantum/process_keycode/process_combo.c +++ b/quantum/process_keycode/process_combo.c @@ -24,10 +24,10 @@ extern combo_t key_combos[]; extern int COMBO_LEN; #endif -__attribute__((weak)) void process_combo_event(uint8_t combo_index, bool pressed) {} +__attribute__((weak)) void process_combo_event(uint16_t combo_index, bool pressed) {} static uint16_t timer = 0; -static uint8_t current_combo_index = 0; +static uint16_t current_combo_index = 0; static bool drop_buffer = false; static bool is_active = false; static bool b_combo_enable = true; // defaults to enabled @@ -83,7 +83,7 @@ static inline void dump_key_buffer(bool emit) { static bool process_single_combo(combo_t *combo, uint16_t keycode, keyrecord_t *record) { uint8_t count = 0; - uint8_t index = -1; + uint16_t index = -1; /* Find index of keycode and number of combo keys */ for (const uint16_t *keys = combo->keys;; ++count) { uint16_t key = pgm_read_word(&keys[count]); diff --git a/quantum/process_keycode/process_combo.h b/quantum/process_keycode/process_combo.h index e21ee19609..0f01aae93e 100644 --- a/quantum/process_keycode/process_combo.h +++ b/quantum/process_keycode/process_combo.h @@ -56,7 +56,7 @@ typedef struct { bool process_combo(uint16_t keycode, keyrecord_t *record); void matrix_scan_combo(void); -void process_combo_event(uint8_t combo_index, bool pressed); +void process_combo_event(uint16_t combo_index, bool pressed); void combo_enable(void); void combo_disable(void); -- cgit v1.2.3 From 9d3b26a47543d9898a2af2cee5f6ef53b4995e9f Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Fri, 24 Jul 2020 20:05:27 -0700 Subject: Update features to use Custom Tapping Term when appropriate (#6259) * Update Space Cadet to use Custom Tapping Term functionality * Detect correct keycode for space cadet tapping term * Update tap dancing to use global custom tapping term * Update documentation for Tap Dances * formatting pass * Apply suggestions from code review Co-Authored-By: fauxpark * Update docs/feature_tap_dance.md Co-authored-by: James Young <18669334+noroadsleft@users.noreply.github.com> * Update for future * Update user keymaps for space cadet * Fix typos * Clean up tapping term stuff * Fix compiler issue if NO_ACTION_TAPPING is enabled Co-authored-by: fauxpark Co-authored-by: James Young <18669334+noroadsleft@users.noreply.github.com> --- quantum/process_keycode/process_space_cadet.c | 23 ++++++++++++----------- quantum/process_keycode/process_space_cadet.h | 5 ++++- quantum/process_keycode/process_tap_dance.c | 6 +----- 3 files changed, 17 insertions(+), 17 deletions(-) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_space_cadet.c b/quantum/process_keycode/process_space_cadet.c index 6833fdb9fb..bcaf62a964 100644 --- a/quantum/process_keycode/process_space_cadet.c +++ b/quantum/process_keycode/process_space_cadet.c @@ -14,9 +14,10 @@ * along with this program. If not, see . */ #include "process_space_cadet.h" +#include "action_tapping.h" -#ifndef TAPPING_TERM -# define TAPPING_TERM 200 +#ifdef NO_ACTION_TAPPING +__attribute__((weak)) uint16_t get_tapping_term(uint16_t keycode, keyrecord_t *record) { return TAPPING_TERM; }; #endif // ********** OBSOLETE DEFINES, STOP USING! (pls?) ********** @@ -85,7 +86,7 @@ static uint16_t sc_timer = 0; static uint8_t sc_mods = 0; #endif -void perform_space_cadet(keyrecord_t *record, uint8_t holdMod, uint8_t tapMod, uint8_t keycode) { +void perform_space_cadet(keyrecord_t *record, uint16_t sc_keycode, uint8_t holdMod, uint8_t tapMod, uint8_t keycode) { if (record->event.pressed) { sc_last = holdMod; sc_timer = timer_read(); @@ -96,7 +97,7 @@ void perform_space_cadet(keyrecord_t *record, uint8_t holdMod, uint8_t tapMod, u register_mods(MOD_BIT(holdMod)); } } else { - if (sc_last == holdMod && timer_elapsed(sc_timer) < TAPPING_TERM) { + if (sc_last == holdMod && timer_elapsed(sc_timer) < get_tapping_term(sc_keycode, record)) { if (holdMod != tapMod) { if (IS_MOD(holdMod)) { unregister_mods(MOD_BIT(holdMod)); @@ -126,31 +127,31 @@ void perform_space_cadet(keyrecord_t *record, uint8_t holdMod, uint8_t tapMod, u bool process_space_cadet(uint16_t keycode, keyrecord_t *record) { switch (keycode) { case KC_LSPO: { - perform_space_cadet(record, LSPO_KEYS); + perform_space_cadet(record, keycode, LSPO_KEYS); return false; } case KC_RSPC: { - perform_space_cadet(record, RSPC_KEYS); + perform_space_cadet(record, keycode, RSPC_KEYS); return false; } case KC_LCPO: { - perform_space_cadet(record, LCPO_KEYS); + perform_space_cadet(record, keycode, LCPO_KEYS); return false; } case KC_RCPC: { - perform_space_cadet(record, RCPC_KEYS); + perform_space_cadet(record, keycode, RCPC_KEYS); return false; } case KC_LAPO: { - perform_space_cadet(record, LAPO_KEYS); + perform_space_cadet(record, keycode, LAPO_KEYS); return false; } case KC_RAPC: { - perform_space_cadet(record, RAPC_KEYS); + perform_space_cadet(record, keycode, RAPC_KEYS); return false; } case KC_SFTENT: { - perform_space_cadet(record, SFTENT_KEYS); + perform_space_cadet(record, keycode, SFTENT_KEYS); return false; } default: { diff --git a/quantum/process_keycode/process_space_cadet.h b/quantum/process_keycode/process_space_cadet.h index c823143504..3ace073997 100644 --- a/quantum/process_keycode/process_space_cadet.h +++ b/quantum/process_keycode/process_space_cadet.h @@ -17,5 +17,8 @@ #include "quantum.h" -void perform_space_cadet(keyrecord_t *record, uint8_t holdMod, uint8_t tapMod, uint8_t keycode); +void perform_space_cadet(keyrecord_t *record, uint16_t sc_keycode, uint8_t holdMod, uint8_t tapMod, uint8_t keycode); bool process_space_cadet(uint16_t keycode, keyrecord_t *record); +#ifdef NO_ACTION_TAPPING +uint16_t get_tapping_term(uint16_t keycode, keyrecord_t *record); +#endif diff --git a/quantum/process_keycode/process_tap_dance.c b/quantum/process_keycode/process_tap_dance.c index 16756e59c2..0c7b6353eb 100644 --- a/quantum/process_keycode/process_tap_dance.c +++ b/quantum/process_keycode/process_tap_dance.c @@ -16,10 +16,6 @@ #include "quantum.h" #include "action_tapping.h" -#ifndef TAPPING_TERM -# define TAPPING_TERM 200 -#endif - #ifndef NO_ACTION_ONESHOT uint8_t get_oneshot_mods(void); #endif @@ -171,7 +167,7 @@ void matrix_scan_tap_dance() { if (action->custom_tapping_term > 0) { tap_user_defined = action->custom_tapping_term; } else { - tap_user_defined = TAPPING_TERM; + tap_user_defined = get_tapping_term(action->state.keycode, NULL); } if (action->state.count && timer_elapsed(action->state.timer) > tap_user_defined) { process_tap_dance_action_on_dance_finished(action); -- cgit v1.2.3 From d4be07dad368c57669c88ead6c093c9e23086855 Mon Sep 17 00:00:00 2001 From: a-chol Date: Sat, 25 Jul 2020 14:01:15 +0200 Subject: Hid joystick interface (#4226) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add support for hid gamepad interface add documentation for HID joystick Add joystick_task to read analog axes values even when no key is pressed or release. update doc Update docs/feature_joystick.md Manage pin setup and read to maintain matrix scan after analog read * Incorporates patches and changes to HID reporting There are some patches provided by @a-chol incorporated on this commit, and also some changes I made to the HID Report structure. The most interesting is the one dealing with number of buttons: Linux doesn't seem to care, but Windows requires the HID structure to be byte aligned (that's in the spec). So if one declares 8/16/32... buttons they should not have any issues, but this is what happens when you have 9 buttons: ``` bits |0|1|2|3|4|5|6|7| |*|*|*|*|*|*|*|*| axis 0 (report size 8) |*|*|*|*|*|*|*|*| ... |*|*|*|*|*|*|*|*| |*|*|*|*|*|*|*|*| |*|*|*|*|*|*|*|*| |*|*|*|*|*|*|*|*| |*|*|*|*|*|*|*|*| axis 6 |*|*|*|*|*|*|*|*| first 8 buttons (report size 1) |*| | | | | | | | last of 9 buttons, not aligned ``` So for that I added a conditonal that will add a number of reports with size 1 to make sure it aligns to the next multiple of 8. Those reports send dummy inputs that don't do anything aside from aligning the data. Tested on Linux, Windows 10 and Street Fighter (where the joystick is recognized as direct-input) * Add save and restore of each pin used in reading joystick (AVR). Allow output pin to be JS_VIRTUAL_AXIS if the axis is connected to Vcc instead of an output pin from the MCU. Fix joystick report id Fix broken v-usb hid joystick interface. Make it more resilient to unusual settings (none multiple of eight button count, 0 buttons or 0 axes) Correct adc reading for multiple axes. Piecewise range conversion for uncentered raw value range. Input, output and ground pin configuration per axis. Documentation fixes * Fix port addressing for joystick analog read * The other required set of changes As per the PR, the changes still holding it up. Add onekey for testing. Fix ARM builds. Fix device descriptor when either axes or buttons is zero. Add compile-time check for at least one axis or button. Move definition to try to fix conflict. PR review comments. qmk cformat * avoid float functions to compute range mapping for axis adc reading * Remove V-USB support for now. Updated docs accordingly. * Update tmk_core/protocol/lufa/lufa.c Co-Authored-By: Ryan * Update tmk_core/protocol/usb_descriptor.c Co-Authored-By: Ryan * Update tmk_core/protocol/usb_descriptor.c Co-Authored-By: Ryan * Update tmk_core/protocol/usb_descriptor.c Co-Authored-By: Ryan * Add support for joystick adc reading for stm32 MCUs. Fix joystick hid report sending for chibios * Fix HID joystick report sending for ChibiOS. Add one analog axis to the onekey:joystick keymap. Fix pin state save and restore during joystick analog read for STM32 MCUs. * Update tmk_core/protocol/chibios/usb_main.c Co-Authored-By: Ryan * Update tmk_core/protocol/lufa/lufa.c Co-Authored-By: Ryan * Add missing mcuconf.h and halconf.h to onekey:joystick keymap. Add suggested fixes from PR. * Switch saveState and restoreState signature to use pin_t type. onekey:joystick : add a second axis, virtual and programmatically animated. * Update docs/feature_joystick.md Co-Authored-By: Ryan * Update docs/feature_joystick.md Co-Authored-By: Ryan * Add PR corrections * Remove halconf.h and mcuconf.h from onekey keymaps * Change ADC_PIN to A0 Co-authored-by: achol Co-authored-by: José Júnior Co-authored-by: a-chol Co-authored-by: Nick Brassel Co-authored-by: Ryan --- quantum/process_keycode/process_joystick.c | 168 +++++++++++++++++++++++++++++ quantum/process_keycode/process_joystick.h | 11 ++ 2 files changed, 179 insertions(+) create mode 100644 quantum/process_keycode/process_joystick.c create mode 100644 quantum/process_keycode/process_joystick.h (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_joystick.c b/quantum/process_keycode/process_joystick.c new file mode 100644 index 0000000000..c12f756854 --- /dev/null +++ b/quantum/process_keycode/process_joystick.c @@ -0,0 +1,168 @@ +#include "joystick.h" +#include "process_joystick.h" + +#include "analog.h" + +#include +#include + +bool process_joystick_buttons(uint16_t keycode, keyrecord_t *record); + +bool process_joystick(uint16_t keycode, keyrecord_t *record) { + if (process_joystick_buttons(keycode, record) && (joystick_status.status & JS_UPDATED) > 0) { + send_joystick_packet(&joystick_status); + joystick_status.status &= ~JS_UPDATED; + } + + return true; +} + +__attribute__((weak)) +void joystick_task(void) { + if (process_joystick_analogread() && (joystick_status.status & JS_UPDATED)) { + send_joystick_packet(&joystick_status); + joystick_status.status &= ~JS_UPDATED; + } +} + +bool process_joystick_buttons(uint16_t keycode, keyrecord_t *record) { + if (keycode < JS_BUTTON0 || keycode > JS_BUTTON_MAX) { + return true; + } else { + if (record->event.pressed) { + joystick_status.buttons[(keycode - JS_BUTTON0) / 8] |= 1 << (keycode % 8); + } else { + joystick_status.buttons[(keycode - JS_BUTTON0) / 8] &= ~(1 << (keycode % 8)); + } + + joystick_status.status |= JS_UPDATED; + } + + return true; +} + +uint16_t savePinState(pin_t pin) { +#ifdef __AVR__ + uint8_t pinNumber = pin & 0xF; + return ((PORTx_ADDRESS(pin) >> pinNumber) & 0x1) << 1 | ((DDRx_ADDRESS(pin) >> pinNumber) & 0x1); +#elif defined(PROTOCOL_CHIBIOS) + /* + The pin configuration is backed up in the following format : + bit 15 9 8 7 6 5 4 3 2 1 0 + |unused|ODR|IDR|PUPDR|OSPEEDR|OTYPER|MODER| + */ + return (( PAL_PORT(pin)->MODER >> (2*PAL_PAD(pin))) & 0x3) + | (((PAL_PORT(pin)->OTYPER >> (1*PAL_PAD(pin))) & 0x1) << 2) + | (((PAL_PORT(pin)->OSPEEDR >> (2*PAL_PAD(pin))) & 0x3) << 3) + | (((PAL_PORT(pin)->PUPDR >> (2*PAL_PAD(pin))) & 0x3) << 5) + | (((PAL_PORT(pin)->IDR >> (1*PAL_PAD(pin))) & 0x1) << 7) + | (((PAL_PORT(pin)->ODR >> (1*PAL_PAD(pin))) & 0x1) << 8); +#else + return 0; +#endif +} + +void restorePinState(pin_t pin, uint16_t restoreState) { +#if defined(PROTOCOL_LUFA) + uint8_t pinNumber = pin & 0xF; + PORTx_ADDRESS(pin) = (PORTx_ADDRESS(pin) & ~_BV(pinNumber)) | (((restoreState >> 1) & 0x1) << pinNumber); + DDRx_ADDRESS(pin) = (DDRx_ADDRESS(pin) & ~_BV(pinNumber)) | ((restoreState & 0x1) << pinNumber); +#elif defined(PROTOCOL_CHIBIOS) + PAL_PORT(pin)->MODER = (PAL_PORT(pin)->MODER & ~(0x3<< (2*PAL_PAD(pin)))) | (restoreState & 0x3) << (2*PAL_PAD(pin)); + PAL_PORT(pin)->OTYPER = (PAL_PORT(pin)->OTYPER & ~(0x1<< (1*PAL_PAD(pin)))) | ((restoreState>>2) & 0x1) << (1*PAL_PAD(pin)); + PAL_PORT(pin)->OSPEEDR= (PAL_PORT(pin)->OSPEEDR & ~(0x3<< (2*PAL_PAD(pin)))) | ((restoreState>>3) & 0x3) << (2*PAL_PAD(pin)); + PAL_PORT(pin)->PUPDR = (PAL_PORT(pin)->PUPDR & ~(0x3<< (2*PAL_PAD(pin)))) | ((restoreState>>5) & 0x3) << (2*PAL_PAD(pin)); + PAL_PORT(pin)->IDR = (PAL_PORT(pin)->IDR & ~(0x1<< (1*PAL_PAD(pin)))) | ((restoreState>>7) & 0x1) << (1*PAL_PAD(pin)); + PAL_PORT(pin)->ODR = (PAL_PORT(pin)->ODR & ~(0x1<< (1*PAL_PAD(pin)))) | ((restoreState>>8) & 0x1) << (1*PAL_PAD(pin)); +#else + return; +#endif +} + +__attribute__((weak)) bool process_joystick_analogread() { return process_joystick_analogread_quantum(); } + +bool process_joystick_analogread_quantum() { +#if JOYSTICK_AXES_COUNT > 0 + for (int axis_index = 0; axis_index < JOYSTICK_AXES_COUNT; ++axis_index) { + if (joystick_axes[axis_index].input_pin == JS_VIRTUAL_AXIS) { + continue; + } + + // save previous input pin status as well + uint16_t inputSavedState = savePinState(joystick_axes[axis_index].input_pin); + + // disable pull-up resistor + writePinLow(joystick_axes[axis_index].input_pin); + + // if pin was a pull-up input, we need to uncharge it by turning it low + // before making it a low input + setPinOutput(joystick_axes[axis_index].input_pin); + + wait_us(10); + + // save and apply output pin status + uint16_t outputSavedState = 0; + if (joystick_axes[axis_index].output_pin != JS_VIRTUAL_AXIS) { + // save previous output pin status + outputSavedState = savePinState(joystick_axes[axis_index].output_pin); + + setPinOutput(joystick_axes[axis_index].output_pin); + writePinHigh(joystick_axes[axis_index].output_pin); + } + + uint16_t groundSavedState = 0; + if (joystick_axes[axis_index].ground_pin != JS_VIRTUAL_AXIS) { + // save previous output pin status + groundSavedState = savePinState(joystick_axes[axis_index].ground_pin); + + setPinOutput(joystick_axes[axis_index].ground_pin); + writePinLow(joystick_axes[axis_index].ground_pin); + } + + wait_us(10); + + setPinInput(joystick_axes[axis_index].input_pin); + + wait_us(10); + +# if defined(__AVR__) || defined(PROTOCOL_CHIBIOS) + int16_t axis_val = analogReadPin(joystick_axes[axis_index].input_pin); +# else + // default to resting position + int16_t axis_val = joystick_axes[axis_index].mid_digit; +# endif + + //test the converted value against the lower range + int32_t ref = joystick_axes[axis_index].mid_digit; + int32_t range = joystick_axes[axis_index].min_digit; + int32_t ranged_val = ((axis_val - ref) * -127) / (range - ref) ; + + if (ranged_val > 0) { + //the value is in the higher range + range = joystick_axes[axis_index].max_digit; + ranged_val = ((axis_val - ref) * 127) / (range - ref); + } + + //clamp the result in the valid range + ranged_val = ranged_val < -127 ? -127 : ranged_val; + ranged_val = ranged_val > 127 ? 127 : ranged_val; + + if (ranged_val != joystick_status.axes[axis_index]) { + joystick_status.axes[axis_index] = ranged_val; + joystick_status.status |= JS_UPDATED; + } + + // restore output, ground and input status + if (joystick_axes[axis_index].output_pin != JS_VIRTUAL_AXIS) { + restorePinState(joystick_axes[axis_index].output_pin, outputSavedState); + } + if (joystick_axes[axis_index].ground_pin != JS_VIRTUAL_AXIS) { + restorePinState(joystick_axes[axis_index].ground_pin, groundSavedState); + } + + restorePinState(joystick_axes[axis_index].input_pin, inputSavedState); + } + +#endif + return true; +} diff --git a/quantum/process_keycode/process_joystick.h b/quantum/process_keycode/process_joystick.h new file mode 100644 index 0000000000..7a8b82913a --- /dev/null +++ b/quantum/process_keycode/process_joystick.h @@ -0,0 +1,11 @@ +#pragma once + +#include +#include "quantum.h" + +bool process_joystick(uint16_t keycode, keyrecord_t *record); + +void joystick_task(void); + +bool process_joystick_analogread(void); +bool process_joystick_analogread_quantum(void); -- cgit v1.2.3 From 568cae28ec41acc84a4a60bc3e20120e33ebee89 Mon Sep 17 00:00:00 2001 From: Greg Wright Date: Sat, 15 Aug 2020 16:55:13 -0400 Subject: #define AUTO_SHIFT_SETUP (#8441) * #define AUTO_SHIFT_SETUP * Clarification Changed `#ifndef` to `#ifdef` and moved enable disable outside AUTO_SHIFT_SETUP * AUTO_SHIFT_NO_SETUp --- quantum/process_keycode/process_auto_shift.c | 70 +++++++++++++++------------- 1 file changed, 37 insertions(+), 33 deletions(-) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_auto_shift.c b/quantum/process_keycode/process_auto_shift.c index b474bda691..330037cefb 100644 --- a/quantum/process_keycode/process_auto_shift.c +++ b/quantum/process_keycode/process_auto_shift.c @@ -25,19 +25,6 @@ static uint16_t autoshift_time = 0; static uint16_t autoshift_timeout = AUTO_SHIFT_TIMEOUT; static uint16_t autoshift_lastkey = KC_NO; -void autoshift_timer_report(void) { - char display[8]; - - snprintf(display, 8, "\n%d\n", autoshift_timeout); - - send_string((const char *)display); -} - -void autoshift_on(uint16_t keycode) { - autoshift_time = timer_read(); - autoshift_lastkey = keycode; -} - void autoshift_flush(void) { if (autoshift_lastkey != KC_NO) { uint16_t elapsed = timer_elapsed(autoshift_time); @@ -53,21 +40,36 @@ void autoshift_flush(void) { } } -void autoshift_enable(void) { autoshift_enabled = true; } -void autoshift_disable(void) { +void autoshift_on(uint16_t keycode) { + autoshift_time = timer_read(); + autoshift_lastkey = keycode; +} + +void autoshift_toggle(void) { + if (autoshift_enabled) { autoshift_enabled = false; autoshift_flush(); + } else { + autoshift_enabled = true; + } } -void autoshift_toggle(void) { - if (autoshift_enabled) { - autoshift_enabled = false; - autoshift_flush(); - } else { - autoshift_enabled = true; - } +void autoshift_enable(void) { autoshift_enabled = true; } +void autoshift_disable(void) { + autoshift_enabled = false; + autoshift_flush(); } +#ifndef AUTO_SHIFT_NO_SETUP +void autoshift_timer_report(void) { + char display[8]; + + snprintf(display, 8, "\n%d\n", autoshift_timeout); + + send_string((const char *)display); +} +#endif + bool get_autoshift_state(void) { return autoshift_enabled; } uint16_t get_autoshift_timeout(void) { return autoshift_timeout; } @@ -77,21 +79,11 @@ void set_autoshift_timeout(uint16_t timeout) { autoshift_timeout = timeout; } bool process_auto_shift(uint16_t keycode, keyrecord_t *record) { if (record->event.pressed) { switch (keycode) { - case KC_ASUP: - autoshift_timeout += 5; - return true; - - case KC_ASDN: - autoshift_timeout -= 5; - return true; - - case KC_ASRP: - autoshift_timer_report(); - return true; case KC_ASTG: autoshift_toggle(); return true; + case KC_ASON: autoshift_enable(); return true; @@ -99,6 +91,18 @@ bool process_auto_shift(uint16_t keycode, keyrecord_t *record) { autoshift_disable(); return true; +# ifndef AUTO_SHIFT_NO_SETUP + case KC_ASUP: + autoshift_timeout += 5; + return true; + case KC_ASDN: + autoshift_timeout -= 5; + return true; + + case KC_ASRP: + autoshift_timer_report(); + return true; +# endif # ifndef NO_AUTO_SHIFT_ALPHA case KC_A ... KC_Z: # endif -- cgit v1.2.3 From a3db72df7299140e52f57d082a3742a8b480a226 Mon Sep 17 00:00:00 2001 From: QMK Bot Date: Sat, 29 Aug 2020 22:57:48 +0000 Subject: format code according to conventions [skip ci] --- quantum/process_keycode/process_auto_shift.c | 35 +++++++++++------------ quantum/process_keycode/process_combo.c | 4 +-- quantum/process_keycode/process_joystick.c | 42 ++++++++++++---------------- 3 files changed, 37 insertions(+), 44 deletions(-) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_auto_shift.c b/quantum/process_keycode/process_auto_shift.c index 330037cefb..b1267922ce 100644 --- a/quantum/process_keycode/process_auto_shift.c +++ b/quantum/process_keycode/process_auto_shift.c @@ -41,34 +41,34 @@ void autoshift_flush(void) { } void autoshift_on(uint16_t keycode) { - autoshift_time = timer_read(); - autoshift_lastkey = keycode; + autoshift_time = timer_read(); + autoshift_lastkey = keycode; } void autoshift_toggle(void) { - if (autoshift_enabled) { - autoshift_enabled = false; - autoshift_flush(); - } else { - autoshift_enabled = true; - } + if (autoshift_enabled) { + autoshift_enabled = false; + autoshift_flush(); + } else { + autoshift_enabled = true; + } } void autoshift_enable(void) { autoshift_enabled = true; } void autoshift_disable(void) { - autoshift_enabled = false; - autoshift_flush(); + autoshift_enabled = false; + autoshift_flush(); } -#ifndef AUTO_SHIFT_NO_SETUP +# ifndef AUTO_SHIFT_NO_SETUP void autoshift_timer_report(void) { - char display[8]; + char display[8]; - snprintf(display, 8, "\n%d\n", autoshift_timeout); + snprintf(display, 8, "\n%d\n", autoshift_timeout); - send_string((const char *)display); + send_string((const char *)display); } -#endif +# endif bool get_autoshift_state(void) { return autoshift_enabled; } @@ -79,7 +79,6 @@ void set_autoshift_timeout(uint16_t timeout) { autoshift_timeout = timeout; } bool process_auto_shift(uint16_t keycode, keyrecord_t *record) { if (record->event.pressed) { switch (keycode) { - case KC_ASTG: autoshift_toggle(); return true; @@ -92,10 +91,10 @@ bool process_auto_shift(uint16_t keycode, keyrecord_t *record) { return true; # ifndef AUTO_SHIFT_NO_SETUP - case KC_ASUP: + case KC_ASUP: autoshift_timeout += 5; return true; - case KC_ASDN: + case KC_ASDN: autoshift_timeout -= 5; return true; diff --git a/quantum/process_keycode/process_combo.c b/quantum/process_keycode/process_combo.c index 1f715f43b9..f38d7d47a0 100644 --- a/quantum/process_keycode/process_combo.c +++ b/quantum/process_keycode/process_combo.c @@ -27,7 +27,7 @@ extern int COMBO_LEN; __attribute__((weak)) void process_combo_event(uint16_t combo_index, bool pressed) {} static uint16_t timer = 0; -static uint16_t current_combo_index = 0; +static uint16_t current_combo_index = 0; static bool drop_buffer = false; static bool is_active = false; static bool b_combo_enable = true; // defaults to enabled @@ -82,7 +82,7 @@ static inline void dump_key_buffer(bool emit) { } while (0) static bool process_single_combo(combo_t *combo, uint16_t keycode, keyrecord_t *record) { - uint8_t count = 0; + uint8_t count = 0; uint16_t index = -1; /* Find index of keycode and number of combo keys */ for (const uint16_t *keys = combo->keys;; ++count) { diff --git a/quantum/process_keycode/process_joystick.c b/quantum/process_keycode/process_joystick.c index c12f756854..5778a7434c 100644 --- a/quantum/process_keycode/process_joystick.c +++ b/quantum/process_keycode/process_joystick.c @@ -17,8 +17,7 @@ bool process_joystick(uint16_t keycode, keyrecord_t *record) { return true; } -__attribute__((weak)) -void joystick_task(void) { +__attribute__((weak)) void joystick_task(void) { if (process_joystick_analogread() && (joystick_status.status & JS_UPDATED)) { send_joystick_packet(&joystick_status); joystick_status.status &= ~JS_UPDATED; @@ -47,16 +46,11 @@ uint16_t savePinState(pin_t pin) { return ((PORTx_ADDRESS(pin) >> pinNumber) & 0x1) << 1 | ((DDRx_ADDRESS(pin) >> pinNumber) & 0x1); #elif defined(PROTOCOL_CHIBIOS) /* - The pin configuration is backed up in the following format : + The pin configuration is backed up in the following format : bit 15 9 8 7 6 5 4 3 2 1 0 |unused|ODR|IDR|PUPDR|OSPEEDR|OTYPER|MODER| */ - return (( PAL_PORT(pin)->MODER >> (2*PAL_PAD(pin))) & 0x3) - | (((PAL_PORT(pin)->OTYPER >> (1*PAL_PAD(pin))) & 0x1) << 2) - | (((PAL_PORT(pin)->OSPEEDR >> (2*PAL_PAD(pin))) & 0x3) << 3) - | (((PAL_PORT(pin)->PUPDR >> (2*PAL_PAD(pin))) & 0x3) << 5) - | (((PAL_PORT(pin)->IDR >> (1*PAL_PAD(pin))) & 0x1) << 7) - | (((PAL_PORT(pin)->ODR >> (1*PAL_PAD(pin))) & 0x1) << 8); + return ((PAL_PORT(pin)->MODER >> (2 * PAL_PAD(pin))) & 0x3) | (((PAL_PORT(pin)->OTYPER >> (1 * PAL_PAD(pin))) & 0x1) << 2) | (((PAL_PORT(pin)->OSPEEDR >> (2 * PAL_PAD(pin))) & 0x3) << 3) | (((PAL_PORT(pin)->PUPDR >> (2 * PAL_PAD(pin))) & 0x3) << 5) | (((PAL_PORT(pin)->IDR >> (1 * PAL_PAD(pin))) & 0x1) << 7) | (((PAL_PORT(pin)->ODR >> (1 * PAL_PAD(pin))) & 0x1) << 8); #else return 0; #endif @@ -68,12 +62,12 @@ void restorePinState(pin_t pin, uint16_t restoreState) { PORTx_ADDRESS(pin) = (PORTx_ADDRESS(pin) & ~_BV(pinNumber)) | (((restoreState >> 1) & 0x1) << pinNumber); DDRx_ADDRESS(pin) = (DDRx_ADDRESS(pin) & ~_BV(pinNumber)) | ((restoreState & 0x1) << pinNumber); #elif defined(PROTOCOL_CHIBIOS) - PAL_PORT(pin)->MODER = (PAL_PORT(pin)->MODER & ~(0x3<< (2*PAL_PAD(pin)))) | (restoreState & 0x3) << (2*PAL_PAD(pin)); - PAL_PORT(pin)->OTYPER = (PAL_PORT(pin)->OTYPER & ~(0x1<< (1*PAL_PAD(pin)))) | ((restoreState>>2) & 0x1) << (1*PAL_PAD(pin)); - PAL_PORT(pin)->OSPEEDR= (PAL_PORT(pin)->OSPEEDR & ~(0x3<< (2*PAL_PAD(pin)))) | ((restoreState>>3) & 0x3) << (2*PAL_PAD(pin)); - PAL_PORT(pin)->PUPDR = (PAL_PORT(pin)->PUPDR & ~(0x3<< (2*PAL_PAD(pin)))) | ((restoreState>>5) & 0x3) << (2*PAL_PAD(pin)); - PAL_PORT(pin)->IDR = (PAL_PORT(pin)->IDR & ~(0x1<< (1*PAL_PAD(pin)))) | ((restoreState>>7) & 0x1) << (1*PAL_PAD(pin)); - PAL_PORT(pin)->ODR = (PAL_PORT(pin)->ODR & ~(0x1<< (1*PAL_PAD(pin)))) | ((restoreState>>8) & 0x1) << (1*PAL_PAD(pin)); + PAL_PORT(pin)->MODER = (PAL_PORT(pin)->MODER & ~(0x3 << (2 * PAL_PAD(pin)))) | (restoreState & 0x3) << (2 * PAL_PAD(pin)); + PAL_PORT(pin)->OTYPER = (PAL_PORT(pin)->OTYPER & ~(0x1 << (1 * PAL_PAD(pin)))) | ((restoreState >> 2) & 0x1) << (1 * PAL_PAD(pin)); + PAL_PORT(pin)->OSPEEDR = (PAL_PORT(pin)->OSPEEDR & ~(0x3 << (2 * PAL_PAD(pin)))) | ((restoreState >> 3) & 0x3) << (2 * PAL_PAD(pin)); + PAL_PORT(pin)->PUPDR = (PAL_PORT(pin)->PUPDR & ~(0x3 << (2 * PAL_PAD(pin)))) | ((restoreState >> 5) & 0x3) << (2 * PAL_PAD(pin)); + PAL_PORT(pin)->IDR = (PAL_PORT(pin)->IDR & ~(0x1 << (1 * PAL_PAD(pin)))) | ((restoreState >> 7) & 0x1) << (1 * PAL_PAD(pin)); + PAL_PORT(pin)->ODR = (PAL_PORT(pin)->ODR & ~(0x1 << (1 * PAL_PAD(pin)))) | ((restoreState >> 8) & 0x1) << (1 * PAL_PAD(pin)); #else return; #endif @@ -132,21 +126,21 @@ bool process_joystick_analogread_quantum() { int16_t axis_val = joystick_axes[axis_index].mid_digit; # endif - //test the converted value against the lower range - int32_t ref = joystick_axes[axis_index].mid_digit; - int32_t range = joystick_axes[axis_index].min_digit; - int32_t ranged_val = ((axis_val - ref) * -127) / (range - ref) ; + // test the converted value against the lower range + int32_t ref = joystick_axes[axis_index].mid_digit; + int32_t range = joystick_axes[axis_index].min_digit; + int32_t ranged_val = ((axis_val - ref) * -127) / (range - ref); if (ranged_val > 0) { - //the value is in the higher range - range = joystick_axes[axis_index].max_digit; + // the value is in the higher range + range = joystick_axes[axis_index].max_digit; ranged_val = ((axis_val - ref) * 127) / (range - ref); } - - //clamp the result in the valid range + + // clamp the result in the valid range ranged_val = ranged_val < -127 ? -127 : ranged_val; ranged_val = ranged_val > 127 ? 127 : ranged_val; - + if (ranged_val != joystick_status.axes[axis_index]) { joystick_status.axes[axis_index] = ranged_val; joystick_status.status |= JS_UPDATED; -- cgit v1.2.3 From ef7c79b781318faaef4e6fe318fffade1b1ed299 Mon Sep 17 00:00:00 2001 From: cmdremily <68452184+cmdremily@users.noreply.github.com> Date: Sat, 12 Sep 2020 22:32:46 +0200 Subject: Fix issues with unused variables and functions preventing a clean compile. --- quantum/process_keycode/process_rgb.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_rgb.c b/quantum/process_keycode/process_rgb.c index a1e46e0348..d38af74f41 100644 --- a/quantum/process_keycode/process_rgb.c +++ b/quantum/process_keycode/process_rgb.c @@ -23,6 +23,7 @@ typedef void (*rgb_func_pointer)(void); * * noinline to optimise for firmware size not speed (not in hot path) */ +#if !(defined(RGBLIGHT_DISABLE_KEYCODES) || defined(RGB_MATRIX_DISABLE_KEYCODES)) static void __attribute__((noinline)) handleKeycodeRGB(const uint8_t is_shifted, const rgb_func_pointer inc_func, const rgb_func_pointer dec_func) { if (is_shifted) { dec_func(); @@ -30,6 +31,7 @@ static void __attribute__((noinline)) handleKeycodeRGB(const uint8_t is_shifted, inc_func(); } } +#endif /** * Wrapper for animation mode @@ -56,7 +58,9 @@ bool process_rgb(const uint16_t keycode, const keyrecord_t *record) { // Split keyboards need to trigger on key-up for edge-case issue if (!record->event.pressed) { #endif +#if !(defined(RGBLIGHT_DISABLE_KEYCODES) || defined(RGB_MATRIX_DISABLE_KEYCODES)) uint8_t shifted = get_mods() & MOD_MASK_SHIFT; +#endif switch (keycode) { case RGB_TOG: #if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES) -- cgit v1.2.3 From c8cff1489a82bb61266ce32750895c6935b256a3 Mon Sep 17 00:00:00 2001 From: QMK Bot Date: Sun, 4 Oct 2020 20:54:31 +0000 Subject: format code according to conventions [skip ci] --- quantum/process_keycode/process_rgb.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_rgb.c b/quantum/process_keycode/process_rgb.c index d38af74f41..e0c62465f9 100644 --- a/quantum/process_keycode/process_rgb.c +++ b/quantum/process_keycode/process_rgb.c @@ -167,7 +167,7 @@ bool process_rgb(const uint16_t keycode, const keyrecord_t *record) { #endif return false; case RGB_MODE_RAINBOW: -#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES) && defined( RGBLIGHT_EFFECT_RAINBOW_MOOD) +#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES) && defined(RGBLIGHT_EFFECT_RAINBOW_MOOD) handleKeycodeRGBMode(RGBLIGHT_MODE_RAINBOW_MOOD, RGBLIGHT_MODE_RAINBOW_MOOD_end); #endif #if defined(RGB_MATRIX_ENABLE) && !defined(RGB_MATRIX_DISABLE_KEYCODES) && !defined(DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT) @@ -175,7 +175,7 @@ bool process_rgb(const uint16_t keycode, const keyrecord_t *record) { #endif return false; case RGB_MODE_SWIRL: -#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES) && defined( RGBLIGHT_EFFECT_RAINBOW_SWIRL) +#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES) && defined(RGBLIGHT_EFFECT_RAINBOW_SWIRL) handleKeycodeRGBMode(RGBLIGHT_MODE_RAINBOW_SWIRL, RGBLIGHT_MODE_RAINBOW_SWIRL_end); #endif #if defined(RGB_MATRIX_ENABLE) && !defined(RGB_MATRIX_DISABLE_KEYCODES) && !defined(DISABLE_RGB_MATRIX_CYCLE_PINWHEEL) @@ -183,27 +183,27 @@ bool process_rgb(const uint16_t keycode, const keyrecord_t *record) { #endif return false; case RGB_MODE_SNAKE: -#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES) && defined( RGBLIGHT_EFFECT_SNAKE) +#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES) && defined(RGBLIGHT_EFFECT_SNAKE) handleKeycodeRGBMode(RGBLIGHT_MODE_SNAKE, RGBLIGHT_MODE_SNAKE_end); #endif return false; case RGB_MODE_KNIGHT: -#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES) && defined( RGBLIGHT_EFFECT_KNIGHT) +#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES) && defined(RGBLIGHT_EFFECT_KNIGHT) handleKeycodeRGBMode(RGBLIGHT_MODE_KNIGHT, RGBLIGHT_MODE_KNIGHT_end); #endif return false; case RGB_MODE_XMAS: -#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES) && defined( RGBLIGHT_EFFECT_CHRISTMAS) +#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES) && defined(RGBLIGHT_EFFECT_CHRISTMAS) rgblight_mode(RGBLIGHT_MODE_CHRISTMAS); #endif return false; case RGB_MODE_GRADIENT: -#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES) && defined( RGBLIGHT_EFFECT_STATIC_GRADIENT) +#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES) && defined(RGBLIGHT_EFFECT_STATIC_GRADIENT) handleKeycodeRGBMode(RGBLIGHT_MODE_STATIC_GRADIENT, RGBLIGHT_MODE_STATIC_GRADIENT_end); #endif return false; case RGB_MODE_RGBTEST: -#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES) && defined( RGBLIGHT_EFFECT_RGB_TEST) +#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES) && defined(RGBLIGHT_EFFECT_RGB_TEST) rgblight_mode(RGBLIGHT_MODE_RGB_TEST); #endif return false; -- cgit v1.2.3 From 2bcac45650563822f20a2336a9fc4d95b2cc4e3e Mon Sep 17 00:00:00 2001 From: 3araht <69518343+3araht@users.noreply.github.com> Date: Mon, 5 Oct 2020 06:32:24 +0900 Subject: Fix for MIDI sustain effect issue (#10361) --- quantum/process_keycode/process_midi.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_midi.c b/quantum/process_keycode/process_midi.c index b2fb902eb4..e525770144 100644 --- a/quantum/process_keycode/process_midi.c +++ b/quantum/process_keycode/process_midi.c @@ -68,10 +68,12 @@ bool process_midi(uint16_t keycode, keyrecord_t *record) { uint8_t tone = keycode - MIDI_TONE_MIN; uint8_t velocity = compute_velocity(midi_config.velocity); if (record->event.pressed) { - uint8_t note = midi_compute_note(keycode); - midi_send_noteon(&midi_device, channel, note, velocity); - dprintf("midi noteon channel:%d note:%d velocity:%d\n", channel, note, velocity); - tone_status[tone] = note; + if (tone_status[tone] == MIDI_INVALID_NOTE) { + uint8_t note = midi_compute_note(keycode); + midi_send_noteon(&midi_device, channel, note, velocity); + dprintf("midi noteon channel:%d note:%d velocity:%d\n", channel, note, velocity); + tone_status[tone] = note; + } } else { uint8_t note = tone_status[tone]; if (note != MIDI_INVALID_NOTE) { -- cgit v1.2.3 From bc79e5199071472f3d728826f381abf8cca59456 Mon Sep 17 00:00:00 2001 From: a_p_u_r_o Date: Wed, 7 Oct 2020 11:30:43 +0900 Subject: Fix issue introduced by PR#10404 (#10559) --- quantum/process_keycode/process_rgb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_rgb.c b/quantum/process_keycode/process_rgb.c index e0c62465f9..5dd8e7809d 100644 --- a/quantum/process_keycode/process_rgb.c +++ b/quantum/process_keycode/process_rgb.c @@ -23,7 +23,7 @@ typedef void (*rgb_func_pointer)(void); * * noinline to optimise for firmware size not speed (not in hot path) */ -#if !(defined(RGBLIGHT_DISABLE_KEYCODES) || defined(RGB_MATRIX_DISABLE_KEYCODES)) +#if (defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES)) || (defined(RGB_MATRIX_ENABLE) && !defined(RGB_MATRIX_DISABLE_KEYCODES)) static void __attribute__((noinline)) handleKeycodeRGB(const uint8_t is_shifted, const rgb_func_pointer inc_func, const rgb_func_pointer dec_func) { if (is_shifted) { dec_func(); @@ -58,7 +58,7 @@ bool process_rgb(const uint16_t keycode, const keyrecord_t *record) { // Split keyboards need to trigger on key-up for edge-case issue if (!record->event.pressed) { #endif -#if !(defined(RGBLIGHT_DISABLE_KEYCODES) || defined(RGB_MATRIX_DISABLE_KEYCODES)) +#if (defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES)) || (defined(RGB_MATRIX_ENABLE) && !defined(RGB_MATRIX_DISABLE_KEYCODES)) uint8_t shifted = get_mods() & MOD_MASK_SHIFT; #endif switch (keycode) { -- cgit v1.2.3 From 2c92ee1f56b92b15403b2f070c827162db37c9ba Mon Sep 17 00:00:00 2001 From: Ryan Date: Tue, 27 Oct 2020 06:14:56 +1100 Subject: Allow modified keycodes in Unicode input (#10658) --- quantum/process_keycode/process_unicode_common.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_unicode_common.c b/quantum/process_keycode/process_unicode_common.c index 84c44d9874..80be316232 100644 --- a/quantum/process_keycode/process_unicode_common.c +++ b/quantum/process_keycode/process_unicode_common.c @@ -136,20 +136,10 @@ __attribute__((weak)) void unicode_input_cancel(void) { set_mods(unicode_saved_mods); // Reregister previously set mods } -__attribute__((weak)) uint16_t hex_to_keycode(uint8_t hex) { - if (hex == 0x0) { - return KC_0; - } else if (hex < 0xA) { - return KC_1 + (hex - 0x1); - } else { - return KC_A + (hex - 0xA); - } -} - void register_hex(uint16_t hex) { for (int i = 3; i >= 0; i--) { uint8_t digit = ((hex >> (i * 4)) & 0xF); - tap_code(hex_to_keycode(digit)); + tap_code16(hex_to_keycode(digit)); } } @@ -162,10 +152,10 @@ void register_hex32(uint32_t hex) { uint8_t digit = ((hex >> (i * 4)) & 0xF); if (digit == 0) { if (!onzerostart) { - tap_code(hex_to_keycode(digit)); + tap_code16(hex_to_keycode(digit)); } } else { - tap_code(hex_to_keycode(digit)); + tap_code16(hex_to_keycode(digit)); onzerostart = false; } } -- cgit v1.2.3 From c66df1664497546f32662409778731143e45a552 Mon Sep 17 00:00:00 2001 From: James Young <18669334+noroadsleft@users.noreply.github.com> Date: Sat, 28 Nov 2020 12:02:18 -0800 Subject: 2020 November 28 Breaking Changes Update (#11053) * Branch point for 2020 November 28 Breaking Change * Remove matrix_col_t to allow MATRIX_ROWS > 32 (#10183) * Add support for soft serial to ATmega32U2 (#10204) * Change MIDI velocity implementation to allow direct control of velocity value (#9940) * Add ability to build a subset of all keyboards based on platform. * Actually use eeprom_driver_init(). * Make bootloader_jump weak for ChibiOS. (#10417) * Joystick 16-bit support (#10439) * Per-encoder resolutions (#10259) * Share button state from mousekey to pointing_device (#10179) * Add hotfix for chibios keyboards not wake (#10088) * Add advanced/efficient RGB Matrix Indicators (#8564) * Naming change. * Support for STM32 GPIOF,G,H,I,J,K (#10206) * Add milc as a dependency and remove the installed milc (#10563) * ChibiOS upgrade: early init conversions (#10214) * ChibiOS upgrade: configuration file migrator (#9952) * Haptic and solenoid cleanup (#9700) * XD75 cleanup (#10524) * OLED display update interval support (#10388) * Add definition based on currently-selected serial driver. (#10716) * New feature: Retro Tapping per key (#10622) * Allow for modification of output RGB values when using rgblight/rgb_matrix. (#10638) * Add housekeeping task callbacks so that keyboards/keymaps are capable of executing code for each main loop iteration. (#10530) * Rescale both ChibiOS and AVR backlighting. * Reduce Helix keyboard build variation (#8669) * Minor change to behavior allowing display updates to continue between task ticks (#10750) * Some GPIO manipulations in matrix.c change to atomic. (#10491) * qmk cformat (#10767) * [Keyboard] Update the Speedo firmware for v3.0 (#10657) * Maartenwut/Maarten namechange to evyd13/Evy (#10274) * [quantum] combine repeated lines of code (#10837) * Add step sequencer feature (#9703) * aeboards/ext65 refactor (#10820) * Refactor xelus/dawn60 for Rev2 later (#10584) * add DEBUG_MATRIX_SCAN_RATE_ENABLE to common_features.mk (#10824) * [Core] Added `add_oneshot_mods` & `del_oneshot_mods` (#10549) * update chibios os usb for the otg driver (#8893) * Remove HD44780 References, Part 4 (#10735) * [Keyboard] Add Valor FRL TKL (+refactor) (#10512) * Fix cursor position bug in oled_write_raw functions (#10800) * Fixup version.h writing when using SKIP_VERSION=yes (#10972) * Allow for certain code in the codebase assuming length of string. (#10974) * Add AT90USB support for serial.c (#10706) * Auto shift: support repeats and early registration (#9826) * Rename ledmatrix.h to match .c file (#7949) * Split RGB_MATRIX_ENABLE into _ENABLE and _DRIVER (#10231) * Split LED_MATRIX_ENABLE into _ENABLE and _DRIVER (#10840) * Merge point for 2020 Nov 28 Breaking Change --- quantum/process_keycode/process_auto_shift.c | 199 ++++++++++++++++++++------- quantum/process_keycode/process_auto_shift.h | 1 + quantum/process_keycode/process_joystick.c | 8 +- quantum/process_keycode/process_midi.c | 25 +++- quantum/process_keycode/process_midi.h | 2 +- quantum/process_keycode/process_sequencer.c | 62 +++++++++ quantum/process_keycode/process_sequencer.h | 21 +++ 7 files changed, 256 insertions(+), 62 deletions(-) create mode 100644 quantum/process_keycode/process_sequencer.c create mode 100644 quantum/process_keycode/process_sequencer.h (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_auto_shift.c b/quantum/process_keycode/process_auto_shift.c index b1267922ce..a2d315408b 100644 --- a/quantum/process_keycode/process_auto_shift.c +++ b/quantum/process_keycode/process_auto_shift.c @@ -16,48 +16,149 @@ #ifdef AUTO_SHIFT_ENABLE +# include # include # include "process_auto_shift.h" -static bool autoshift_enabled = true; static uint16_t autoshift_time = 0; static uint16_t autoshift_timeout = AUTO_SHIFT_TIMEOUT; static uint16_t autoshift_lastkey = KC_NO; +static struct { + // Whether autoshift is enabled. + bool enabled : 1; + // Whether the last auto-shifted key was released after the timeout. This + // is used to replicate the last key for a tap-then-hold. + bool lastshifted : 1; + // Whether an auto-shiftable key has been pressed but not processed. + bool in_progress : 1; + // Whether the auto-shifted keypress has been registered. + bool holding_shift : 1; +} autoshift_flags = {true, false, false, false}; + +/** \brief Record the press of an autoshiftable key + * + * \return Whether the record should be further processed. + */ +static bool autoshift_press(uint16_t keycode, uint16_t now, keyrecord_t *record) { + if (!autoshift_flags.enabled) { + return true; + } + +# ifndef AUTO_SHIFT_MODIFIERS + if (get_mods() & (~MOD_BIT(KC_LSFT))) { + return true; + } +# endif +# ifdef AUTO_SHIFT_REPEAT + const uint16_t elapsed = TIMER_DIFF_16(now, autoshift_time); +# ifndef AUTO_SHIFT_NO_AUTO_REPEAT + if (!autoshift_flags.lastshifted) { +# endif + if (elapsed < TAPPING_TERM && keycode == autoshift_lastkey) { + // Allow a tap-then-hold for keyrepeat. + if (!autoshift_flags.lastshifted) { + register_code(autoshift_lastkey); + } else { + // Simulate pressing the shift key. + add_weak_mods(MOD_BIT(KC_LSFT)); + register_code(autoshift_lastkey); + } + return false; + } +# ifndef AUTO_SHIFT_NO_AUTO_REPEAT + } +# endif +# endif -void autoshift_flush(void) { - if (autoshift_lastkey != KC_NO) { - uint16_t elapsed = timer_elapsed(autoshift_time); + // Record the keycode so we can simulate it later. + autoshift_lastkey = keycode; + autoshift_time = now; + autoshift_flags.in_progress = true; - if (elapsed > autoshift_timeout) { - tap_code16(LSFT(autoshift_lastkey)); +# if !defined(NO_ACTION_ONESHOT) && !defined(NO_ACTION_TAPPING) + clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED); +# endif + return false; +} + +/** \brief Registers an autoshiftable key under the right conditions + * + * If the autoshift delay has elapsed, register a shift and the key. + * + * If the autoshift key is released before the delay has elapsed, register the + * key without a shift. + */ +static void autoshift_end(uint16_t keycode, uint16_t now, bool matrix_trigger) { + // Called on key down with KC_NO, auto-shifted key up, and timeout. + if (autoshift_flags.in_progress) { + // Process the auto-shiftable key. + autoshift_flags.in_progress = false; + + // Time since the initial press was recorded. + const uint16_t elapsed = TIMER_DIFF_16(now, autoshift_time); + if (elapsed < autoshift_timeout) { + register_code(autoshift_lastkey); + autoshift_flags.lastshifted = false; } else { - tap_code(autoshift_lastkey); + // Simulate pressing the shift key. + add_weak_mods(MOD_BIT(KC_LSFT)); + register_code(autoshift_lastkey); + autoshift_flags.lastshifted = true; +# if defined(AUTO_SHIFT_REPEAT) && !defined(AUTO_SHIFT_NO_AUTO_REPEAT) + if (matrix_trigger) { + // Prevents release. + return; + } +# endif } - autoshift_time = 0; - autoshift_lastkey = KC_NO; +# if TAP_CODE_DELAY > 0 + wait_ms(TAP_CODE_DELAY); +# endif + unregister_code(autoshift_lastkey); + del_weak_mods(MOD_BIT(KC_LSFT)); + } else { + // Release after keyrepeat. + unregister_code(keycode); + if (keycode == autoshift_lastkey) { + // This will only fire when the key was the last auto-shiftable + // pressed. That prevents aaaaBBBB then releasing a from unshifting + // later Bs (if B wasn't auto-shiftable). + del_weak_mods(MOD_BIT(KC_LSFT)); + } } + send_keyboard_report(); // del_weak_mods doesn't send one. + // Roll the autoshift_time forward for detecting tap-and-hold. + autoshift_time = now; } -void autoshift_on(uint16_t keycode) { - autoshift_time = timer_read(); - autoshift_lastkey = keycode; +/** \brief Simulates auto-shifted key releases when timeout is hit + * + * Can be called from \c matrix_scan_user so that auto-shifted keys are sent + * immediately after the timeout has expired, rather than waiting for the key + * to be released. + */ +void autoshift_matrix_scan(void) { + if (autoshift_flags.in_progress) { + const uint16_t now = timer_read(); + const uint16_t elapsed = TIMER_DIFF_16(now, autoshift_time); + if (elapsed >= autoshift_timeout) { + autoshift_end(autoshift_lastkey, now, true); + } + } } void autoshift_toggle(void) { - if (autoshift_enabled) { - autoshift_enabled = false; - autoshift_flush(); - } else { - autoshift_enabled = true; - } + autoshift_flags.enabled = !autoshift_flags.enabled; + del_weak_mods(MOD_BIT(KC_LSFT)); } -void autoshift_enable(void) { autoshift_enabled = true; } +void autoshift_enable(void) { autoshift_flags.enabled = true; } + void autoshift_disable(void) { - autoshift_enabled = false; - autoshift_flush(); + autoshift_flags.enabled = false; + del_weak_mods(MOD_BIT(KC_LSFT)); } # ifndef AUTO_SHIFT_NO_SETUP @@ -70,19 +171,30 @@ void autoshift_timer_report(void) { } # endif -bool get_autoshift_state(void) { return autoshift_enabled; } +bool get_autoshift_state(void) { return autoshift_flags.enabled; } uint16_t get_autoshift_timeout(void) { return autoshift_timeout; } void set_autoshift_timeout(uint16_t timeout) { autoshift_timeout = timeout; } bool process_auto_shift(uint16_t keycode, keyrecord_t *record) { + // Note that record->event.time isn't reliable, see: + // https://github.com/qmk/qmk_firmware/pull/9826#issuecomment-733559550 + const uint16_t now = timer_read(); + if (record->event.pressed) { + if (autoshift_flags.in_progress) { + // Evaluate previous key if there is one. Doing this elsewhere is + // more complicated and easier to break. + autoshift_end(KC_NO, now, false); + } + // For pressing another key while keyrepeating shifted autoshift. + del_weak_mods(MOD_BIT(KC_LSFT)); + switch (keycode) { case KC_ASTG: autoshift_toggle(); return true; - case KC_ASON: autoshift_enable(); return true; @@ -102,41 +214,28 @@ bool process_auto_shift(uint16_t keycode, keyrecord_t *record) { autoshift_timer_report(); return true; # endif + } + } + + switch (keycode) { # ifndef NO_AUTO_SHIFT_ALPHA - case KC_A ... KC_Z: + case KC_A ... KC_Z: # endif # ifndef NO_AUTO_SHIFT_NUMERIC - case KC_1 ... KC_0: + case KC_1 ... KC_0: # endif # ifndef NO_AUTO_SHIFT_SPECIAL - case KC_TAB: - case KC_MINUS ... KC_SLASH: - case KC_NONUS_BSLASH: -# endif - autoshift_flush(); - if (!autoshift_enabled) return true; - -# ifndef AUTO_SHIFT_MODIFIERS - if (get_mods()) { - return true; - } -# endif - autoshift_on(keycode); - - // We need some extra handling here for OSL edge cases -# if !defined(NO_ACTION_ONESHOT) && !defined(NO_ACTION_TAPPING) - clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED); + case KC_TAB: + case KC_MINUS ... KC_SLASH: + case KC_NONUS_BSLASH: # endif + if (record->event.pressed) { + return autoshift_press(keycode, now, record); + } else { + autoshift_end(keycode, now, false); return false; - - default: - autoshift_flush(); - return true; - } - } else { - autoshift_flush(); + } } - return true; } diff --git a/quantum/process_keycode/process_auto_shift.h b/quantum/process_keycode/process_auto_shift.h index e86c4658e9..5b2718f11c 100644 --- a/quantum/process_keycode/process_auto_shift.h +++ b/quantum/process_keycode/process_auto_shift.h @@ -30,3 +30,4 @@ void autoshift_toggle(void); bool get_autoshift_state(void); uint16_t get_autoshift_timeout(void); void set_autoshift_timeout(uint16_t timeout); +void autoshift_matrix_scan(void); diff --git a/quantum/process_keycode/process_joystick.c b/quantum/process_keycode/process_joystick.c index 5778a7434c..3ffaf42bf8 100644 --- a/quantum/process_keycode/process_joystick.c +++ b/quantum/process_keycode/process_joystick.c @@ -129,17 +129,17 @@ bool process_joystick_analogread_quantum() { // test the converted value against the lower range int32_t ref = joystick_axes[axis_index].mid_digit; int32_t range = joystick_axes[axis_index].min_digit; - int32_t ranged_val = ((axis_val - ref) * -127) / (range - ref); + int32_t ranged_val = ((axis_val - ref) * -JOYSTICK_RESOLUTION) / (range - ref); if (ranged_val > 0) { // the value is in the higher range range = joystick_axes[axis_index].max_digit; - ranged_val = ((axis_val - ref) * 127) / (range - ref); + ranged_val = ((axis_val - ref) * JOYSTICK_RESOLUTION) / (range - ref); } // clamp the result in the valid range - ranged_val = ranged_val < -127 ? -127 : ranged_val; - ranged_val = ranged_val > 127 ? 127 : ranged_val; + ranged_val = ranged_val < -JOYSTICK_RESOLUTION ? -JOYSTICK_RESOLUTION : ranged_val; + ranged_val = ranged_val > JOYSTICK_RESOLUTION ? JOYSTICK_RESOLUTION : ranged_val; if (ranged_val != joystick_status.axes[axis_index]) { joystick_status.axes[axis_index] = ranged_val; diff --git a/quantum/process_keycode/process_midi.c b/quantum/process_keycode/process_midi.c index e525770144..8e2fb955e7 100644 --- a/quantum/process_keycode/process_midi.c +++ b/quantum/process_keycode/process_midi.c @@ -41,12 +41,12 @@ static int8_t midi_modulation_step; static uint16_t midi_modulation_timer; midi_config_t midi_config; -inline uint8_t compute_velocity(uint8_t setting) { return (setting + 1) * (128 / (MIDI_VELOCITY_MAX - MIDI_VELOCITY_MIN + 1)); } +inline uint8_t compute_velocity(uint8_t setting) { return setting * (128 / (MIDI_VELOCITY_MAX - MIDI_VELOCITY_MIN)); } void midi_init(void) { midi_config.octave = MI_OCT_2 - MIDI_OCTAVE_MIN; midi_config.transpose = 0; - midi_config.velocity = (MIDI_VELOCITY_MAX - MIDI_VELOCITY_MIN); + midi_config.velocity = 127; midi_config.channel = 0; midi_config.modulation_interval = 8; @@ -66,7 +66,7 @@ bool process_midi(uint16_t keycode, keyrecord_t *record) { case MIDI_TONE_MIN ... MIDI_TONE_MAX: { uint8_t channel = midi_config.channel; uint8_t tone = keycode - MIDI_TONE_MIN; - uint8_t velocity = compute_velocity(midi_config.velocity); + uint8_t velocity = midi_config.velocity; if (record->event.pressed) { if (tone_status[tone] == MIDI_INVALID_NOTE) { uint8_t note = midi_compute_note(keycode); @@ -124,19 +124,30 @@ bool process_midi(uint16_t keycode, keyrecord_t *record) { return false; case MIDI_VELOCITY_MIN ... MIDI_VELOCITY_MAX: if (record->event.pressed) { - midi_config.velocity = keycode - MIDI_VELOCITY_MIN; + midi_config.velocity = compute_velocity(keycode - MIDI_VELOCITY_MIN); dprintf("midi velocity %d\n", midi_config.velocity); } return false; case MI_VELD: if (record->event.pressed && midi_config.velocity > 0) { - midi_config.velocity--; + if (midi_config.velocity == 127) { + midi_config.velocity -= 10; + } else if (midi_config.velocity > 12) { + midi_config.velocity -= 13; + } else { + midi_config.velocity = 0; + } + dprintf("midi velocity %d\n", midi_config.velocity); } return false; case MI_VELU: - if (record->event.pressed) { - midi_config.velocity++; + if (record->event.pressed && midi_config.velocity < 127) { + if (midi_config.velocity < 115) { + midi_config.velocity += 13; + } else { + midi_config.velocity = 127; + } dprintf("midi velocity %d\n", midi_config.velocity); } return false; diff --git a/quantum/process_keycode/process_midi.h b/quantum/process_keycode/process_midi.h index 0007b3ed25..ef5661dd4d 100644 --- a/quantum/process_keycode/process_midi.h +++ b/quantum/process_keycode/process_midi.h @@ -35,7 +35,7 @@ typedef union { struct { uint8_t octave : 4; int8_t transpose : 4; - uint8_t velocity : 4; + uint8_t velocity : 7; uint8_t channel : 4; uint8_t modulation_interval : 4; }; diff --git a/quantum/process_keycode/process_sequencer.c b/quantum/process_keycode/process_sequencer.c new file mode 100644 index 0000000000..334b4c0092 --- /dev/null +++ b/quantum/process_keycode/process_sequencer.c @@ -0,0 +1,62 @@ +/* Copyright 2020 Rodolphe Belouin + * + * 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 . + */ + +#include "process_sequencer.h" + +bool process_sequencer(uint16_t keycode, keyrecord_t *record) { + if (record->event.pressed) { + switch (keycode) { + case SQ_ON: + sequencer_on(); + return false; + case SQ_OFF: + sequencer_off(); + return false; + case SQ_TOG: + sequencer_toggle(); + return false; + case SQ_TMPD: + sequencer_decrease_tempo(); + return false; + case SQ_TMPU: + sequencer_increase_tempo(); + return false; + case SEQUENCER_RESOLUTION_MIN ... SEQUENCER_RESOLUTION_MAX: + sequencer_set_resolution(keycode - SEQUENCER_RESOLUTION_MIN); + return false; + case SQ_RESD: + sequencer_decrease_resolution(); + return false; + case SQ_RESU: + sequencer_increase_resolution(); + return false; + case SQ_SALL: + sequencer_set_all_steps_on(); + return false; + case SQ_SCLR: + sequencer_set_all_steps_off(); + return false; + case SEQUENCER_STEP_MIN ... SEQUENCER_STEP_MAX: + sequencer_toggle_step(keycode - SEQUENCER_STEP_MIN); + return false; + case SEQUENCER_TRACK_MIN ... SEQUENCER_TRACK_MAX: + sequencer_toggle_single_active_track(keycode - SEQUENCER_TRACK_MIN); + return false; + } + } + + return true; +} diff --git a/quantum/process_keycode/process_sequencer.h b/quantum/process_keycode/process_sequencer.h new file mode 100644 index 0000000000..2b85f24299 --- /dev/null +++ b/quantum/process_keycode/process_sequencer.h @@ -0,0 +1,21 @@ +/* Copyright 2020 Rodolphe Belouin + * + * 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 . + */ + +#pragma once + +#include "quantum.h" + +bool process_sequencer(uint16_t keycode, keyrecord_t *record); -- cgit v1.2.3 From 501f2fdef115314713e94428d409e5c3b5bfc1c2 Mon Sep 17 00:00:00 2001 From: Ryan Date: Fri, 11 Dec 2020 13:45:24 +1100 Subject: Normalise include statements in core code (#11153) * Normalise include statements in core code * Missed one --- quantum/process_keycode/process_key_lock.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_key_lock.c b/quantum/process_keycode/process_key_lock.c index 602127a74b..4bd58f0c1e 100644 --- a/quantum/process_keycode/process_key_lock.c +++ b/quantum/process_keycode/process_key_lock.c @@ -14,8 +14,8 @@ * along with this program. If not, see . */ -#include "inttypes.h" -#include "stdint.h" +#include +#include #include "process_key_lock.h" #define BV_64(shift) (((uint64_t)1) << (shift)) -- cgit v1.2.3 From 54e2bf3edefb670ede2c2c3934dc732264ac6381 Mon Sep 17 00:00:00 2001 From: Joshua Diamond Date: Tue, 22 Dec 2020 12:23:09 -0500 Subject: Fix Issue #9533 - Delayed shift state handling (#11220) Co-authored-by: Ryan --- quantum/process_keycode/process_unicode_common.h | 1 - quantum/process_keycode/process_unicodemap.c | 9 +++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_unicode_common.h b/quantum/process_keycode/process_unicode_common.h index 3082fbb5f0..c10e171ec3 100644 --- a/quantum/process_keycode/process_unicode_common.h +++ b/quantum/process_keycode/process_unicode_common.h @@ -75,7 +75,6 @@ typedef union { } unicode_config_t; extern unicode_config_t unicode_config; -extern uint8_t unicode_saved_mods; void unicode_input_mode_init(void); uint8_t get_unicode_input_mode(void); diff --git a/quantum/process_keycode/process_unicodemap.c b/quantum/process_keycode/process_unicodemap.c index fcf676c24e..459397014d 100644 --- a/quantum/process_keycode/process_unicodemap.c +++ b/quantum/process_keycode/process_unicodemap.c @@ -21,8 +21,13 @@ __attribute__((weak)) uint16_t unicodemap_index(uint16_t keycode) { // Keycode is a pair: extract index based on Shift / Caps Lock state uint16_t index = keycode - QK_UNICODEMAP_PAIR; - bool shift = unicode_saved_mods & MOD_MASK_SHIFT; - bool caps = IS_HOST_LED_ON(USB_LED_CAPS_LOCK); + uint8_t mods = get_mods() | get_weak_mods(); +#ifndef NO_ACTION_ONESHOT + mods |= get_oneshot_mods(); +#endif + + bool shift = mods & MOD_MASK_SHIFT; + bool caps = host_keyboard_led_state().caps_lock; if (shift ^ caps) { index >>= 7; } -- cgit v1.2.3 From f40b56468366212ffa23de5dd424f24e42bb88bb Mon Sep 17 00:00:00 2001 From: Joshua Diamond Date: Tue, 22 Dec 2020 12:51:47 -0500 Subject: Partial fix for Issue #9405 - Caps Lock not working with Unicode Map's XP on Linux (#11232) --- quantum/process_keycode/process_unicode_common.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_unicode_common.c b/quantum/process_keycode/process_unicode_common.c index 80be316232..bac9fbcc0f 100644 --- a/quantum/process_keycode/process_unicode_common.c +++ b/quantum/process_keycode/process_unicode_common.c @@ -21,6 +21,7 @@ unicode_config_t unicode_config; uint8_t unicode_saved_mods; +bool unicode_saved_caps_lock; #if UNICODE_SELECTED_MODES != -1 static uint8_t selected[] = {UNICODE_SELECTED_MODES}; @@ -77,6 +78,16 @@ void cycle_unicode_input_mode(int8_t offset) { void persist_unicode_input_mode(void) { eeprom_update_byte(EECONFIG_UNICODEMODE, unicode_config.input_mode); } __attribute__((weak)) void unicode_input_start(void) { + unicode_saved_caps_lock = host_keyboard_led_state().caps_lock; + + // Note the order matters here! + // Need to do this before we mess around with the mods, or else + // UNICODE_KEY_LNX (which is usually Ctrl-Shift-U) might not work + // correctly in the shifted case. + if (unicode_config.input_mode == UC_LNX && unicode_saved_caps_lock) { + tap_code(KC_CAPS); + } + unicode_saved_mods = get_mods(); // Save current mods clear_mods(); // Unregister mods to start from a clean state @@ -107,6 +118,9 @@ __attribute__((weak)) void unicode_input_finish(void) { break; case UC_LNX: tap_code(KC_SPC); + if (unicode_saved_caps_lock) { + tap_code(KC_CAPS); + } break; case UC_WIN: unregister_code(KC_LALT); @@ -125,6 +139,11 @@ __attribute__((weak)) void unicode_input_cancel(void) { unregister_code(UNICODE_KEY_MAC); break; case UC_LNX: + tap_code(KC_ESC); + if (unicode_saved_caps_lock) { + tap_code(KC_CAPS); + } + break; case UC_WINC: tap_code(KC_ESC); break; -- cgit v1.2.3 From 48f4768d33313e6a6ed48c31f95eb44feda10a51 Mon Sep 17 00:00:00 2001 From: Ryan Date: Sat, 26 Dec 2020 15:53:12 +1100 Subject: Change include guards in quantum/ to pragma once (#11239) --- quantum/process_keycode/process_audio.h | 5 +---- quantum/process_keycode/process_clicky.h | 5 +---- quantum/process_keycode/process_combo.h | 5 +---- quantum/process_keycode/process_key_lock.h | 5 +---- quantum/process_keycode/process_leader.h | 5 +---- quantum/process_keycode/process_midi.h | 5 +---- quantum/process_keycode/process_music.h | 5 +---- quantum/process_keycode/process_printer.h | 5 +---- quantum/process_keycode/process_steno.h | 6 ++---- quantum/process_keycode/process_tap_dance.h | 6 ++---- quantum/process_keycode/process_terminal.h | 5 +---- quantum/process_keycode/process_terminal_nop.h | 5 +---- 12 files changed, 14 insertions(+), 48 deletions(-) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_audio.h b/quantum/process_keycode/process_audio.h index 3a84c3d869..d89a834ea8 100644 --- a/quantum/process_keycode/process_audio.h +++ b/quantum/process_keycode/process_audio.h @@ -1,5 +1,4 @@ -#ifndef PROCESS_AUDIO_H -#define PROCESS_AUDIO_H +#pragma once float compute_freq_for_midi_note(uint8_t note); @@ -9,5 +8,3 @@ void process_audio_noteoff(uint8_t note); void process_audio_all_notes_off(void); void audio_on_user(void); - -#endif diff --git a/quantum/process_keycode/process_clicky.h b/quantum/process_keycode/process_clicky.h index f746edb951..67b6463c5d 100644 --- a/quantum/process_keycode/process_clicky.h +++ b/quantum/process_keycode/process_clicky.h @@ -1,5 +1,4 @@ -#ifndef PROCESS_CLICKY_H -#define PROCESS_CLICKY_H +#pragma once void clicky_play(void); bool process_clicky(uint16_t keycode, keyrecord_t *record); @@ -13,5 +12,3 @@ void clicky_on(void); void clicky_off(void); bool is_clicky_on(void); - -#endif diff --git a/quantum/process_keycode/process_combo.h b/quantum/process_keycode/process_combo.h index 0f01aae93e..e51a2f1f4e 100644 --- a/quantum/process_keycode/process_combo.h +++ b/quantum/process_keycode/process_combo.h @@ -14,8 +14,7 @@ * along with this program. If not, see . */ -#ifndef PROCESS_COMBO_H -#define PROCESS_COMBO_H +#pragma once #include "progmem.h" #include "quantum.h" @@ -62,5 +61,3 @@ void combo_enable(void); void combo_disable(void); void combo_toggle(void); bool is_combo_enabled(void); - -#endif diff --git a/quantum/process_keycode/process_key_lock.h b/quantum/process_keycode/process_key_lock.h index a8e110a4bf..baa0b39077 100644 --- a/quantum/process_keycode/process_key_lock.h +++ b/quantum/process_keycode/process_key_lock.h @@ -14,11 +14,8 @@ * along with this program. If not, see . */ -#ifndef PROCESS_KEY_LOCK_H -#define PROCESS_KEY_LOCK_H +#pragma once #include "quantum.h" bool process_key_lock(uint16_t *keycode, keyrecord_t *record); - -#endif // PROCESS_KEY_LOCK_H diff --git a/quantum/process_keycode/process_leader.h b/quantum/process_keycode/process_leader.h index e0edf57b32..9844f27a1b 100644 --- a/quantum/process_keycode/process_leader.h +++ b/quantum/process_keycode/process_leader.h @@ -14,8 +14,7 @@ * along with this program. If not, see . */ -#ifndef PROCESS_LEADER_H -#define PROCESS_LEADER_H +#pragma once #include "quantum.h" @@ -37,5 +36,3 @@ void qk_leader_start(void); extern uint16_t leader_sequence[5]; \ extern uint8_t leader_sequence_size #define LEADER_DICTIONARY() if (leading && timer_elapsed(leader_time) > LEADER_TIMEOUT) - -#endif diff --git a/quantum/process_keycode/process_midi.h b/quantum/process_keycode/process_midi.h index ef5661dd4d..68c6eda666 100644 --- a/quantum/process_keycode/process_midi.h +++ b/quantum/process_keycode/process_midi.h @@ -14,8 +14,7 @@ * along with this program. If not, see . */ -#ifndef PROCESS_MIDI_H -#define PROCESS_MIDI_H +#pragma once #include "quantum.h" @@ -53,5 +52,3 @@ uint8_t midi_compute_note(uint16_t keycode); # endif // MIDI_ADVANCED #endif // MIDI_ENABLE - -#endif diff --git a/quantum/process_keycode/process_music.h b/quantum/process_keycode/process_music.h index 292bc53742..01014aa6c2 100644 --- a/quantum/process_keycode/process_music.h +++ b/quantum/process_keycode/process_music.h @@ -14,8 +14,7 @@ * along with this program. If not, see . */ -#ifndef PROCESS_MUSIC_H -#define PROCESS_MUSIC_H +#pragma once #include "quantum.h" @@ -57,5 +56,3 @@ bool music_mask_user(uint16_t keycode); # endif #endif // defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC)) - -#endif diff --git a/quantum/process_keycode/process_printer.h b/quantum/process_keycode/process_printer.h index 71d3a4b56a..3c6d06ff94 100644 --- a/quantum/process_keycode/process_printer.h +++ b/quantum/process_keycode/process_printer.h @@ -14,13 +14,10 @@ * along with this program. If not, see . */ -#ifndef PROCESS_PRINTER_H -#define PROCESS_PRINTER_H +#pragma once #include "quantum.h" #include "protocol/serial.h" bool process_printer(uint16_t keycode, keyrecord_t *record); - -#endif diff --git a/quantum/process_keycode/process_steno.h b/quantum/process_keycode/process_steno.h index ed049eb13f..d11fd40af0 100644 --- a/quantum/process_keycode/process_steno.h +++ b/quantum/process_keycode/process_steno.h @@ -13,8 +13,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -#ifndef PROCESS_STENO_H -#define PROCESS_STENO_H + +#pragma once #include "quantum.h" @@ -25,5 +25,3 @@ void steno_init(void); void steno_set_mode(steno_mode_t mode); uint8_t *steno_get_state(void); uint8_t *steno_get_chord(void); - -#endif diff --git a/quantum/process_keycode/process_tap_dance.h b/quantum/process_keycode/process_tap_dance.h index 09ceef74d8..a013c5cabf 100644 --- a/quantum/process_keycode/process_tap_dance.h +++ b/quantum/process_keycode/process_tap_dance.h @@ -13,8 +13,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -#ifndef PROCESS_TAP_DANCE_H -#define PROCESS_TAP_DANCE_H + +#pragma once #ifdef TAP_DANCE_ENABLE @@ -101,5 +101,3 @@ void qk_tap_dance_dual_role_reset(qk_tap_dance_state_t *state, void *user_data); # define TD(n) KC_NO #endif - -#endif diff --git a/quantum/process_keycode/process_terminal.h b/quantum/process_keycode/process_terminal.h index 8426f442b6..0159131e5b 100644 --- a/quantum/process_keycode/process_terminal.h +++ b/quantum/process_keycode/process_terminal.h @@ -14,8 +14,7 @@ * along with this program. If not, see . */ -#ifndef PROCESS_TERMINAL_H -#define PROCESS_TERMINAL_H +#pragma once #include "quantum.h" @@ -23,5 +22,3 @@ extern const char keycode_to_ascii_lut[58]; extern const char shifted_keycode_to_ascii_lut[58]; extern const char terminal_prompt[8]; bool process_terminal(uint16_t keycode, keyrecord_t *record); - -#endif \ No newline at end of file diff --git a/quantum/process_keycode/process_terminal_nop.h b/quantum/process_keycode/process_terminal_nop.h index 56895b33c3..36e25320c5 100644 --- a/quantum/process_keycode/process_terminal_nop.h +++ b/quantum/process_keycode/process_terminal_nop.h @@ -14,12 +14,9 @@ * along with this program. If not, see . */ -#ifndef PROCESS_TERMINAL_H -#define PROCESS_TERMINAL_H +#pragma once #include "quantum.h" #define TERM_ON KC_NO #define TERM_OFF KC_NO - -#endif \ No newline at end of file -- cgit v1.2.3 From 810eafad121bda333c53490e2d8a29f3a83d9c19 Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Mon, 4 Jan 2021 16:37:20 -0800 Subject: Fix Tap-Hold Configs (#11127) * Add proper prototypes for Tap-Hold Per Key functions * Fix handwired/tennie default keymap * Remove unneeded references * Fix tapping term per key check in space cadet * Pre-emptive fix for tap dance * Fix marksard/leftover30 * Replace hard coded tapping term with define --- quantum/process_keycode/process_space_cadet.c | 11 ++++++----- quantum/process_keycode/process_space_cadet.h | 3 --- quantum/process_keycode/process_tap_dance.c | 5 ++++- 3 files changed, 10 insertions(+), 9 deletions(-) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_space_cadet.c b/quantum/process_keycode/process_space_cadet.c index bcaf62a964..f99db2a87b 100644 --- a/quantum/process_keycode/process_space_cadet.c +++ b/quantum/process_keycode/process_space_cadet.c @@ -16,10 +16,6 @@ #include "process_space_cadet.h" #include "action_tapping.h" -#ifdef NO_ACTION_TAPPING -__attribute__((weak)) uint16_t get_tapping_term(uint16_t keycode, keyrecord_t *record) { return TAPPING_TERM; }; -#endif - // ********** OBSOLETE DEFINES, STOP USING! (pls?) ********** // Shift / paren setup #ifndef LSPO_KEY @@ -97,7 +93,12 @@ void perform_space_cadet(keyrecord_t *record, uint16_t sc_keycode, uint8_t holdM register_mods(MOD_BIT(holdMod)); } } else { - if (sc_last == holdMod && timer_elapsed(sc_timer) < get_tapping_term(sc_keycode, record)) { +#ifdef TAPPING_TERM_PER_KEY + if (sc_last == holdMod && timer_elapsed(sc_timer) < get_tapping_term(sc_keycode, record)) +#else + if (sc_last == holdMod && timer_elapsed(sc_timer) < TAPPING_TERM) +#endif + { if (holdMod != tapMod) { if (IS_MOD(holdMod)) { unregister_mods(MOD_BIT(holdMod)); diff --git a/quantum/process_keycode/process_space_cadet.h b/quantum/process_keycode/process_space_cadet.h index 3ace073997..fcb70f3b43 100644 --- a/quantum/process_keycode/process_space_cadet.h +++ b/quantum/process_keycode/process_space_cadet.h @@ -19,6 +19,3 @@ void perform_space_cadet(keyrecord_t *record, uint16_t sc_keycode, uint8_t holdMod, uint8_t tapMod, uint8_t keycode); bool process_space_cadet(uint16_t keycode, keyrecord_t *record); -#ifdef NO_ACTION_TAPPING -uint16_t get_tapping_term(uint16_t keycode, keyrecord_t *record); -#endif diff --git a/quantum/process_keycode/process_tap_dance.c b/quantum/process_keycode/process_tap_dance.c index 0c7b6353eb..138de0eba2 100644 --- a/quantum/process_keycode/process_tap_dance.c +++ b/quantum/process_keycode/process_tap_dance.c @@ -14,7 +14,6 @@ * along with this program. If not, see . */ #include "quantum.h" -#include "action_tapping.h" #ifndef NO_ACTION_ONESHOT uint8_t get_oneshot_mods(void); @@ -167,7 +166,11 @@ void matrix_scan_tap_dance() { if (action->custom_tapping_term > 0) { tap_user_defined = action->custom_tapping_term; } else { +#ifdef TAPPING_TERM_PER_KEY tap_user_defined = get_tapping_term(action->state.keycode, NULL); +#else + tap_user_defined = TAPPING_TERM; +#endif } if (action->state.count && timer_elapsed(action->state.timer) > tap_user_defined) { process_tap_dance_action_on_dance_finished(action); -- cgit v1.2.3 From 71f067a60ef01df6a58c086a939a58e40ab7e972 Mon Sep 17 00:00:00 2001 From: Takeshi Nishio Date: Wed, 20 Jan 2021 11:08:06 +0900 Subject: Fix wrong key when "Music Map" is used with MAJOR_MODE. (#11234) With MAJOR_MODE (= major scale), keys in one octave is not 12 but 7. To solve this problem, change divisor number from 12 to 7 at %(Modulo) and /(Division). NOTE: The last 12 represents half step keys in one octave for pitch calculation. --- quantum/process_keycode/process_music.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_music.c b/quantum/process_keycode/process_music.c index b61a16e878..eb06be96c2 100644 --- a/quantum/process_keycode/process_music.c +++ b/quantum/process_keycode/process_music.c @@ -191,7 +191,7 @@ bool process_music(uint16_t keycode, keyrecord_t *record) { note = music_starting_note + music_offset + 36 + music_map[record->event.key.row][record->event.key.col]; } else { uint8_t position = music_map[record->event.key.row][record->event.key.col]; - note = music_starting_note + music_offset + 36 + SCALE[position % 12] + (position / 12) * 12; + note = music_starting_note + music_offset + 36 + SCALE[position % 7] + (position / 7) * 12; } # else if (music_mode == MUSIC_MODE_CHROMATIC) -- cgit v1.2.3 From 88dce243750d9e80948cd7262566182018d7bbdf Mon Sep 17 00:00:00 2001 From: Ryan Date: Fri, 12 Mar 2021 18:03:44 +1100 Subject: Remove hex_to_keycode and move tap_random_base64 to send_string.c (#12079) --- quantum/process_keycode/process_unicode_common.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_unicode_common.c b/quantum/process_keycode/process_unicode_common.c index bac9fbcc0f..46fcaaa86b 100644 --- a/quantum/process_keycode/process_unicode_common.c +++ b/quantum/process_keycode/process_unicode_common.c @@ -158,7 +158,7 @@ __attribute__((weak)) void unicode_input_cancel(void) { void register_hex(uint16_t hex) { for (int i = 3; i >= 0; i--) { uint8_t digit = ((hex >> (i * 4)) & 0xF); - tap_code16(hex_to_keycode(digit)); + send_nibble(digit); } } @@ -171,10 +171,10 @@ void register_hex32(uint32_t hex) { uint8_t digit = ((hex >> (i * 4)) & 0xF); if (digit == 0) { if (!onzerostart) { - tap_code16(hex_to_keycode(digit)); + send_nibble(digit); } } else { - tap_code16(hex_to_keycode(digit)); + send_nibble(digit); onzerostart = false; } } -- cgit v1.2.3 From 8e820cde131c72d7966fb5dd528ba0ed2c1cd577 Mon Sep 17 00:00:00 2001 From: jakobkg Date: Thu, 25 Mar 2021 12:51:57 +0100 Subject: Fix handling multiples of the same MIDI note (fixes bug brought up in issue #10199) (#11639) * Fix handling multiples of the same MIDI note * Extend MIDI note status to fix note releases --- quantum/process_keycode/process_midi.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_midi.c b/quantum/process_keycode/process_midi.c index 8e2fb955e7..9632d2b757 100644 --- a/quantum/process_keycode/process_midi.c +++ b/quantum/process_keycode/process_midi.c @@ -34,7 +34,7 @@ void process_midi_all_notes_off(void) { midi_send_cc(&midi_device, 0, 0x7B, 0); # include "timer.h" -static uint8_t tone_status[MIDI_TONE_COUNT]; +static uint8_t tone_status[2][MIDI_TONE_COUNT]; static uint8_t midi_modulation; static int8_t midi_modulation_step; @@ -51,7 +51,8 @@ void midi_init(void) { midi_config.modulation_interval = 8; for (uint8_t i = 0; i < MIDI_TONE_COUNT; i++) { - tone_status[i] = MIDI_INVALID_NOTE; + tone_status[0][i] = MIDI_INVALID_NOTE; + tone_status[1][i] = 0; } midi_modulation = 0; @@ -68,19 +69,21 @@ bool process_midi(uint16_t keycode, keyrecord_t *record) { uint8_t tone = keycode - MIDI_TONE_MIN; uint8_t velocity = midi_config.velocity; if (record->event.pressed) { - if (tone_status[tone] == MIDI_INVALID_NOTE) { - uint8_t note = midi_compute_note(keycode); - midi_send_noteon(&midi_device, channel, note, velocity); - dprintf("midi noteon channel:%d note:%d velocity:%d\n", channel, note, velocity); - tone_status[tone] = note; + uint8_t note = midi_compute_note(keycode); + midi_send_noteon(&midi_device, channel, note, velocity); + dprintf("midi noteon channel:%d note:%d velocity:%d\n", channel, note, velocity); + tone_status[1][tone] += 1; + if (tone_status[0][tone] == MIDI_INVALID_NOTE) { + tone_status[0][tone] = note; } } else { - uint8_t note = tone_status[tone]; - if (note != MIDI_INVALID_NOTE) { + uint8_t note = tone_status[0][tone]; + tone_status[1][tone] -= 1; + if (tone_status[1][tone] == 0) { midi_send_noteoff(&midi_device, channel, note, velocity); dprintf("midi noteoff channel:%d note:%d velocity:%d\n", channel, note, velocity); + tone_status[0][tone] = MIDI_INVALID_NOTE; } - tone_status[tone] = MIDI_INVALID_NOTE; } return false; } -- cgit v1.2.3 From 57475caab0c030dc3e37086fdc060ddf0c81e69f Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Thu, 25 Mar 2021 05:41:19 -0700 Subject: Fix issues when manually shifting characters and Auto Shift (#12083) Specifically, when using the Auto-Shift feature, if you hold and roll shift, it would not actually shift the character that you hit after the shift --- quantum/process_keycode/process_auto_shift.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_auto_shift.c b/quantum/process_keycode/process_auto_shift.c index a2d315408b..bf359e994d 100644 --- a/quantum/process_keycode/process_auto_shift.c +++ b/quantum/process_keycode/process_auto_shift.c @@ -46,7 +46,7 @@ static bool autoshift_press(uint16_t keycode, uint16_t now, keyrecord_t *record) } # ifndef AUTO_SHIFT_MODIFIERS - if (get_mods() & (~MOD_BIT(KC_LSFT))) { + if (get_mods()) { return true; } # endif -- cgit v1.2.3 From da6e888a32a6d9c09a1506e9ae4a59a36f8a5354 Mon Sep 17 00:00:00 2001 From: Sergey Vlasov Date: Sun, 25 Apr 2021 06:41:37 +0300 Subject: Do not leak weak mods from tap dance to the interrupting keypress (#12471) Tap dance callbacks may register weak mods; one case when it happens is when a tap dance registers a key with modifiers. When the tap dance is interrupted by pressing another key, these weak mods could affect the interrupting key (normally any stale weak mods are cleared at the start of action_exec() when handling a keypress event, but the tap dance interrupt check code is called later, and the weak mods left by that code were not cleared). Add another clear_weak_mods() call to preprocess_tap_dance() to make sure that the interrupting keypress is not affected by unrelated weak mods from the previous tap dance. Fixes #12445. --- quantum/process_keycode/process_tap_dance.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_tap_dance.c b/quantum/process_keycode/process_tap_dance.c index 138de0eba2..17dc540a64 100644 --- a/quantum/process_keycode/process_tap_dance.c +++ b/quantum/process_keycode/process_tap_dance.c @@ -117,6 +117,10 @@ void preprocess_tap_dance(uint16_t keycode, keyrecord_t *record) { action->state.interrupting_keycode = keycode; process_tap_dance_action_on_dance_finished(action); reset_tap_dance(&action->state); + + // Tap dance actions can leave some weak mods active (e.g., if the tap dance is mapped to a keycode with + // modifiers), but these weak mods should not affect the keypress which interrupted the tap dance. + clear_weak_mods(); } } } -- cgit v1.2.3