diff options
-rw-r--r-- | common_features.mk | 6 | ||||
-rw-r--r-- | keyboards/planck/ez/ez.c | 108 | ||||
-rw-r--r-- | quantum/process_keycode/process_space_cadet.c | 146 | ||||
-rw-r--r-- | quantum/process_keycode/process_space_cadet.h | 21 | ||||
-rw-r--r-- | quantum/quantum.c | 123 | ||||
-rw-r--r-- | quantum/quantum.h | 4 | ||||
-rw-r--r-- | quantum/quantum_keycodes.h | 12 | ||||
-rw-r--r-- | tmk_core/common/chibios/suspend.c | 2 |
8 files changed, 247 insertions, 175 deletions
diff --git a/common_features.mk b/common_features.mk index fbfbc3ebc6..6d03f4f405 100644 --- a/common_features.mk +++ b/common_features.mk @@ -343,3 +343,9 @@ ifeq ($(strip $(OLED_DRIVER_ENABLE)), yes) QUANTUM_LIB_SRC += i2c_master.c SRC += oled_driver.c endif + +SPACE_CADET_ENABLE ?= yes +ifeq ($(strip $(SPACE_CADET_ENABLE)), yes) + SRC += $(QUANTUM_DIR)/process_keycode/process_space_cadet.c + OPT_DEFS += -DSPACE_CADET_ENABLE +endif diff --git a/keyboards/planck/ez/ez.c b/keyboards/planck/ez/ez.c index b859af6c15..c3b7e26170 100644 --- a/keyboards/planck/ez/ez.c +++ b/keyboards/planck/ez/ez.c @@ -22,60 +22,60 @@ const is31_led g_is31_leds[DRIVER_LED_TOTAL] = { * | | G location * | | | B location * | | | | */ - {0, A_12, B_12, C_12}, - {0, A_11, B_11, C_11}, - {0, A_10, B_10, C_10}, - {0, A_9, B_9, C_9}, - {0, A_8, B_8, C_8}, - {0, A_7, B_7, C_7}, - - {0, G_12, H_12, I_12}, - {0, G_11, H_11, I_11}, - {0, G_10, H_10, I_10}, - {0, G_9, H_9, I_9}, - {0, G_8, H_8, I_8}, - {0, G_7, H_7, I_7}, - - {0, A_6, B_6, C_6}, - {0, A_5, B_5, C_5}, - {0, A_4, B_4, C_4}, - {0, A_3, B_3, C_3}, - {0, A_2, B_2, C_2}, - {0, A_1, B_1, C_1}, - - {0, G_6, H_6, I_6}, - {0, G_5, H_5, I_5}, - {0, G_4, H_4, I_4}, - {0, G_3, H_3, I_3}, - {0, G_2, H_2, I_2}, - {0, G_1, H_1, I_1}, - - {0, D_12, E_12, F_12}, - {0, D_11, E_11, F_11}, - {0, D_10, E_10, F_10}, - {0, D_9, E_9, F_9}, - {0, D_8, E_8, F_8}, - {0, D_7, E_7, F_7}, - - {0, J_12, K_12, L_12}, - {0, J_11, K_11, L_11}, - {0, J_10, K_10, L_10}, - {0, J_9, K_9, L_9}, - {0, J_8, K_8, L_8}, - {0, J_7, K_7, L_7}, - - {0, D_6, E_6, F_6}, - {0, D_5, E_5, F_5}, - {0, D_4, E_4, F_4}, - {0, D_3, E_3, F_3}, - {0, D_2, E_2, F_2}, - {0, D_1, E_1, F_1}, - - {0, J_6, K_6, L_6}, - {0, J_5, K_5, L_5}, - {0, J_4, K_4, L_4}, - {0, J_3, K_3, L_3}, - {0, J_2, K_2, L_2}, + {0, B_12, A_12, C_12}, + {0, B_11, A_11, C_11}, + {0, B_10, A_10, C_10}, + {0, B_9, A_9, C_9}, + {0, B_8, A_8, C_8}, + {0, B_7, A_7, C_7}, + + {0, H_12, G_12, I_12}, + {0, H_11, G_11, I_11}, + {0, H_10, G_10, I_10}, + {0, H_9, G_9, I_9}, + {0, H_8, G_8, I_8}, + {0, H_7, G_7, I_7}, + + {0, B_6, A_6, C_6}, + {0, B_5, A_5, C_5}, + {0, B_4, A_4, C_4}, + {0, B_3, A_3, C_3}, + {0, B_2, A_2, C_2}, + {0, B_1, A_1, C_1}, + + {0, H_6, G_6, I_6}, + {0, H_5, G_5, I_5}, + {0, H_4, G_4, I_4}, + {0, H_3, G_3, I_3}, + {0, H_2, G_2, I_2}, + {0, H_1, G_1, I_1}, + + {0, E_12, D_12, F_12}, + {0, E_11, D_11, F_11}, + {0, E_10, D_10, F_10}, + {0, E_9, D_9, F_9}, + {0, E_8, D_8, F_8}, + {0, E_7, D_7, F_7}, + + {0, K_12, J_12, L_12}, + {0, K_11, J_11, L_11}, + {0, K_10, J_10, L_10}, + {0, K_9, J_9, L_9}, + {0, K_8, J_8, L_8}, + {0, K_7, J_7, L_7}, + + {0, E_6, D_6, F_6}, + {0, E_5, D_5, F_5}, + {0, E_4, D_4, F_4}, + {0, E_3, D_3, F_3}, + {0, E_2, D_2, F_2}, + {0, E_1, D_1, F_1}, + + {0, K_6, J_6, L_6}, + {0, K_5, J_5, L_5}, + {0, K_4, J_4, L_4}, + {0, K_3, J_3, L_3}, + {0, K_2, J_2, L_2}, }; diff --git a/quantum/process_keycode/process_space_cadet.c b/quantum/process_keycode/process_space_cadet.c new file mode 100644 index 0000000000..a9c506168d --- /dev/null +++ b/quantum/process_keycode/process_space_cadet.c @@ -0,0 +1,146 @@ +/* Copyright 2019 Jack Humbert + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ +#include "process_space_cadet.h" + +#ifndef TAPPING_TERM + #define TAPPING_TERM 200 +#endif + +// ********** OBSOLETE DEFINES, STOP USING! (pls?) ********** +// Shift / paren setup +#ifndef LSPO_KEY + #define LSPO_KEY KC_9 +#endif +#ifndef RSPC_KEY + #define RSPC_KEY KC_0 +#endif + +// Shift / Enter setup +#ifndef SFTENT_KEY + #define SFTENT_KEY KC_ENT +#endif + +#ifdef DISABLE_SPACE_CADET_MODIFIER + #ifndef LSPO_MOD + #define LSPO_MOD KC_TRNS + #endif + #ifndef RSPC_MOD + #define RSPC_MOD KC_TRNS + #endif +#else + #ifndef LSPO_MOD + #define LSPO_MOD KC_LSFT + #endif + #ifndef RSPC_MOD + #define RSPC_MOD KC_RSFT + #endif +#endif +// ********************************************************** + +// Shift / paren setup +#ifndef LSPO_KEYS + #define LSPO_KEYS KC_LSFT, LSPO_MOD, LSPO_KEY +#endif +#ifndef RSPC_KEYS + #define RSPC_KEYS KC_RSFT, RSPC_MOD, RSPC_KEY +#endif + +// Control / paren setup +#ifndef LCPO_KEYS + #define LCPO_KEYS KC_LCTL, KC_LCTL, KC_9 +#endif +#ifndef RCPO_KEYS + #define RCPO_KEYS KC_RCTL, KC_RCTL, KC_0 +#endif + +// Alt / paren setup +#ifndef LAPO_KEYS + #define LAPO_KEYS KC_LALT, KC_LALT, KC_9 +#endif +#ifndef RAPO_KEYS + #define RAPO_KEYS KC_RALT, KC_RALT, KC_0 +#endif + +// Shift / Enter setup +#ifndef SFTENT_KEYS + #define SFTENT_KEYS KC_RSFT, KC_TRNS, SFTENT_KEY +#endif + +static uint8_t sc_last = 0; +static uint16_t sc_timer = 0; + +void perform_space_cadet(keyrecord_t *record, uint8_t normalMod, uint8_t tapMod, uint8_t keycode) { + if (record->event.pressed) { + sc_last = normalMod; + sc_timer = timer_read (); + if (IS_MOD(normalMod)) { + register_mods(MOD_BIT(normalMod)); + } + } + else { + if (IS_MOD(normalMod)) { + unregister_mods(MOD_BIT(normalMod)); + } + + if (sc_last == normalMod && timer_elapsed(sc_timer) < TAPPING_TERM) { + if (IS_MOD(tapMod)) { + register_mods(MOD_BIT(tapMod)); + } + tap_code(keycode); + if (IS_MOD(tapMod)) { + unregister_mods(MOD_BIT(tapMod)); + } + } + } +} + +bool process_space_cadet(uint16_t keycode, keyrecord_t *record) { + switch(keycode) { + case KC_LSPO: { + perform_space_cadet(record, LSPO_KEYS); + return false; + } + case KC_RSPC: { + perform_space_cadet(record, RSPC_KEYS); + return false; + } + case KC_LCPO: { + perform_space_cadet(record, LCPO_KEYS); + return false; + } + case KC_RCPC: { + perform_space_cadet(record, RCPO_KEYS); + return false; + } + case KC_LAPO: { + perform_space_cadet(record, LAPO_KEYS); + return false; + } + case KC_RAPC: { + perform_space_cadet(record, RAPO_KEYS); + return false; + } + case KC_SFTENT: { + perform_space_cadet(record, SFTENT_KEYS); + return false; + } + default: { + sc_last = 0; + break; + } + } + return true; +} diff --git a/quantum/process_keycode/process_space_cadet.h b/quantum/process_keycode/process_space_cadet.h new file mode 100644 index 0000000000..3f08b8002a --- /dev/null +++ b/quantum/process_keycode/process_space_cadet.h @@ -0,0 +1,21 @@ +/* Copyright 2019 Jack Humbert + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ +#pragma once + +#include "quantum.h" + +void perform_space_cadet(keyrecord_t *record, uint8_t normalMod, uint8_t tapMod, uint8_t keycode); +bool process_space_cadet(uint16_t keycode, keyrecord_t *record); diff --git a/quantum/quantum.c b/quantum/quantum.c index 86dc00381e..2d21bf0773 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -24,10 +24,6 @@ #include "outputselect.h" #endif -#ifndef TAPPING_TERM -#define TAPPING_TERM 200 -#endif - #ifndef BREATHING_PERIOD #define BREATHING_PERIOD 6 #endif @@ -196,30 +192,6 @@ void reset_keyboard(void) { bootloader_jump(); } -// Shift / paren setup - -#ifndef LSPO_KEY - #define LSPO_KEY KC_9 -#endif -#ifndef RSPC_KEY - #define RSPC_KEY KC_0 -#endif - -#ifndef LSPO_MOD - #define LSPO_MOD KC_LSFT -#endif -#ifndef RSPC_MOD - #define RSPC_MOD KC_RSFT -#endif - -// Shift / Enter setup -#ifndef SFTENT_KEY - #define SFTENT_KEY KC_ENT -#endif - -static bool shift_interrupted[2] = {0, 0}; -static uint16_t scs_timer[2] = {0, 0}; - /* true if the last press of GRAVE_ESC was shifted (i.e. GUI or SHIFT were pressed), false otherwise. * Used to ensure that the correct keycode is released if the key is released. */ @@ -329,6 +301,9 @@ bool process_record_quantum(keyrecord_t *record) { #ifdef TERMINAL_ENABLE process_terminal(keycode, record) && #endif + #ifdef SPACE_CADET_ENABLE + process_space_cadet(keycode, record) && + #endif true)) { return false; } @@ -685,92 +660,6 @@ bool process_record_quantum(keyrecord_t *record) { return false; } break; - case KC_LSPO: { - if (record->event.pressed) { - shift_interrupted[0] = false; - scs_timer[0] = timer_read (); - register_mods(MOD_BIT(KC_LSFT)); - } - else { - #ifdef DISABLE_SPACE_CADET_ROLLOVER - if (get_mods() & MOD_BIT(RSPC_MOD)) { - shift_interrupted[0] = true; - shift_interrupted[1] = true; - } - #endif - if (!shift_interrupted[0] && timer_elapsed(scs_timer[0]) < TAPPING_TERM) { - #ifdef DISABLE_SPACE_CADET_MODIFIER - unregister_mods(MOD_BIT(KC_LSFT)); - #else - if( LSPO_MOD != KC_LSFT ){ - unregister_mods(MOD_BIT(KC_LSFT)); - register_mods(MOD_BIT(LSPO_MOD)); - } - #endif - register_code(LSPO_KEY); - unregister_code(LSPO_KEY); - #ifndef DISABLE_SPACE_CADET_MODIFIER - if( LSPO_MOD != KC_LSFT ){ - unregister_mods(MOD_BIT(LSPO_MOD)); - } - #endif - } - unregister_mods(MOD_BIT(KC_LSFT)); - } - return false; - } - - case KC_RSPC: { - if (record->event.pressed) { - shift_interrupted[1] = false; - scs_timer[1] = timer_read (); - register_mods(MOD_BIT(KC_RSFT)); - } - else { - #ifdef DISABLE_SPACE_CADET_ROLLOVER - if (get_mods() & MOD_BIT(LSPO_MOD)) { - shift_interrupted[0] = true; - shift_interrupted[1] = true; - } - #endif - if (!shift_interrupted[1] && timer_elapsed(scs_timer[1]) < TAPPING_TERM) { - #ifdef DISABLE_SPACE_CADET_MODIFIER - unregister_mods(MOD_BIT(KC_RSFT)); - #else - if( RSPC_MOD != KC_RSFT ){ - unregister_mods(MOD_BIT(KC_RSFT)); - register_mods(MOD_BIT(RSPC_MOD)); - } - #endif - register_code(RSPC_KEY); - unregister_code(RSPC_KEY); - #ifndef DISABLE_SPACE_CADET_MODIFIER - if ( RSPC_MOD != KC_RSFT ){ - unregister_mods(MOD_BIT(RSPC_MOD)); - } - #endif - } - unregister_mods(MOD_BIT(KC_RSFT)); - } - return false; - } - - case KC_SFTENT: { - if (record->event.pressed) { - shift_interrupted[1] = false; - scs_timer[1] = timer_read (); - register_mods(MOD_BIT(KC_RSFT)); - } - else if (!shift_interrupted[1] && timer_elapsed(scs_timer[1]) < TAPPING_TERM) { - unregister_mods(MOD_BIT(KC_RSFT)); - register_code(SFTENT_KEY); - unregister_code(SFTENT_KEY); - } - else { - unregister_mods(MOD_BIT(KC_RSFT)); - } - return false; - } case GRAVE_ESC: { uint8_t shifted = get_mods() & ((MOD_BIT(KC_LSHIFT)|MOD_BIT(KC_RSHIFT) @@ -825,12 +714,6 @@ bool process_record_quantum(keyrecord_t *record) { return false; } #endif - - default: { - shift_interrupted[0] = true; - shift_interrupted[1] = true; - break; - } } return process_action_kb(record); diff --git a/quantum/quantum.h b/quantum/quantum.h index 987516dedb..ca9013e52e 100644 --- a/quantum/quantum.h +++ b/quantum/quantum.h @@ -131,6 +131,10 @@ extern uint32_t default_layer_state; #include "process_terminal_nop.h" #endif +#ifdef SPACE_CADET_ENABLE + #include "process_space_cadet.h" +#endif + #ifdef HD44780_ENABLE #include "hd44780.h" #endif diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h index fe2e3510d6..19bd7c2165 100644 --- a/quantum/quantum_keycodes.h +++ b/quantum/quantum_keycodes.h @@ -475,6 +475,18 @@ enum quantum_keycodes { HPT_DWLI, HPT_DWLD, + // Left control, open paren + KC_LCPO, + + // Right control, close paren + KC_RCPC, + + // Left control, open paren + KC_LAPO, + + // Right control, close paren + KC_RAPC, + // always leave at the end SAFE_RANGE }; diff --git a/tmk_core/common/chibios/suspend.c b/tmk_core/common/chibios/suspend.c index 4a119ccefe..6027d69b78 100644 --- a/tmk_core/common/chibios/suspend.c +++ b/tmk_core/common/chibios/suspend.c @@ -82,7 +82,7 @@ void suspend_wakeup_init_user(void) { } */ __attribute__ ((weak)) void suspend_wakeup_init_kb(void) { - suspend_power_down_user(); + suspend_wakeup_init_user(); } /** \brief suspend wakeup condition |