diff options
Diffstat (limited to 'qmk/keyboards/sofle_choc/keymaps')
18 files changed, 578 insertions, 183 deletions
diff --git a/qmk/keyboards/sofle_choc/keymaps/custom/callbacks.c b/qmk/keyboards/sofle_choc/keymaps/custom/callbacks.c new file mode 100644 index 0000000..305bacc --- /dev/null +++ b/qmk/keyboards/sofle_choc/keymaps/custom/callbacks.c @@ -0,0 +1,30 @@ +#include QMK_KEYBOARD_H +#include "star_key.h" +#include "lighting.h" +#include "enter_dance.h" +#include "shift_dance.h" +#include "keycodes.h" + +void keyboard_post_init_user(void) { + lighting_init(); + star_key_init(); +} + +void housekeeping_task_user(void) { + if (is_keyboard_master()) { + sync_star_key(); + } + housekeeping_task_lighting(); +} + +void oneshot_mods_changed_user(uint8_t mods) { + oneshot_mods_changed_lighting(mods); +} + +bool process_record_user(uint16_t keycode, keyrecord_t *record) { + star_key_process_record(keycode, record); + shift_dance_process_record(keycode, record); + enter_dance_process_record(keycode, record); + + return keycodes_process_record(keycode, record); +} diff --git a/qmk/keyboards/sofle_choc/keymaps/custom/config.h b/qmk/keyboards/sofle_choc/keymaps/custom/config.h index db8e644..310c993 100644 --- a/qmk/keyboards/sofle_choc/keymaps/custom/config.h +++ b/qmk/keyboards/sofle_choc/keymaps/custom/config.h @@ -22,18 +22,18 @@ // is the slave. // // I've found this helps with some ProMicros where the slave does not boot -#define SPLIT_USB_DETECT +#define EE_HANDS #define RGB_DISABLE_WHEN_USB_SUSPENDED // turn off effects when suspended #define SPLIT_TRANSPORT_MIRROR // If LED_MATRIX_KEYPRESSES or LED_MATRIX_KEYRELEASES is enabled, you also will want to enable SPLIT_TRANSPORT_MIRROR -#define RGB_MATRIX_MAXIMUM_BRIGHTNESS 150 // limits maximum brightness of LEDs (max 255). Higher may cause the controller to crash. +#define RGB_MATRIX_MAXIMUM_BRIGHTNESS 100 // limits maximum brightness of LEDs (max 255). Higher may cause the controller to crash. // Sets the default enabled state, if none has been set #define RGB_MATRIX_DEFAULT_ON true // Triggers RGB keypress events on key down. This makes RGB control feel more // responsive. This may cause RGB to not function properly on some boards -#define RGB_TRIGGER_ON_KEYDOWN +#define RGB_TRIGGER_ON_KEYDOWN // Disable the codes, don’t need them. #define RGB_MATRIX_DISABLE_KEYCODES @@ -41,7 +41,7 @@ #define ENABLE_RGB_MATRIX_BREATHING #define ENABLE_RGB_MATRIX_SOLID_COLOR #define ENABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE - // Sets the default mode, if none has been set +// Sets the default mode, if none has been set #define RGB_MATRIX_DEFAULT_MODE RGB_MATRIX_SOLID_REACTIVE_SIMPLE // Sync data between the two splits. This allow the leds to be in sync in the @@ -57,12 +57,9 @@ #define TAPPING_TERM 200 #define TAPPING_TERM_PER_KEY -// Modify the tap-hold configuration for helping with some tap-dance keys. -// The behavior with double-tap (like c/ç) and mod-tap is to wait the delay for -// the tap-dance before reporting the key to send. -// If I release the MOD-TAP key before, the modifier is not applied and the -// host receive a sequence of two keys, which is not what I want. -//#define PERMISSIVE_HOLD -//#define HOLD_ON_OTHER_KEY_PRESS - #define COMBO_MUST_PRESS_IN_ORDER + +// Prevent the keyboard to go to sleep and requiring a reboot +#define NO_SUSPEND_POWER_DOWN + +#define SPLIT_TRANSACTION_IDS_USER SET_STAR_KEY diff --git a/qmk/keyboards/sofle_choc/keymaps/custom/enter_dance.c b/qmk/keyboards/sofle_choc/keymaps/custom/enter_dance.c new file mode 100644 index 0000000..d5e0838 --- /dev/null +++ b/qmk/keyboards/sofle_choc/keymaps/custom/enter_dance.c @@ -0,0 +1,60 @@ +#include QMK_KEYBOARD_H +#include "quad_tapdance.h" +#include "enter_dance.h" + +static td_tap_t enter_tap_state = { + .state = TD_NONE +}; + +static bool inhibit_mod = 0; + +void enter_dance_process_record(uint16_t keycode, keyrecord_t *record) { + if (enter_tap_state.state == TD_SINGLE_HOLD && record->event.pressed) { + inhibit_mod = 1; + } + return; +} + +void enter_finished(tap_dance_state_t *state, void *user_data) { + enter_tap_state.state = cur_dance(state); + switch (enter_tap_state.state) { + case TD_SINGLE_HOLD: + if (get_oneshot_mods() & MOD_MASK_ALT) { + del_oneshot_mods(MOD_MASK_ALT); + //clear_oneshot_mods(); + inhibit_mod = 1; + } + register_code(KC_RIGHT_ALT); + break; + default: break; + } +} + +void enter_released(tap_dance_state_t *state, void *user_data) { + if (state->finished && state->count > 1) + // Exit prevently, we are sure in the next conditions we don’t fall in + // this case. + return; + else if (!state->finished) { + tap_code16(KC_ENTER); + reset_tap_dance(state); + } else if (!state->interrupted) { + // Final case, the key was keeped pressed without any other action + // in this case, active the one shot key for right alt + if (get_oneshot_mods() & MOD_MASK_ALT) { + del_oneshot_mods(MOD_MASK_ALT); + //clear_oneshot_mods(); + } else if (!inhibit_mod) { + set_oneshot_mods(MOD_BIT(KC_RIGHT_ALT)); + } + } + inhibit_mod = 0; +} + +void enter_reset(tap_dance_state_t *state, void *user_data) { + switch (enter_tap_state.state) { + case TD_SINGLE_HOLD: unregister_code(KC_RIGHT_ALT); break; + default: break; + } + enter_tap_state.state = TD_NONE; +} diff --git a/qmk/keyboards/sofle_choc/keymaps/custom/enter_dance.h b/qmk/keyboards/sofle_choc/keymaps/custom/enter_dance.h new file mode 100644 index 0000000..382e28d --- /dev/null +++ b/qmk/keyboards/sofle_choc/keymaps/custom/enter_dance.h @@ -0,0 +1,8 @@ +#pragma once +#include QMK_KEYBOARD_H + +void enter_released(tap_dance_state_t *state, void *user_data); +void enter_finished(tap_dance_state_t *state, void *user_data); +void enter_reset(tap_dance_state_t *state, void *user_data); + +void enter_dance_process_record(uint16_t keycode, keyrecord_t *record); diff --git a/qmk/keyboards/sofle_choc/keymaps/custom/keycodes.c b/qmk/keyboards/sofle_choc/keymaps/custom/keycodes.c index c21ba53..e82eed5 100644 --- a/qmk/keyboards/sofle_choc/keymaps/custom/keycodes.c +++ b/qmk/keyboards/sofle_choc/keymaps/custom/keycodes.c @@ -6,7 +6,7 @@ * Rules and modifier to apply over the keycodes. This includes the keys * redefinitions and the keys to include in the caps_word mecanism. * - * All thoses update are working over the custom keys declared in `keycodes.h` + * All thoses update are working over the custom keys declared in `keycodes.h` */ /* @@ -20,7 +20,6 @@ bool caps_word_press_user(uint16_t keycode) { case KC_A ... KC_Z: case KC_1 ... KC_0: case KC_MINS: - case KEY_C: // Add also the tapdance keys here. case KEY_W: case KEY_E: case BP_Z: // Additionals keys from the bepo layout. @@ -51,9 +50,8 @@ uint16_t get_tapping_term(uint16_t keycode, keyrecord_t *record) { case KEY_E: return 230; case KEY_W: - return 400; - case KEY_EE: - return 350; + case TD_ENTER: + return 2 * TAPPING_TERM; default: return TAPPING_TERM; } @@ -64,7 +62,7 @@ static uint32_t key_timer; // timer for last keyboard activity, use // idle time possible static uint16_t latest_key = 0L; -bool process_record_user(uint16_t keycode, keyrecord_t *record) { +bool keycodes_process_record(uint16_t keycode, keyrecord_t *record) { if (!record->event.pressed) { @@ -72,14 +70,10 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { // know if we are inside a typing sequence or not. key_timer = timer_read32(); latest_key = keycode; - } + } switch (keycode) { - case KC_LEFT_SHIFT: - if (host_keyboard_led_state().caps_lock) { - tap_code16(KC_CAPS_LOCK); - } - return true; + case KC_ESC: case AL_ENT: if (layer_state_is(LAYER_SYMBOLS) && !record->event.pressed) { // Remove the layer the key is released. @@ -87,7 +81,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { } return true; // If a key where released just before, consider we are typing some text - // and not starting a new sequence + // and not starting a new sequence case KEY_E: if (record->event.pressed && timer_elapsed32(key_timer) < TAPPING_TERM) { if (is_caps_word_on()) { @@ -106,19 +100,6 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { return false; } return true; - // Here, the key KC_BSPC become È when used inside a sequence, but we still - // allow the repetition of KC_BSPC. - case KC_BSPC: - if (record->event.pressed \ - && timer_elapsed32(key_timer) < (TAPPING_TERM / 2) \ - && latest_key != keycode) - { - // I completely rewrite the key here, that’s why I’m using tap_code16 - // instead of register_code. - tap_code16(BP_EGRV); - return false; - } - return true; // Override the key APP when hold into AltGR + Layer 1 when hold case KEY_APP: @@ -140,7 +121,9 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { layer_off(1); } return true; + default: return true; // Process all other keycodes normally } } + diff --git a/qmk/keyboards/sofle_choc/keymaps/custom/keycodes.h b/qmk/keyboards/sofle_choc/keymaps/custom/keycodes.h index 9bf6290..4142ed5 100644 --- a/qmk/keyboards/sofle_choc/keymaps/custom/keycodes.h +++ b/qmk/keyboards/sofle_choc/keymaps/custom/keycodes.h @@ -1,31 +1,40 @@ #pragma once +#include QMK_KEYBOARD_H +#include "action.h" enum { - // Custom key for defining the tapdance allowing to transform C into Ç - TD_C_CCED, // Transform the key W into SHIFT or CAPSLOCK TD_W_CAPSLOCK, // Transform the key E into È TD_EE, TD_PRC, TD_LAYER_SYMB, - TD_LSFT, + TD_ENTER, }; enum { LAYER_BASE, LAYER_SYMBOLS, - RIGHT_CTRL, + LAYER_DIACRITIC, }; #define MENU LGUI(BP_I) #define KEY_APP LT(0, KC_APP) -#define KEY_C TD(TD_C_CCED) #define KEY_W TD(TD_W_CAPSLOCK) #define KEY_PRC TD(TD_PRC) #define AL_ENT MT(MOD_RALT, KC_ENT) #define AL_SPC MT(MOD_LALT, KC_SPC) #define KEY_E MT(MOD_LCTL, BP_E) -#define KEY_EE TD(TD_EE) #define KEY_T MT(MOD_RCTL, BP_T) #define KEY_INS MT(MOD_RGUI, KC_INS) +#define TD_ENTR TD(TD_ENTER) + +// In the number layout, I keep the mod-tap modifiers applies to the middle +// letters : +// +#define KEY_6 MT(MOD_LCTL, KC_P6) +#define KEY_DOWN MT(MOD_RCTL, KC_DOWN) +#define KEY_PGDN MT(MOD_RSFT, KC_PGDN) + + +bool keycodes_process_record(uint16_t keycode, keyrecord_t *record); diff --git a/qmk/keyboards/sofle_choc/keymaps/custom/keymap.c b/qmk/keyboards/sofle_choc/keymaps/custom/keymap.c index b02567e..1755428 100644 --- a/qmk/keyboards/sofle_choc/keymaps/custom/keymap.c +++ b/qmk/keyboards/sofle_choc/keymaps/custom/keymap.c @@ -13,23 +13,45 @@ * 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 QMK_KEYBOARD_H +#include "keymap_common.h" +#include "quantum_keycodes.h" +#include "process_tap_dance.h" +#include "process_key_override.h" + #include "keymap_bepo.h" #include "keycodes.h" +#include "quad_tapdance.h" +#include "enter_dance.h" +#include "shift_dance.h" +#include "overrides.h" +#include QMK_KEYBOARD_H + +// Declare the tapdance table here. +// The functions for ACTION_TAP_DANCE_FN_ADVANCED or defined in "quand_dance" +tap_dance_action_t tap_dance_actions[] = { + [TD_PRC] = ACTION_TAP_DANCE_DOUBLE(BP_EQL, BP_PERC), + [TD_W_CAPSLOCK] = ACTION_TAP_DANCE_FN_ADVANCED_WITH_RELEASE(NULL, right_shift_released, right_shift_finished, right_shift_reset), + [TD_LAYER_SYMB] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, ql_finished, ql_reset), + [TD_EE] = ACTION_TAP_DANCE_DOUBLE(BP_COMM, BP_EGRV), + [TD_ENTER] = ACTION_TAP_DANCE_FN_ADVANCED_WITH_RELEASE(NULL, enter_released, enter_finished, enter_reset), +}; + -#define LY_SYMBOL TD(TD_LAYER_SYMB) +#define LY_SYMB TD(TD_LAYER_SYMB) +// Activate the layer just for a single key +#define LY_DIACRITIC OSL(LAYER_DIACRITIC) const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { /* * BÉPO * ,-----------------------------------------. ,-----------------------------------------. - * | ` | 1 | 2 | 3 | 4 | 5 | | 6 | 7 | 8 | 9 | 0 | `% | + * | ESC | 1 | 2 | 3 | 4 | 5 | | 6 | 7 | 8 | 9 | 0 | `% | * |------+------+------+------+------+------| |------+------+------+------+------+------| - * | ESC | B | É | P | O | È | | ! | V | D | L | J | Z | + * | $ | B | É | P | O | È | | ! | V | D | L | J | Z | * |------+------+------+------+------+------| |------+------+------+------+------+------| - * | Tab | A | U | I | E | ;È |-------. ,-------| CÇ | T | S | R | N | M | + * | Tab | A | U | I | E | ; |-------. ,-------| CÇ | T | S | R | N | M | * |------+------+------+------+------+------| Mute | | Pause |------+------+------+------+------+------| * |LShift| À | Y | X | : | K |-------| |-------| ? | Q | G | H | F | W | * `-----------------------------------------/ / \ \-----------------------------------------' @@ -40,30 +62,35 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { [LAYER_BASE] = LAYOUT( KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KEY_PRC, - BP_DLR, BP_B, BP_EACU, BP_P, BP_O, KC_BSPC, BP_DCIR, BP_V, BP_D, BP_L, BP_J, BP_Z, - KC_TAB, BP_A, BP_U, BP_I, KEY_E, KEY_EE, KEY_C, KEY_T, BP_S, BP_R, BP_N, BP_M, + BP_DLR, BP_B, BP_EACU, BP_P, BP_O, BP_EGRV, BP_DCIR, BP_V, BP_D, KC_O, BP_J, BP_Z, + KC_TAB, BP_A, BP_U, BP_I, KEY_E, BP_COMM, BP_C, KEY_T, BP_S, BP_R, BP_N, BP_M, KC_LSFT, BP_AGRV,BP_Y, BP_X, BP_DOT, KC_B, KC_MUTE, KC_MPLY,BP_QUOT, BP_Q, BP_G, BP_H, BP_F, KEY_W, - KC_LCTL, KC_DELETE,KC_LGUI,LY_SYMBOL,AL_SPC, AL_ENT, LY_SYMBOL,KEY_APP, KEY_INS, KC_RCTL + KC_LCTL, KC_DELETE,KC_LGUI,LY_SYMB, AL_SPC, TD_ENTR,LY_SYMB, KEY_APP, KEY_INS, LY_DIACRITIC ), -// In the number layout, I keep the mod-tap modifiers applies to the middle letters : -// -#define KEY_5 MT(MOD_LCTL, KC_P5) -#define KEY_DOWN MT(MOD_RCTL, KC_DOWN) // This layer is used to access to the numeric keypad, functions keys, and also provide some keys used with KC_LGUI [LAYER_SYMBOLS] = LAYOUT( - KC_ESC, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, - KC_NO, KC_NO, KC_P7, KC_P8, KC_P9, KC_TRNS, KC_HOME, KC_UP, KC_END, KC_TRNS, KC_NO, S(BP_EQL), - KC_TAB, KC_NO, KC_P4, KEY_5, KC_P6, KC_NO, KC_LEFT, KEY_DOWN, KC_RIGHT,BP_R, BP_N, KC_PGUP, - KC_LSFT, KC_NO, KC_P1, KC_P2, KC_P3, KC_NO, KC_MUTE, KC_MPLY,KC_PGUP, KC_TRNS, KC_PGDN, KC_TRNS, BP_F, KC_PGDN, - KC_P0, KC_PDOT, KC_TRNS, LY_SYMBOL,AL_SPC, AL_ENT, LY_SYMBOL,KC_TRNS, KC_RGUI, KC_TRNS + KC_TRNS, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, + KC_TRNS, KC_TRNS, KC_P7, KC_P8, KC_P9, KC_BSPC, KC_HOME, KC_UP, KC_END, KC_TRNS, KC_TRNS, S(BP_EQL), + KC_TRNS, KC_TRNS, KC_P4, KC_P5, KEY_6, KC_TRNS, KC_LEFT, KC_DOWN, KC_RIGHT,KC_TRNS, KC_TRNS, KC_PGUP, + KC_LSFT, KC_TRNS, KC_P1, KC_P2, KC_P3, KC_TRNS, KC_MUTE, KC_MPLY, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KEY_PGDN, + KC_P0, KC_PDOT, KC_TRNS, KC_TRNS, AL_SPC, AL_ENT, KC_TRNS, KC_TRNS, KC_RGUI, KC_TRNS +), + +[LAYER_DIACRITIC] = LAYOUT( + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, BP_PERC, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_BSPC, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, BP_CCED, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS ), }; #if defined(ENCODER_MAP_ENABLE) const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][NUM_DIRECTIONS] = { - [LAYER_BASE] = { ENCODER_CCW_CW(KC_VOLD, KC_VOLU), ENCODER_CCW_CW(KC_MS_WH_UP, KC_MS_WH_DOWN) }, - [LAYER_SYMBOLS] = { ENCODER_CCW_CW(KC_TRNS, KC_TRNS), ENCODER_CCW_CW(KC_TRNS, KC_TRNS) }, + [LAYER_BASE] = { ENCODER_CCW_CW(KC_VOLD, KC_VOLU), ENCODER_CCW_CW(QK_MOUSE_WHEEL_UP, QK_MOUSE_WHEEL_DOWN) }, + [LAYER_SYMBOLS] = { ENCODER_CCW_CW(KC_TRNS, KC_TRNS), ENCODER_CCW_CW(KC_TRNS, KC_TRNS) }, + [LAYER_DIACRITIC] = { ENCODER_CCW_CW(KC_TRNS, KC_TRNS), ENCODER_CCW_CW(KC_TRNS, KC_TRNS) }, }; #endif diff --git a/qmk/keyboards/sofle_choc/keymaps/custom/lighting.c b/qmk/keyboards/sofle_choc/keymaps/custom/lighting.c new file mode 100644 index 0000000..5617837 --- /dev/null +++ b/qmk/keyboards/sofle_choc/keymaps/custom/lighting.c @@ -0,0 +1,156 @@ +#include QMK_KEYBOARD_H + uint8_t flags = 0; +#include "keycodes.h" +#include "lighting.h" +#include "keymap_bepo.h" + +// The variable is defined in star_key.h +// The LED is on when the key is pressed. +extern bool is_star; + +// Set the color at the given position, but limit the intensity +void set_color(uint8_t index, uint8_t h, uint8_t s, uint8_t _) { + HSV hsv = {h, s, RGB_MATRIX_MAXIMUM_BRIGHTNESS}; + RGB rgb = hsv_to_rgb(hsv); + rgb_matrix_set_color(index, rgb.r, rgb.g, rgb.b); +} + +HSV hsv_of_color(uint8_t h, uint8_t s, uint8_t v) { + return (HSV){h, s, v > 100 ? 100:v}; +} + +void lighting_init(void) { + rgb_matrix_sethsv_noeeprom(HSV_WHITE); + rgb_matrix_mode_noeeprom(RGB_MATRIX_SOLID_REACTIVE_SIMPLE); +} + + +static uint8_t last_flags; +static bool one_shot_alt_flag = 0; + +void oneshot_mods_changed_lighting(uint8_t mods) { + one_shot_alt_flag = mods & MOD_MASK_ALT; +} + +void housekeeping_task_lighting(void) { + + // Colors for the mods + HSV const colors[] = { + hsv_of_color(HSV_BLACK), // 000 + hsv_of_color(55, 255, 255),// 001 + hsv_of_color(HSV_RED), // 010 + hsv_of_color(HSV_ORANGE),// 011 + hsv_of_color(HSV_CYAN), // 100 + hsv_of_color(HSV_GREEN), // 101 + hsv_of_color(HSV_PURPLE),// 110 + hsv_of_color(HSV_WHITE), // 111 + }; + + uint8_t counter = 0; + uint8_t flags = 0; + if (get_mods() & MOD_MASK_CTRL) { + flags |= 0b001; + counter += 1; + } + if (one_shot_alt_flag || (get_mods() & MOD_MASK_ALT)) { + flags |= 0b010; + counter += 1; + } + if ((get_mods() & MOD_MASK_SHIFT) || host_keyboard_led_state().caps_lock) { + flags |= 0b100; + counter += 1; + } + + uint8_t matrix_mode = rgb_matrix_get_mode(); + if (matrix_mode != RGB_MATRIX_BREATHING && host_keyboard_led_state().caps_lock) { + rgb_matrix_mode_noeeprom(RGB_MATRIX_BREATHING); + } + + if (flags == last_flags) { + return; + } + last_flags = flags; + + if (flags) { + if (matrix_mode != RGB_MATRIX_SOLID_COLOR) { + rgb_matrix_mode_noeeprom(RGB_MATRIX_SOLID_COLOR); + } + uint8_t v = colors[flags].v; + if (counter >= 2) + v *= 2; + rgb_matrix_sethsv_noeeprom(colors[flags].h, colors[flags].s, v); + } else if (matrix_mode != RGB_MATRIX_SOLID_REACTIVE_SIMPLE) { + rgb_matrix_sethsv_noeeprom(HSV_WHITE); + rgb_matrix_mode_noeeprom(RGB_MATRIX_SOLID_REACTIVE_SIMPLE); + } +} + +#define KEY_6 MT(MOD_LCTL, KC_P6) +#define KEY_DOWN MT(MOD_RCTL, KC_DOWN) +bool rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) { + // Activate effects depending of mods + + if (is_caps_word_on()) { + if (rgb_matrix_get_mode() != RGB_MATRIX_BREATHING) { + rgb_matrix_mode_noeeprom(RGB_MATRIX_BREATHING); + } + rgb_matrix_sethsv_noeeprom(HSV_SPRINGGREEN); + return false; + } + + for (uint8_t row = 0; row < MATRIX_ROWS; ++row) { + for (uint8_t col = 0; col < MATRIX_COLS; ++col) { + uint8_t index = g_led_config.matrix_co[row][col]; + + if (index < led_min || index > led_max || index == NO_LED) + continue; + + uint8_t layer = layer_switch_get_layer((keypos_t){col,row}); + uint16_t keycode = keymap_key_to_keycode(layer, (keypos_t){col,row}); + + if (keycode == KC_O && is_star) { + rgb_matrix_set_color(index, 100, 100, 0); + } + + if (layer == 0) + continue; + + + switch (keycode) { + case KC_F1 ... KC_F11: + rgb_matrix_set_color(index, 128, 128, 128); + break; + case KC_P1 ... KC_P0: + case KEY_6: + rgb_matrix_set_color(index, 100, 100, 0); + break; + case BP_CCED: + case BP_PERC: + case KC_PDOT: + // Add a bit of red for the punction symbol + rgb_matrix_set_color(index, 150, 50, 0); + break; + case KC_RIGHT: + case KEY_DOWN: + case KC_LEFT ... KC_UP: + case KC_PGUP: + case KC_PGDN: + case KEY_PGDN: + rgb_matrix_set_color(index, 32, 32, 128); + break; + case KC_HOME: + case KC_END: + rgb_matrix_set_color(index, RGB_SPRINGGREEN); + break; + case KC_BSPC: + case AL_SPC: + case AL_ENT: + set_color(index, HSV_BLUE); + break; + + } + } + } + + return false; +} diff --git a/qmk/keyboards/sofle_choc/keymaps/custom/lighting.h b/qmk/keyboards/sofle_choc/keymaps/custom/lighting.h new file mode 100644 index 0000000..a66e329 --- /dev/null +++ b/qmk/keyboards/sofle_choc/keymaps/custom/lighting.h @@ -0,0 +1,8 @@ +#pragma once + +// Callback for one_shot_modifier +void oneshot_mods_changed_lighting(uint8_t mods); + +void lighting_init(void); + +void housekeeping_task_lighting(void); diff --git a/qmk/keyboards/sofle_choc/keymaps/custom/overrides.c b/qmk/keyboards/sofle_choc/keymaps/custom/overrides.c index a99582a..0181903 100644 --- a/qmk/keyboards/sofle_choc/keymaps/custom/overrides.c +++ b/qmk/keyboards/sofle_choc/keymaps/custom/overrides.c @@ -6,40 +6,8 @@ // Override the symbol ° and replace it by ` // The symbol is still available in the symbol layer with the key just below. // -const key_override_t perc_key_override = +const key_override_t perc_key_override = ko_make_basic(MOD_MASK_SHIFT, KEY_PRC, LSFT(BP_PERC)); -// -// I don’t care of the mapping CTRL+Ç and using the mod_tap does not work well -// when I type too fast because of tap-dance, so I remap the pattern here. -// -const key_override_t c_key_override = - ko_make_basic(MOD_MASK_CTRL, KEY_C, LCTL(BP_C)); - -// Same here, I want to be able to type '' without triggering the tapdance. -// And there is no such key combo for Alt+È. -const key_override_t quote_key_override = - ko_make_basic(MOD_MASK_ALT, KEY_EE, RALT(BP_COMM)); - -// Same here, I override the key W with CTRL because the tapdance activate the -// caps_word which does not make sense here. -const key_override_t w_key_override = - ko_make_basic(MOD_MASK_CTRL, KEY_W, LCTL(BP_W)); - -const key_override_t e_key_override = +const key_override_t e_key_override = ko_make_basic(MOD_MASK_CTRL, KEY_E, RCTL(BP_E)); - -// This globally defines all key overrides to be used -const key_override_t **key_overrides = (const key_override_t *[]){ - &perc_key_override, - &c_key_override, - &w_key_override, - &e_key_override, - "e_key_override, - // Override the key GUI + MENU and to map the key desktop from the - // typematrix - &(ko_make_basic(MOD_MASK_GUI, KEY_APP, MENU)), - - - NULL -}; diff --git a/qmk/keyboards/sofle_choc/keymaps/custom/overrides.h b/qmk/keyboards/sofle_choc/keymaps/custom/overrides.h new file mode 100644 index 0000000..79836d4 --- /dev/null +++ b/qmk/keyboards/sofle_choc/keymaps/custom/overrides.h @@ -0,0 +1,30 @@ +#pragma once + +#include "keymap_bepo.h" +#include "keycodes.h" + +// +// Override the symbol ° and replace it by ` +// The symbol is still available in the symbol layer with the key just below. +// +const key_override_t perc_key_override ; + +// +// I don’t care of the mapping CTRL+Ç and using the mod_tap does not work well +// when I type too fast because of tap-dance, so I remap the pattern here. +// +//const key_override_t c_key_override ; + +const key_override_t e_key_override ; + +// This globally defines all key overrides to be used +const key_override_t *key_overrides[]= (const key_override_t *[]){ + &perc_key_override, + &e_key_override, + // Override the key GUI + MENU and to map the key desktop from the + // typematrix + &(ko_make_basic(MOD_MASK_GUI, KEY_APP, MENU)), + + + NULL +}; diff --git a/qmk/keyboards/sofle_choc/keymaps/custom/quad_tapdance.c b/qmk/keyboards/sofle_choc/keymaps/custom/quad_tapdance.c index de54aa7..2b01fe9 100644 --- a/qmk/keyboards/sofle_choc/keymaps/custom/quad_tapdance.c +++ b/qmk/keyboards/sofle_choc/keymaps/custom/quad_tapdance.c @@ -34,86 +34,39 @@ td_state_t cur_dance(tap_dance_state_t *state) { if (state->count == 1) { // The function can be called when the delay is over, or because of - // another tap. + // another tap. // I do not check here if the delay is over, as soon as another tap // occurs, I check the state of the key and switch in hold mode if the // key is still pressed. // if (!state->pressed) return TD_SINGLE_TAP; - // Key has not been interrupted, but the key is still held. Means you want to send a 'HOLD'. + // Key has not been interrupted, but the key is still held. + // Means you want to send a 'HOLD'. else return TD_SINGLE_HOLD; } else if (state->count == 2) { - // TD_DOUBLE_SINGLE_TAP is to distinguish between typing "pepper", and actually wanting a double tap - // action when hitting 'pp'. Suggested use case for this return value is when you want to send two + // TD_DOUBLE_SINGLE_TAP is to distinguish between typing "pepper", + // and actually wanting a double tap + // action when hitting 'pp'. Suggested use case for this return value + // is when you want to send two // keystrokes of the key, and not the 'double tap' action/macro. if (state->interrupted) return TD_DOUBLE_SINGLE_TAP; else if (state->pressed) return TD_DOUBLE_HOLD; else return TD_DOUBLE_TAP; - } - - // Assumes no one is trying to type the same letter three times (at least not quickly). - // If your tap dance key is 'KC_W', and you want to type "www." quickly - then you will need to add - // an exception here to return a 'TD_TRIPLE_SINGLE_TAP', and define that enum just like 'TD_DOUBLE_SINGLE_TAP' - if (state->count == 3) { - if (state->interrupted || !state->pressed) return TD_TRIPLE_TAP; - else return TD_TRIPLE_HOLD; } else return TD_UNKNOWN; } // -// Definition for the key W. -// -// The main usage is to send the letter W when pressed, but the key is also -// used to activate the SHIFT mode when pressed. -// -// If the key is double tapped, it will also switch into the caps_word mode. -// - -static td_tap_t w_tap_state = { - .is_press_action = true, - .state = TD_NONE -}; - -void w_finished(tap_dance_state_t *state, void *user_data) { - w_tap_state.state = cur_dance(state); - switch (w_tap_state.state) { - case TD_SINGLE_TAP: - register_code(BP_W); break; - case TD_DOUBLE_TAP: - case TD_DOUBLE_SINGLE_TAP: - caps_word_on(); - break; - case TD_SINGLE_HOLD: - case TD_DOUBLE_HOLD: - caps_word_off(); - register_code(KC_RIGHT_SHIFT); - break; - default: break; - } -} - -void w_reset(tap_dance_state_t *state, void *user_data) { - switch (w_tap_state.state) { - case TD_SINGLE_TAP: unregister_code(BP_W); break; - case TD_SINGLE_HOLD: unregister_code(KC_RIGHT_SHIFT); break; - case TD_DOUBLE_SINGLE_TAP: unregister_code(BP_W); break; - default: break; - } - w_tap_state.state = TD_NONE; -} - -// // Definition for the layer key // // The only one usage is to activate the layer over the keyboard, but there is // two way of doing it: // -// The first mode, when hold, is to activate the layer as long as the key is pressed. -// The second one is to switch in the layer mode when double tapped, in this -// mode, you can go back into the normal layer by a single press on the key. +// The first mode, when hold, is to activate the layer as long as the key is +// pressed. +// The second one is to switch in the layer mode when tapped, in this mode, +// you can go back into the normal layer by a single press on the key. // static td_tap_t ql_tap_state = { - .is_press_action = true, .state = TD_NONE }; @@ -121,11 +74,10 @@ static td_tap_t ql_tap_state = { void ql_finished(tap_dance_state_t *state, void *user_data) { ql_tap_state.state = cur_dance(state); switch (ql_tap_state.state) { - // Remove the layer with a single tap, this way I always have a key to remove the - // the layer, without knowing the previous state I had. - case TD_SINGLE_TAP: layer_off(LAYER_SYMBOLS); break; + // Remove the layer with a single tap, this way I always have a key to + // remove the the layer, without knowing the previous state I had. + case TD_SINGLE_TAP: layer_invert(LAYER_SYMBOLS); break; case TD_SINGLE_HOLD: layer_on(LAYER_SYMBOLS); break; - case TD_DOUBLE_TAP: layer_invert(LAYER_SYMBOLS); break; default: break; } } @@ -133,19 +85,7 @@ void ql_finished(tap_dance_state_t *state, void *user_data) { void ql_reset(tap_dance_state_t *state, void *user_data) { // If the key was held down and now is released then switch off the layer if (ql_tap_state.state == TD_SINGLE_HOLD) { - layer_off(LAYER_SYMBOLS); + layer_clear(); } ql_tap_state.state = TD_NONE; } - -// -// Declare the tapdance table here. -// -tap_dance_action_t tap_dance_actions[] = { - [TD_C_CCED] = ACTION_TAP_DANCE_DOUBLE(BP_C, BP_CCED), - [TD_PRC] = ACTION_TAP_DANCE_DOUBLE(BP_EQL, BP_PERC), - [TD_W_CAPSLOCK] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, w_finished, w_reset), - [TD_LAYER_SYMB] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, ql_finished, ql_reset), - [TD_EE] = ACTION_TAP_DANCE_DOUBLE(BP_COMM, BP_EGRV), -}; - diff --git a/qmk/keyboards/sofle_choc/keymaps/custom/quad_tapdance.h b/qmk/keyboards/sofle_choc/keymaps/custom/quad_tapdance.h index 87da433..8f2770c 100644 --- a/qmk/keyboards/sofle_choc/keymaps/custom/quad_tapdance.h +++ b/qmk/keyboards/sofle_choc/keymaps/custom/quad_tapdance.h @@ -1,5 +1,8 @@ #pragma once +#include "keymap_bepo.h" +#include "keycodes.h" + typedef enum { TD_NONE, TD_UNKNOWN, @@ -8,23 +11,13 @@ typedef enum { TD_DOUBLE_TAP, TD_DOUBLE_HOLD, TD_DOUBLE_SINGLE_TAP, // Send two single taps - TD_TRIPLE_TAP, - TD_TRIPLE_HOLD } td_state_t; typedef struct { - bool is_press_action; td_state_t state; } td_tap_t; td_state_t cur_dance(tap_dance_state_t *state); -// For the x tap dance. Put it here so it can be used in any keymap -void w_finished(tap_dance_state_t *state, void *user_data); -void w_reset(tap_dance_state_t *state, void *user_data); - void ql_finished(tap_dance_state_t *state, void *user_data); void ql_reset(tap_dance_state_t *state, void *user_data); - -void lshift_finished(tap_dance_state_t *state, void *user_data); -void lshift_reset(tap_dance_state_t *state, void *user_data); diff --git a/qmk/keyboards/sofle_choc/keymaps/custom/rules.mk b/qmk/keyboards/sofle_choc/keymaps/custom/rules.mk index 2703553..90eda0e 100644 --- a/qmk/keyboards/sofle_choc/keymaps/custom/rules.mk +++ b/qmk/keyboards/sofle_choc/keymaps/custom/rules.mk @@ -8,5 +8,14 @@ BACKLIGHT_ENABLE = no RGB_MATRIX_ENABLE = yes RGB_MATRIX_DRIVER = ws2812 +MOUSEKEY_ENABLE = yes -SRC += quad_tapdance.c keycodes.c overrides.c lighting.c +CONVERT_TO=rp2040_ce +SRC += star_key.c \ + quad_tapdance.c \ + enter_dance.c \ + shift_dance.c \ + keycodes.c \ + overrides.c \ + lighting.c \ + callbacks.c diff --git a/qmk/keyboards/sofle_choc/keymaps/custom/shift_dance.c b/qmk/keyboards/sofle_choc/keymaps/custom/shift_dance.c new file mode 100644 index 0000000..403c3df --- /dev/null +++ b/qmk/keyboards/sofle_choc/keymaps/custom/shift_dance.c @@ -0,0 +1,93 @@ +#include QMK_KEYBOARD_H +#include "keymap_bepo.h" +#include "quad_tapdance.h" +#include "shift_dance.h" +// +// Definition for the key W. +// +// The main usage is to send the letter W when pressed, but the key is also +// used to activate the SHIFT mode when pressed. +// +static td_tap_t right_shift_tap_state = { + .state = TD_NONE +}; + +// Do not switch the supended mode when the key is released. +// This allow to remove the mod earler without reactivating automatically. +static bool inhibit_mod = 0; +static bool lshift_interrupted = 0; + +// If there is any other keypress before releasing the key, do not keep the +// layer once the key is release. +// +// This function is a callbackk called from process_record_user +void shift_dance_process_record(uint16_t keycode, keyrecord_t *record) { + if (right_shift_tap_state.state == TD_SINGLE_HOLD && record->event.pressed) { + // If there is any key pressed while holding the key, do not switch + // in caps lock mod on release. + inhibit_mod = 1; + } + switch (keycode) { + // If the key is pressed without any other combination, remove the + // caps lock if activated. + // Otherwise, act just as a modifier key. + case KC_LSFT: + if (record->event.pressed) { + lshift_interrupted = 0; + break; + } + if (lshift_interrupted) { + break; + } + // Continue on the next block + case KC_ESC: + if (host_keyboard_led_state().caps_lock) { + tap_code16(KC_CAPS_LOCK); + } + break; + default: + lshift_interrupted = 1; + break; + } + return; +} + +void right_shift_finished(tap_dance_state_t *state, void *user_data) { + right_shift_tap_state.state = cur_dance(state); + switch (right_shift_tap_state.state) { + case TD_SINGLE_HOLD: + if (get_mods() & MOD_MASK_SHIFT) { + del_mods(MOD_MASK_SHIFT); + inhibit_mod = 1; + } + register_code(KC_RIGHT_SHIFT); + break; + default: break; + } +} + +void right_shift_released(tap_dance_state_t *state, void *user_data) { + if (state->finished && state->count > 1) + // Exit prevently, we are sure in the next conditions we don’t fall in + // this case. + return; + else if (!state->finished) + tap_code16(BP_W); + else if (!state->interrupted && !inhibit_mod) { + // Final case, the key was keeped pressed without any other action + // in this case, switch into CAPS LOCK + del_mods(MOD_MASK_SHIFT); + tap_code16(KC_CAPS_LOCK); + } + inhibit_mod = 0; +} + +void right_shift_reset(tap_dance_state_t *state, void *user_data) { + switch (right_shift_tap_state.state) { + case TD_SINGLE_HOLD: + unregister_code(KC_RIGHT_SHIFT); + break; + default: break; + } + right_shift_tap_state.state = TD_NONE; +} diff --git a/qmk/keyboards/sofle_choc/keymaps/custom/shift_dance.h b/qmk/keyboards/sofle_choc/keymaps/custom/shift_dance.h new file mode 100644 index 0000000..4eb7799 --- /dev/null +++ b/qmk/keyboards/sofle_choc/keymaps/custom/shift_dance.h @@ -0,0 +1,13 @@ +#pragma once +#include QMK_KEYBOARD_H + + +// For the x tap dance. Put it here so it can be used in any keymap +void right_shift_released(tap_dance_state_t *state, void *user_data); +void right_shift_finished(tap_dance_state_t *state, void *user_data); +void right_shift_reset(tap_dance_state_t *state, void *user_data); + + +void shift_dance_process_record(uint16_t keycode, keyrecord_t *record); +const key_override_t shift_space_override; +const key_override_t shift_o_override; diff --git a/qmk/keyboards/sofle_choc/keymaps/custom/star_key.c b/qmk/keyboards/sofle_choc/keymaps/custom/star_key.c new file mode 100644 index 0000000..03ce6b5 --- /dev/null +++ b/qmk/keyboards/sofle_choc/keymaps/custom/star_key.c @@ -0,0 +1,57 @@ +#include QMK_KEYBOARD_H +#include "transactions.h" +#include "star_key.h" + +typedef struct _master_to_slave_t { + int is_star; +} master_to_slave_t; + + +bool is_star = 0; +static bool is_synced = 1; + +// Handler for the slave, receive the star information +void user_sync_a_slave_handler(uint8_t in_buflen, const void* in_data, uint8_t out_buflen, void* out_data) { + const master_to_slave_t *m2s = (const master_to_slave_t*)in_data; + is_star = m2s->is_star; +} + +void star_key_init(void) { + if (!is_keyboard_master()) { + transaction_register_rpc(SET_STAR_KEY, user_sync_a_slave_handler); + } +} + +void sync_star_key(void) { + if (!is_synced) { + // Send the state to the other side of the keyboard + master_to_slave_t m2s = { is_star }; + is_synced = transaction_rpc_send(SET_STAR_KEY, sizeof(m2s), &m2s); + } +} +static uint8_t star_number = 0; +#define LY_SYMB TD(TD_LAYER_SYMB) +void star_key_process_record(uint16_t keycode, keyrecord_t *record) { + switch (keycode) { + case KC_O: + star_number = (star_number + 1) % 3; + if (star_number != 0 && is_star == 0) { + is_star = 1; + is_synced = 0; + } else if (star_number == 0) { + is_star = 0; + is_synced = 0; + } + return; + case LY_SYMB: + // Ignore the layer events + return; + default: + if (star_number != 0) { + star_number = 0; + is_star = 0; + is_synced = 0; + } + return; // Process all other keycodes normally + } +} diff --git a/qmk/keyboards/sofle_choc/keymaps/custom/star_key.h b/qmk/keyboards/sofle_choc/keymaps/custom/star_key.h new file mode 100644 index 0000000..a91d0a3 --- /dev/null +++ b/qmk/keyboards/sofle_choc/keymaps/custom/star_key.h @@ -0,0 +1,14 @@ +#pragma once +#include QMK_KEYBOARD_H +#include "action.h" + +// Initialize the state. +void star_key_init(void); + +// This code is intended to be called from the master. +// Send the star key status to the other side of the keyboard +void sync_star_key(void); + +// Handle the keypress, turn the light on until the next press, or revert off +// after a cycle of 3 presses. +void star_key_process_record(uint16_t keycode, keyrecord_t *record); |
