From 0382a25e3535c1067bb31faac63ac5fc82132b72 Mon Sep 17 00:00:00 2001 From: Paulo Pereira Date: Wed, 12 Apr 2023 20:28:26 +0100 Subject: [Keymap] Add paulomp90 lily58 keymap (#20327) Co-authored-by: Drashna Jaelre --- keyboards/lily58/keymaps/paulomp90/config.h | 22 ++ .../keymaps/paulomp90/features/custom_shift_keys.c | 67 ++++++ .../keymaps/paulomp90/features/custom_shift_keys.h | 29 +++ keyboards/lily58/keymaps/paulomp90/keymap.c | 264 +++++++++++++++++++++ keyboards/lily58/keymaps/paulomp90/readme.md | 10 + keyboards/lily58/keymaps/paulomp90/rules.mk | 14 ++ 6 files changed, 406 insertions(+) create mode 100644 keyboards/lily58/keymaps/paulomp90/config.h create mode 100644 keyboards/lily58/keymaps/paulomp90/features/custom_shift_keys.c create mode 100644 keyboards/lily58/keymaps/paulomp90/features/custom_shift_keys.h create mode 100644 keyboards/lily58/keymaps/paulomp90/keymap.c create mode 100644 keyboards/lily58/keymaps/paulomp90/readme.md create mode 100644 keyboards/lily58/keymaps/paulomp90/rules.mk (limited to 'keyboards') diff --git a/keyboards/lily58/keymaps/paulomp90/config.h b/keyboards/lily58/keymaps/paulomp90/config.h new file mode 100644 index 0000000000..b2cfbdd69c --- /dev/null +++ b/keyboards/lily58/keymaps/paulomp90/config.h @@ -0,0 +1,22 @@ +/* Copyright 2023 Paulo Pereira + * + * 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 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + + +#define QUICK_TAP_TERM 0 +#define TAPPING_TERM 150 +#define TAP_CODE_DELAY 10 \ No newline at end of file diff --git a/keyboards/lily58/keymaps/paulomp90/features/custom_shift_keys.c b/keyboards/lily58/keymaps/paulomp90/features/custom_shift_keys.c new file mode 100644 index 0000000000..f2e091c0b9 --- /dev/null +++ b/keyboards/lily58/keymaps/paulomp90/features/custom_shift_keys.c @@ -0,0 +1,67 @@ +/* Copyright 2023 Paulo Pereira + * + * 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 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "custom_shift_keys.h" + +bool process_custom_shift_keys(uint16_t keycode, keyrecord_t *record) { + static uint16_t registered_keycode = KC_NO; + + // If a custom shift key is registered, then this event is either + // releasing it or manipulating another key at the same time. Either way, + // we release the currently registered key. + if (registered_keycode != KC_NO) { + unregister_code16(registered_keycode); + registered_keycode = KC_NO; + } + + if (record->event.pressed) { // Press event. + const uint8_t mods = get_mods(); +#ifndef NO_ACTION_ONESHOT + if ((mods | get_weak_mods() | get_oneshot_mods()) & MOD_MASK_SHIFT) { +#else + if ((mods | get_weak_mods()) & MOD_MASK_SHIFT) { // Shift is held. +#endif // NO_ACTION_ONESHOT + // Continue default handling if this is a tap-hold key being held. + if ((IS_QK_MOD_TAP(keycode) || IS_QK_LAYER_TAP(keycode)) && + record->tap.count == 0) { + return true; + } + + // Search for a custom shift key whose keycode is `keycode`. + for (int i = 0; i < NUM_CUSTOM_SHIFT_KEYS; ++i) { + if (keycode == custom_shift_keys[i].keycode) { + registered_keycode = custom_shift_keys[i].shifted_keycode; + if (IS_QK_MODS(registered_keycode) && // Should key be shifted? + (QK_MODS_GET_MODS(registered_keycode) & MOD_LSFT) != 0) { + register_code16(registered_keycode); // If so, press directly. + } else { + // If not, cancel shift mods, press the key, and restore mods. + del_weak_mods(MOD_MASK_SHIFT); +#ifndef NO_ACTION_ONESHOT + del_oneshot_mods(MOD_MASK_SHIFT); +#endif // NO_ACTION_ONESHOT + unregister_mods(MOD_MASK_SHIFT); + register_code16(registered_keycode); + set_mods(mods); + } + return false; + } + } + } + } + + return true; // Continue with default handling. +} diff --git a/keyboards/lily58/keymaps/paulomp90/features/custom_shift_keys.h b/keyboards/lily58/keymaps/paulomp90/features/custom_shift_keys.h new file mode 100644 index 0000000000..2097f2bb7e --- /dev/null +++ b/keyboards/lily58/keymaps/paulomp90/features/custom_shift_keys.h @@ -0,0 +1,29 @@ +/* Copyright 2023 Paulo Pereira + * + * 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 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +#pragma once +#include QMK_KEYBOARD_H + +typedef struct { + uint16_t keycode; + uint16_t shifted_keycode; +} custom_shift_key_t; + +extern const custom_shift_key_t custom_shift_keys[]; +extern uint8_t NUM_CUSTOM_SHIFT_KEYS; + +bool process_custom_shift_keys(uint16_t keycode, keyrecord_t *record); \ No newline at end of file diff --git a/keyboards/lily58/keymaps/paulomp90/keymap.c b/keyboards/lily58/keymaps/paulomp90/keymap.c new file mode 100644 index 0000000000..af0fafb337 --- /dev/null +++ b/keyboards/lily58/keymaps/paulomp90/keymap.c @@ -0,0 +1,264 @@ +/* Copyright 2023 Paulo Pereira + * + * 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 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include QMK_KEYBOARD_H +#include "keymap_portuguese.h" +#include "features/custom_shift_keys.h" + +enum layer_number { + _QWERTY = 0, + _LOWER, + _RAISE, + _ADJUST, +}; + +/* tap dance shifts */ +typedef struct { + bool is_press_action; + int state; +} tap; + +typedef enum { + TD_NONE, + TD_UNKNOWN, + TD_SINGLE_TAP, + TD_SINGLE_HOLD, + TD_DOUBLE_TAP +} td_state_t; + +enum { LEFT_SHIFT = 0, RIGHT_SHIFT = 1 }; + +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + + /* QWERTY + * ,-----------------------------------------. ,-----------------------------------------. + * | ESC | 1 | 2 | 3 | 4 | 5 | | 6 | 7 | 8 | 9 | 0 | '? | + * |------+------+------+------+------+------| |------+------+------+------+------+------| + * | Tab | Q | W | E | R | T | | Y | U | I | O | P | +* | + * |------+------+------+------+------+------| |------+------+------+------+------+------| + * |LShift| A | S | D | F | G |-------. ,-------| H | J | K | L | Ç | BACK | + * |------+------+------+------+------+------| <> | | ´` |------+------+------+------+------+------| + * |LCTRL | Z | X | C | V | B |-------| |-------| N | M | ,; | .: | _- |Shift| + * `-----------------------------------------/ / \ \-----------------------------------------' + * | LAlt | LGUI |LOWER | /Space / \Enter \ |RAISE | RGUI | RAlt | + * | | | |/ / \ \ | | | | + * `-------------------''-------' '------''--------------------' + */ + [_QWERTY] = LAYOUT( + KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, + KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_EQL, + TD(LEFT_SHIFT), KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_BSPC, + KC_LCTL, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_GRV, KC_RBRC, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, TD(RIGHT_SHIFT), + KC_LALT, KC_LGUI, TL_LOWR, KC_SPC, KC_ENT, TL_UPPR, KC_RGUI, KC_RALT + ), + + /* LOWER + * ,-----------------------------------------. ,-----------------------------------------. + * | | F2 | F3 | F4 | F5 | F6 | | F7 | F8 | F9 | F10 | F11 | | + * |------+------+------+------+------+------| |------+------+------+------+------+------| + * | F1 | | | | | | | PgUp | HOME | Up | END | ºª | F12 | + * |------+------+------+------+------+------| |------+------+------+------+------+------| + * | | | | | | |-------. ,-------| PgDn | Left | Down |Right | ~^ | DEL | + * |------+------+------+------+------+------| <> | | ´` |------+------+------+------+------+------| + * | | | | << | >|| | >> |-------| |-------| | Vol+ | Vol- | Mute | \| | | + * `-----------------------------------------/ / \ \-----------------------------------------' + * | LAlt | LGUI |LOWER | /Space / \Enter \ |RAISE | RGUI | RAlt | + * | | | |/ / \ \ | | | | + * `-------------------''-------' '------''--------------------' + */ + [_LOWER] = LAYOUT( + _______, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, _______, + KC_F1, _______, _______, _______, _______, _______, KC_PGUP, KC_HOME, KC_UP, KC_END, KC_LBRC, KC_F12, + _______, _______, _______, _______, _______, _______, KC_PGDN, KC_LEFT, KC_DOWN, KC_RGHT, KC_QUOT, KC_DEL, + _______, _______, _______, KC_MPRV, KC_MPLY, KC_MNXT, _______, _______, _______, KC_VOLU, KC_VOLD, KC_MUTE, KC_BSLS, _______, + _______, _______, _______, _______, _______, _______, _______, _______ + ), + + /* RAISE + * ,-----------------------------------------. ,-----------------------------------------. + * | | | | | | | | | | | | | | + * |------+------+------+------+------+------| |------+------+------+------+------+------| + * | | 1 | 2 | 3 | 4 | 5 | | PgUp | HOME | Up | END | ºª | | + * |------+------+------+------+------+------| |------+------+------+------+------+------| + * | | 6 | 7 | 8 | 9 | 0 |-------. ,-------| PgDn | Left | Down |Right | ~^ | | + * |------+------+------+------+------+------| | | |------+------+------+------+------+------| + * | | | | << | >|| | >> |-------| |-------| | Vol+ | Vol- | Mute | \| | | + * `-----------------------------------------/ / \ \-----------------------------------------' + * | LAlt | LGUI |LOWER | /Space / \Enter \ |RAISE | RGUI | RAlt | + * | | | |/ / \ \ | | | | + * `-------------------''-------' '------''--------------------' + */ + [_RAISE] = LAYOUT( + _______, _______, _______, _______, _______, _______, _______, _______, _______,_______, _______, _______, + _______, KC_1, KC_2, KC_3, KC_4, KC_5, KC_PGUP, KC_HOME, KC_UP, KC_END, KC_LBRC, _______, + _______, KC_6, KC_7, KC_8, KC_9, KC_0, KC_PGDN, KC_LEFT, KC_DOWN, KC_RGHT, KC_QUOT, _______, + _______, _______, _______, KC_MPRV, KC_MPLY, KC_MNXT, _______, _______, _______, KC_VOLU, KC_VOLD, KC_MUTE, KC_BSLS, _______, + _______, _______, _______, _______, _______, _______, _______, _______ + ), + + /* ADJUST + * ,-----------------------------------------. ,-----------------------------------------. + * | | | | | | | | | | | | | | + * |------+------+------+------+------+------| |------+------+------+------+------+------| + * | | | | | | | | | | | | | | + * |------+------+------+------+------+------| |------+------+------+------+------+------| + * |RGB ON| HUE+ | SAT+ | VAL+ | | BRG+ |-------. ,-------| | | | | | | + * |------+------+------+------+------+------| | | |------+------+------+------+------+------| + * | MODE | HUE- | SAT- | VAL- | | BRG- |-------| |-------| | | | | | | + * `-----------------------------------------/ / \ \-----------------------------------------' + * | LAlt | LGUI |LOWER | /Space / \Enter \ |RAISE | RGUI | RAlt | + * | | | |/ / \ \ | | | | + * `----------------------------' '------''--------------------' + */ + + [_ADJUST] = LAYOUT( + XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, + XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, + RGB_TOG, RGB_HUI, RGB_SAI, RGB_VAI, XXXXXXX, KC_BRIU, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, + RGB_MOD, RGB_HUD, RGB_SAD, RGB_VAD, XXXXXXX, KC_BRID, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, + _______, _______, _______, _______, _______, _______, _______, _______ + ) +}; + +// SSD1306 OLED update loop, make sure to enable OLED_ENABLE=yes in rules.mk +#ifdef OLED_ENABLE + +oled_rotation_t oled_init_user(oled_rotation_t rotation) { + if (!is_keyboard_master()) return OLED_ROTATION_180; // flips the display 180 degrees if offhand + return rotation; +} + +// When you add source files to SRC in rules.mk, you can use functions. +const char *read_layer_state(void); +const char *read_logo(void); +void set_keylog(uint16_t keycode, keyrecord_t *record); +const char *read_keylog(void); +const char *read_keylogs(void); + +bool oled_task_user(void) { + if (is_keyboard_master()) { + oled_write_ln(read_layer_state(), false); + oled_write_ln(read_keylog(), false); + oled_write_ln(read_keylogs(), false); + } else { + oled_write(read_logo(), false); + } + return false; +} +#endif // OLED_ENABLE + + +bool process_record_user(uint16_t keycode, keyrecord_t *record) { + if (record->event.pressed) { + #ifdef OLED_ENABLE + set_keylog(keycode, record); + #endif + } + + return true; +} + +/* Tap dance shifts */ +td_state_t cur_dance(tap_dance_state_t *state) { + if (state->count == 1) { + if (state->interrupted || !state->pressed) { + return TD_SINGLE_TAP; + } else { + return TD_SINGLE_HOLD; + } + } else if (state->count == 2) { + return TD_DOUBLE_TAP; + } + + return TD_UNKNOWN; +} + +static tap lshifttap_state = {.is_press_action = true, .state = TD_NONE}; + +static tap rshifttap_state = {.is_press_action = true, .state = TD_NONE}; + +void lshift_finished(tap_dance_state_t *state, void *user_data) { + lshifttap_state.state = cur_dance(state); + + switch (lshifttap_state.state) { + case TD_SINGLE_TAP: + register_code16(LALT(KC_LEFT)); + break; + case TD_SINGLE_HOLD: + register_code(KC_LSFT); + break; + case TD_DOUBLE_TAP: + tap_code16(LALT(KC_LEFT)); + register_code16(LALT(KC_LEFT)); + break; + default: + break; + } +} + +void lshift_reset(tap_dance_state_t *state, void *user_data) { + switch (lshifttap_state.state) { + case TD_SINGLE_TAP: + unregister_code16(LALT(KC_LEFT)); + break; + case TD_SINGLE_HOLD: + unregister_code(KC_LSFT); + break; + case TD_DOUBLE_TAP: + unregister_code16(LALT(KC_LEFT)); + break; + } + lshifttap_state.state = TD_NONE; +} + +void rshift_finished(tap_dance_state_t *state, void *user_data) { + rshifttap_state.state = cur_dance(state); + + switch (rshifttap_state.state) { + case TD_SINGLE_TAP: + register_code16(LALT(KC_RGHT)); + break; + case TD_SINGLE_HOLD: + register_code(KC_RSFT); + break; + case TD_DOUBLE_TAP: + tap_code16(LALT(KC_RGHT)); + register_code16(LALT(KC_RGHT)); + break; + default: + break; + } +} + +void rshift_reset(tap_dance_state_t *state, void *user_data) { + switch (rshifttap_state.state) { + case TD_SINGLE_TAP: + unregister_code16(LALT(KC_RGHT)); + break; + case TD_SINGLE_HOLD: + unregister_code(KC_RSFT); + break; + case TD_DOUBLE_TAP: + unregister_code16(LALT(KC_RGHT)); + break; + } + rshifttap_state.state = TD_NONE; +} + +tap_dance_action_t tap_dance_actions[] = { + [LEFT_SHIFT] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, lshift_finished, lshift_reset), + [RIGHT_SHIFT] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, rshift_finished, rshift_reset), +}; diff --git a/keyboards/lily58/keymaps/paulomp90/readme.md b/keyboards/lily58/keymaps/paulomp90/readme.md new file mode 100644 index 0000000000..9ab72cd0b2 --- /dev/null +++ b/keyboards/lily58/keymaps/paulomp90/readme.md @@ -0,0 +1,10 @@ +# Paulo Lily58 + +Lily58 is 6×4 column-staggered split keyboard. + +![Keymap first layer](https://i.postimg.cc/HWcgcxb8/lily58.png "Keymap first layer") + +- Add portuguese include +- Add custom shift behaviour, when tap move by 1 word left <> right, when held act as shift. +idea taken from [here](https://getreuer.info/posts/keyboards/custom-shift-keys/index.html). + diff --git a/keyboards/lily58/keymaps/paulomp90/rules.mk b/keyboards/lily58/keymaps/paulomp90/rules.mk new file mode 100644 index 0000000000..d7bfc97394 --- /dev/null +++ b/keyboards/lily58/keymaps/paulomp90/rules.mk @@ -0,0 +1,14 @@ +EXTRAKEY_ENABLE = yes # Audio control and System control +OLED_ENABLE= yes # OLED display +TAP_DANCE_ENABLE = yes +TRI_LAYER_ENABLE = yes + +# If you want to change the display of OLED, you need to change here +SRC += ./lib/rgb_state_reader.c \ + ./lib/layer_state_reader.c \ + ./lib/logo_reader.c \ + ./lib/keylogger.c \ + features/custom_shift_keys.c \ + # ./lib/mode_icon_reader.c \ + # ./lib/host_led_state_reader.c \ + # ./lib/timelogger.c \ -- cgit v1.2.3