aboutsummaryrefslogtreecommitdiff
path: root/keyboards/wuque/ikki68_aurora/keymaps/ewersp/keymap.c
diff options
context:
space:
mode:
Diffstat (limited to 'keyboards/wuque/ikki68_aurora/keymaps/ewersp/keymap.c')
-rw-r--r--keyboards/wuque/ikki68_aurora/keymaps/ewersp/keymap.c215
1 files changed, 215 insertions, 0 deletions
diff --git a/keyboards/wuque/ikki68_aurora/keymaps/ewersp/keymap.c b/keyboards/wuque/ikki68_aurora/keymaps/ewersp/keymap.c
new file mode 100644
index 000000000..5983625ad
--- /dev/null
+++ b/keyboards/wuque/ikki68_aurora/keymaps/ewersp/keymap.c
@@ -0,0 +1,215 @@
1/* Copyright 2021 Paul Ewers
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include QMK_KEYBOARD_H
18
19enum alt_keycodes {
20 ALT_DEL = SAFE_RANGE, // Map left alt + backspace to delete
21 LED_TOG // Toggle LED modes
22};
23
24// Friendly layer names
25enum alt_layers {
26 DEF = 0,
27 ALT,
28 MAC,
29 FUNC,
30 SUPR
31};
32
33// EEPROM storage mode
34enum alt_led_mode {
35 LED_MODE_ALL = 0,
36 LED_MODE_LOGO,
37 LED_MODE_UNDERGLOW,
38 LED_MODE_OFF,
39 LED_MODE_TOTAL
40};
41
42// EEPROM storage type
43typedef union {
44 uint32_t raw;
45 struct {
46 uint8_t led_mode: 8;
47 };
48} user_config_t;
49
50user_config_t user_config;
51
52const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
53 [DEF] = LAYOUT_all(
54 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_EQL, KC_BSPC, KC_BSPC, KC_HOME, KC_PGUP,
55 KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS, KC_DEL, KC_PGDN,
56 KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT,
57 KC_LSFT, KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_RSFT, KC_UP,
58 KC_LCTL, KC_LGUI, MO(SUPR), KC_SPC, KC_SPC, KC_SPC, KC_RALT, MO(FUNC),KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT
59 ),
60 [ALT] = LAYOUT_all(
61 _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
62 _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
63 _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
64 _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
65 _______, _______, KC_LALT, _______, _______, _______, _______, _______, _______, _______, _______, _______
66 ),
67 [MAC] = LAYOUT_all(
68 _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
69 _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
70 _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
71 _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
72 _______, KC_LALT, KC_LGUI, _______, _______, _______, KC_RGUI, _______, KC_RALT, _______, _______, _______
73 ),
74 [FUNC] = LAYOUT_all(
75 KC_GRV, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______, _______, KC_END, KC_VOLU,
76 _______, RGB_HUD, RGB_VAI, RGB_HUI, RGB_SAI, RGB_M_P, _______, _______, _______, KC_BRIU, KC_PAUS, KC_PSCR, _______, _______, KC_MUTE, KC_VOLD,
77 _______, RGB_RMOD,RGB_VAD, RGB_MOD, RGB_SAD, RGB_M_B, _______, _______, _______, KC_BRID, _______, _______, _______,
78 _______, _______, RGB_TOG, LED_TOG, _______, EEP_RST, RESET, _______, _______, TG(MAC), TG(ALT), _______, _______, _______, KC_PGUP,
79 _______, _______, KC_LALT, _______, _______, _______, _______, _______, _______, KC_HOME, KC_PGDN, KC_END
80 ),
81 [SUPR] = LAYOUT_all(
82 KC_GRV, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, ALT_DEL, ALT_DEL, KC_END, _______,
83 _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
84 _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
85 _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
86 _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_HOME, _______, KC_END
87 )
88};
89
90// If the super alt layer is the active layer
91bool super_alt_layer_active = false;
92
93// If we need to unregister alt when leaving the super alt layer
94bool need_to_unregister_alt = false;
95
96// This runs code every time that the layers get changed
97layer_state_t layer_state_set_user(layer_state_t state) {
98 switch (get_highest_layer(state)) {
99 case DEF:
100 // When returning to the default layer, check if we need to unregister the left alt key
101 if (super_alt_layer_active && need_to_unregister_alt) {
102 unregister_code(KC_LALT);
103 }
104 super_alt_layer_active = false;
105 need_to_unregister_alt = false;
106 break;
107 case SUPR:
108 super_alt_layer_active = true;
109 break;
110 }
111 return state;
112}
113
114// There is a total of 20 LEDs on the board; the 4 logo LEDs have indices 16, 17, 18, 19
115void update_led_mode(void) {
116 rgblight_setrgb(0, 0, 0);
117 switch (user_config.led_mode) {
118 case LED_MODE_ALL:
119 rgblight_set_effect_range(0, RGBLED_NUM);
120 rgblight_enable_noeeprom();
121 break;
122 case LED_MODE_LOGO:
123 rgblight_set_effect_range(16, 4);
124 rgblight_enable_noeeprom();
125 break;
126 case LED_MODE_UNDERGLOW:
127 rgblight_set_effect_range(0, 16);
128 rgblight_enable_noeeprom();
129 break;
130 case LED_MODE_OFF:
131 rgblight_disable_noeeprom();
132 break;
133 }
134}
135
136void keyboard_post_init_user(void) {
137 user_config.raw = eeconfig_read_user();
138 update_led_mode();
139}
140
141void eeconfig_init_user(void) {
142 user_config.raw = 0;
143 user_config.led_mode = LED_MODE_ALL;
144 eeconfig_update_user(user_config.raw);
145 rgblight_enable();
146}
147
148bool process_record_user(uint16_t keycode, keyrecord_t *record) {
149 static uint32_t key_timer;
150
151 switch (keycode) {
152 // These are the keys we want to 'fall though' and behave as usual when pressed with the alt modifier
153 case KC_A ... KC_Z:
154 case KC_TAB:
155 case KC_DEL:
156 case KC_UP:
157 case KC_DOWN:
158 case KC_ENT:
159 case KC_SPC:
160 case MO(FUNC):
161 if (super_alt_layer_active && record->event.pressed) {
162 // Only activate the alt modifier for the first key press
163 if ((get_mods() & MOD_BIT(KC_LALT)) == false) {
164 register_code(KC_LALT);
165 need_to_unregister_alt = true;
166 }
167 }
168 // We still want to process the keycode normally
169 return true;
170 case KC_F4:
171 // Map alt+shift+4 to alt+f4
172 if (super_alt_layer_active && (get_mods() & MOD_BIT(KC_LSHIFT))) {
173 if (record->event.pressed) {
174 register_code(KC_LALT);
175 } else {
176 unregister_code(KC_LALT);
177 }
178 }
179 return true;
180 case ALT_DEL:
181 if (record->event.pressed) {
182 register_code(KC_DEL);
183 } else {
184 unregister_code(KC_DEL);
185 }
186 return false;
187 case LED_TOG:
188 if (record->event.pressed) {
189 user_config.led_mode = (user_config.led_mode + 1) % LED_MODE_TOTAL;
190 update_led_mode();
191 eeconfig_update_user(user_config.raw);
192 }
193 return false;
194 case RESET:
195 if (record->event.pressed) {
196 key_timer = timer_read32();
197 } else {
198 if (timer_elapsed32(key_timer) >= 500) {
199 reset_keyboard();
200 }
201 }
202 return false;
203 case EEP_RST:
204 if (record->event.pressed) {
205 key_timer = timer_read32();
206 } else {
207 if (timer_elapsed32(key_timer) >= 500) {
208 eeconfig_init();
209 }
210 }
211 return false;
212 default:
213 return true; // Process all other keycodes normally
214 }
215}