diff options
author | skullY <skullydazed@gmail.com> | 2019-08-30 11:19:03 -0700 |
---|---|---|
committer | Florian Didron <fdidron@users.noreply.github.com> | 2019-09-17 11:39:43 +0900 |
commit | f8fe33acfac01064112fd2b5da680abfb5190b97 (patch) | |
tree | fcf75ef930800a948e5a3ba015d6759889f2284d /quantum/process_keycode | |
parent | c339d670684674165b422a0168bfd2016ff2e6ef (diff) |
clang-format changes
Diffstat (limited to 'quantum/process_keycode')
30 files changed, 1889 insertions, 2080 deletions
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 5970242263..cba2dcd2dd 100644 --- a/quantum/process_keycode/process_auto_shift.c +++ b/quantum/process_keycode/process_auto_shift.c @@ -16,9 +16,9 @@ #ifdef AUTO_SHIFT_ENABLE -#include <stdio.h> +# include <stdio.h> -#include "process_auto_shift.h" +# include "process_auto_shift.h" static bool autoshift_enabled = true; static uint16_t autoshift_time = 0; @@ -34,7 +34,7 @@ void autoshift_timer_report(void) { } void autoshift_on(uint16_t keycode) { - autoshift_time = timer_read(); + autoshift_time = timer_read(); autoshift_lastkey = keycode; } @@ -54,9 +54,7 @@ void autoshift_flush(void) { } -void autoshift_enable(void) { - autoshift_enabled = true; -} +void autoshift_enable(void) { autoshift_enabled = true; } void autoshift_disable(void) { autoshift_enabled = false; autoshift_flush(); diff --git a/quantum/process_keycode/process_auto_shift.h b/quantum/process_keycode/process_auto_shift.h index 5a2656feec..b909d28eef 100644 --- a/quantum/process_keycode/process_auto_shift.h +++ b/quantum/process_keycode/process_auto_shift.h @@ -19,7 +19,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 <stdint.h> #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 <string.h> +# include "process_leader.h" +# include <string.h> -#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 <LUFA/Drivers/USB/USB.h> -#include "midi.h" -#include "qmk_midi.h" +# include <LUFA/Drivers/USB/USB.h> +# 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 <stdbool.h> -#include <inttypes.h> - -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 <stdbool.h> +# include <inttypes.h> + +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 <math.h> #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 <layer> <row> <col>\n"); - #endif +#ifdef TERMINAL_HELP + SEND_STRING("usage: keycode <layer> <row> <col>\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 <layer>\n"); - #endif +#ifdef TERMINAL_HELP + SEND_STRING("usage: keymap <layer>\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;i<CMD_BUFF_SIZE;i++){ - char tmpChar = ' '; - itoa(i ,&tmpChar,10); - const char * tmpCnstCharStr = &tmpChar; //because sned_string wont take a normal char * - send_string(tmpCnstCharStr); - SEND_STRING(". "); - send_string(cmd_buffer[i]); - SEND_STRING("\n"); - } + /* 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; i < CMD_BUFF_SIZE; i++) { + char tmpChar = ' '; + itoa(i, &tmpChar, 10); + const char *tmpCnstCharStr = &tmpChar; // because sned_string wont take a normal char * + send_string(tmpCnstCharStr); + SEND_STRING(". "); + send_string(cmd_buffer[i]); + SEND_STRING("\n"); + } } - void flush_cmd_buffer(void) { - memset(cmd_buffer,0,CMD_BUFF_SIZE * 80); - SEND_STRING("Buffer Cleared!\n"); + memset(cmd_buffer, 0, CMD_BUFF_SIZE * 80); + SEND_STRING("Buffer Cleared!\n"); } -stringcase terminal_cases[] = { - { "about", terminal_about }, - { "help", terminal_help }, - { "keycode", terminal_keycode }, - { "keymap", terminal_keymap }, - { "flush-buffer" , flush_cmd_buffer}, - { "print-buffer" , print_cmd_buff}, - { "exit", disable_terminal } -}; +stringcase terminal_cases[] = {{"about", terminal_about}, {"help", terminal_help}, {"keycode", terminal_keycode}, {"keymap", terminal_keymap}, {"flush-buffer", flush_cmd_buffer}, {"print-buffer", print_cmd_buff}, {"exit", disable_terminal}}; void terminal_help(void) { SEND_STRING("commands available:\n "); - for( stringcase* case_p = terminal_cases; case_p != terminal_cases + sizeof( terminal_cases ) / sizeof( terminal_cases[0] ); case_p++ ) { + for (stringcase *case_p = terminal_cases; case_p != terminal_cases + sizeof(terminal_cases) / sizeof(terminal_cases[0]); case_p++) { send_string(case_p->string); 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); |