aboutsummaryrefslogtreecommitdiff
path: root/keyboards/mlego/m60/keymaps/via/keymap.c
diff options
context:
space:
mode:
Diffstat (limited to 'keyboards/mlego/m60/keymaps/via/keymap.c')
-rw-r--r--keyboards/mlego/m60/keymaps/via/keymap.c175
1 files changed, 175 insertions, 0 deletions
diff --git a/keyboards/mlego/m60/keymaps/via/keymap.c b/keyboards/mlego/m60/keymaps/via/keymap.c
new file mode 100644
index 000000000..18fdba688
--- /dev/null
+++ b/keyboards/mlego/m60/keymaps/via/keymap.c
@@ -0,0 +1,175 @@
1/*
2Copyright 2021-2022 Alin M Elena <alinm.elena@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#include QMK_KEYBOARD_H
19
20enum layer_names {
21 _QW = 0,
22 _LWR,
23 _RSE,
24 _ADJ
25};
26
27#ifdef RGBLIGHT_ENABLE
28
29const rgblight_segment_t PROGMEM my_qwerty_layer[] = RGBLIGHT_LAYER_SEGMENTS({0, RGBLED_NUM, HSV_PURPLE});
30const rgblight_segment_t PROGMEM my_lwr_layer[] = RGBLIGHT_LAYER_SEGMENTS({0, RGBLED_NUM, HSV_CYAN});
31const rgblight_segment_t PROGMEM my_rse_layer[] = RGBLIGHT_LAYER_SEGMENTS({0, RGBLED_NUM, HSV_RED});
32const rgblight_segment_t PROGMEM my_adj_layer[] = RGBLIGHT_LAYER_SEGMENTS({0, RGBLED_NUM, HSV_GREEN});
33
34const rgblight_segment_t* const PROGMEM my_rgb_layers[] = RGBLIGHT_LAYERS_LIST(my_qwerty_layer, my_lwr_layer, my_rse_layer, my_adj_layer);
35#endif
36
37#define LOWER TT(_LWR)
38#define RAISE TT(_RSE)
39
40// clang-format off
41const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
42[_QW] = LAYOUT_ortho_5x12(
43 KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC,
44 KC_ESC, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_DEL,
45 KC_TAB, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT,
46 KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT ,
47 KC_LCTL, KC_LGUI, KC_LALT, KC_APP, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT
48),
49
50[_LWR] = LAYOUT_ortho_5x12(
51 KC_TILD, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_DEL,
52 KC_DEL, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE,
53 _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12,S(KC_NUHS),S(KC_NUBS),_______, _______, _______,
54 _______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY,
55 _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______
56),
57
58[_RSE] = LAYOUT_ortho_5x12(
59 KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_DEL,
60 KC_DEL, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS,
61 _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_NUHS, KC_NUBS, _______, _______, _______,
62 _______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY,
63 _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______
64),
65
66[_ADJ] = LAYOUT_ortho_5x12(
67 _______, RESET, _______, _______, _______, _______, RGB_TOG, RGB_MOD, RGB_RMOD,RGB_M_G, RESET, _______,
68 _______, _______, _______, _______, _______, _______, RGB_HUI, RGB_SAI, RGB_VAI, _______, _______, _______,
69 _______, _______, _______, _______, _______, _______, RGB_HUD, RGB_SAD, RGB_VAD, _______, _______, _______,
70 _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
71 _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______
72)
73
74};
75// clang-format on
76
77// let us assume we start with both layers off
78bool toggle_lwr = false;
79bool toggle_rse = false;
80
81bool led_update_user(led_t led_state) {
82 // Disable the default LED update code, so that lock LEDs could be reused to show layer status.
83 return false;
84}
85
86void matrix_scan_user(void) {
87 led_lwr(toggle_lwr);
88 led_rse(toggle_rse);
89 led_t led_state = host_keyboard_led_state();
90 led_caps(led_state.caps_lock);
91 if (layer_state_is(_ADJ)) {
92 led_lwr(true);
93 led_rse(true);
94 }
95}
96
97bool process_record_user(uint16_t keycode, keyrecord_t* record) {
98 switch (keycode) {
99 case (TT(_LWR)):
100 if (!record->event.pressed && record->tap.count == TAPPING_TOGGLE) {
101 // This runs before the TT() handler toggles the layer state, so the current layer state is the opposite of the final one after toggle.
102 toggle_lwr = !layer_state_is(_LWR);
103 }
104 return true;
105 break;
106 case (TT(_RSE)):
107 if (record->event.pressed && record->tap.count == TAPPING_TOGGLE) {
108 toggle_rse = !layer_state_is(_RSE);
109 }
110 return true;
111 break;
112 default:
113 return true;
114 }
115}
116
117layer_state_t layer_state_set_user(layer_state_t state) {
118#ifdef RGBLIGHT_ENABLE
119
120 rgblight_set_layer_state(0, layer_state_cmp(state, _QW));
121 rgblight_set_layer_state(1, layer_state_cmp(state, _LWR));
122 rgblight_set_layer_state(2, layer_state_cmp(state, _RSE));
123 rgblight_set_layer_state(3, layer_state_cmp(state, _ADJ));
124
125#endif
126 return update_tri_layer_state(state, _LWR, _RSE, _ADJ);
127}
128
129#ifdef RGBLIGHT_ENABLE
130
131layer_state_t default_layer_state_set_user(layer_state_t state) {
132 rgblight_set_layer_state(0, layer_state_cmp(state, _QW));
133 return state;
134}
135
136void keyboard_post_init_user(void) {
137 // Enable the LED layers
138 rgblight_layers = my_rgb_layers;
139}
140#endif
141
142#ifdef ENCODER_ENABLE
143
144# define MEDIA_KEY_DELAY 10
145
146static inline void my_encoders(const uint8_t index, const bool clockwise) {
147 if (index == 0) { /* First encoder */
148 if (IS_LAYER_ON(_LWR)) {
149 if (clockwise) {
150 rgblight_decrease_val_noeeprom();
151 } else {
152 rgblight_increase_val_noeeprom();
153 }
154 } else if (IS_LAYER_ON(_RSE)) {
155 if (clockwise) {
156 rgblight_decrease_hue_noeeprom();
157 } else {
158 rgblight_increase_hue_noeeprom();
159 }
160
161 } else {
162 if (clockwise) {
163 tap_code_delay(KC_VOLD, MEDIA_KEY_DELAY);
164 } else {
165 tap_code_delay(KC_VOLU, MEDIA_KEY_DELAY);
166 }
167 }
168 }
169}
170
171bool encoder_update_user(uint8_t index, bool clockwise) {
172 my_encoders(index, clockwise);
173 return true;
174}
175#endif