]> git.donarmstrong.com Git - qmk_firmware.git/blob - users/drashna/drashna.c
[Keymap] Update to drashna keymaps: Conform to QMK Standards Edition (#5377)
[qmk_firmware.git] / users / drashna / drashna.c
1 /*
2 Copyright 2017 Christopher Courtney <drashna@live.com> @drashna
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #include "drashna.h"
19
20 userspace_config_t userspace_config;
21 #if (defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE))
22   #define DRASHNA_UNICODE_MODE UC_WIN
23 #else
24   // set to 2 for UC_WIN, set to 4 for UC_WINC
25   #define DRASHNA_UNICODE_MODE 2
26 #endif
27
28
29 // This block is for all of the gaming macros, as they were all doing
30 // the same thing, but with differring text sent.
31 bool send_game_macro(const char *str, keyrecord_t *record, bool override) {
32   if (!record->event.pressed || override) {
33     uint16_t keycode;
34     if (userspace_config.is_overwatch) {
35       keycode = KC_BSPC;
36     } else {
37       keycode = KC_ENTER;
38     }
39     clear_keyboard();
40     tap_code(keycode);
41     wait_ms(50);
42     send_string_with_delay(str, MACRO_TIMER);
43     wait_ms(50);
44     tap_code(KC_ENTER);
45   }
46   if (override) wait_ms(3000);
47   return false;
48 }
49
50 bool mod_key_press_timer (uint16_t code, uint16_t mod_code, bool pressed) {
51   static uint16_t this_timer;
52   if(pressed) {
53       this_timer= timer_read();
54   } else {
55       if (timer_elapsed(this_timer) < TAPPING_TERM){
56           register_code(code);
57           unregister_code(code);
58       } else {
59           register_code(mod_code);
60           register_code(code);
61           unregister_code(code);
62           unregister_code(mod_code);
63       }
64   }
65   return false;
66 }
67
68 bool mod_key_press (uint16_t code, uint16_t mod_code, bool pressed, uint16_t this_timer) {
69   if(pressed) {
70       this_timer= timer_read();
71   } else {
72       if (timer_elapsed(this_timer) < TAPPING_TERM){
73           register_code(code);
74           unregister_code(code);
75       } else {
76           register_code(mod_code);
77           register_code(code);
78           unregister_code(code);
79           unregister_code(mod_code);
80       }
81   }
82   return false;
83 }
84
85 void bootmagic_lite(void) {
86   matrix_scan();
87   #if defined(DEBOUNCING_DELAY) && DEBOUNCING_DELAY > 0
88     wait_ms(DEBOUNCING_DELAY * 2);
89   #elif defined(DEBOUNCE) && DEBOUNCE > 0
90     wait_ms(DEBOUNCE * 2);
91   #else
92     wait_ms(30);
93   #endif
94   matrix_scan();
95    if (matrix_get_row(BOOTMAGIC_LITE_ROW) & (1 << BOOTMAGIC_LITE_COLUMN)) {
96     bootloader_jump();
97   }
98 }
99
100 // Add reconfigurable functions here, for keymap customization
101 // This allows for a global, userspace functions, and continued
102 // customization of the keymap.  Use _keymap instead of _user
103 // functions in the keymaps
104 __attribute__ ((weak))
105 void matrix_init_keymap(void) {}
106
107 // Call user matrix init, set default RGB colors and then
108 // call the keymap's init function
109 void matrix_init_user(void) {
110   userspace_config.raw = eeconfig_read_user();
111
112   #ifdef BOOTLOADER_CATERINA
113     DDRD &= ~(1<<5);
114     PORTD &= ~(1<<5);
115
116     DDRB &= ~(1<<0);
117     PORTB &= ~(1<<0);
118   #endif
119
120   #if (defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE))
121     set_unicode_input_mode(DRASHNA_UNICODE_MODE);
122     get_unicode_input_mode();
123   #endif //UNICODE_ENABLE
124   matrix_init_keymap();
125 }
126
127 __attribute__((weak))
128 void keyboard_post_init_keymap(void){ }
129
130 void keyboard_post_init_user(void){
131 #ifdef RGBLIGHT_ENABLE
132   keyboard_post_init_rgb();
133 #endif
134   keyboard_post_init_keymap();
135 }
136
137 __attribute__ ((weak))
138 void shutdown_keymap(void) {}
139
140 void shutdown_user (void) {
141   #ifdef RGBLIGHT_ENABLE
142     rgblight_enable_noeeprom();
143     rgblight_mode_noeeprom(1);
144     rgblight_setrgb_red();
145   #endif // RGBLIGHT_ENABLE
146   #ifdef RGB_MATRIX_ENABLE
147     // uint16_t timer_start = timer_read();
148     // rgb_matrix_set_color_all( 0xFF, 0x00, 0x00 );
149     // while(timer_elapsed(timer_start) < 250) { wait_ms(1); }
150   #endif //RGB_MATRIX_ENABLE
151   shutdown_keymap();
152 }
153
154 __attribute__ ((weak))
155 void suspend_power_down_keymap(void) {}
156
157 void suspend_power_down_user(void) {
158     suspend_power_down_keymap();
159 }
160
161 __attribute__ ((weak))
162 void suspend_wakeup_init_keymap(void) {}
163
164 void suspend_wakeup_init_user(void) {
165   suspend_wakeup_init_keymap();
166 }
167
168
169 __attribute__ ((weak))
170 void matrix_scan_keymap(void) {}
171
172 // No global matrix scan code, so just run keymap's matrix
173 // scan function
174 void matrix_scan_user(void) {
175   static bool has_ran_yet;
176   if (!has_ran_yet) {
177     has_ran_yet = true;
178     startup_user();
179   }
180
181 #ifdef TAP_DANCE_ENABLE  // Run Diablo 3 macro checking code.
182   run_diablo_macro_check();
183 #endif // TAP_DANCE_ENABLE
184
185 #ifdef RGBLIGHT_ENABLE
186   matrix_scan_rgb();
187 #endif // RGBLIGHT_ENABLE
188
189   matrix_scan_keymap();
190 }
191
192
193 __attribute__ ((weak))
194 uint32_t layer_state_set_keymap (uint32_t state) {
195   return state;
196 }
197
198 // on layer change, no matter where the change was initiated
199 // Then runs keymap's layer change check
200 uint32_t layer_state_set_user(uint32_t state) {
201   state = update_tri_layer_state(state, _RAISE, _LOWER, _ADJUST);
202 #ifdef RGBLIGHT_ENABLE
203   state = layer_state_set_rgb(state);
204 #endif // RGBLIGHT_ENABLE
205   return layer_state_set_keymap (state);
206 }
207
208
209 __attribute__ ((weak))
210 uint32_t default_layer_state_set_keymap (uint32_t state) {
211   return state;
212 }
213
214 // Runs state check and changes underglow color and animation
215 uint32_t default_layer_state_set_user(uint32_t state) {
216   state = default_layer_state_set_keymap(state);
217 #if 0
218 #ifdef RGBLIGHT_ENABLE
219   state = default_layer_state_set_rgb(state);
220 #endif // RGBLIGHT_ENABLE
221 #endif
222   return state;
223 }
224
225 __attribute__ ((weak))
226 void led_set_keymap(uint8_t usb_led) {}
227
228 // Any custom LED code goes here.
229 // So far, I only have keyboard specific code,
230 // So nothing goes here.
231 void led_set_user(uint8_t usb_led) {
232   led_set_keymap(usb_led);
233 }
234
235 __attribute__ ((weak))
236 void eeconfig_init_keymap(void) {}
237
238 void eeconfig_init_user(void) {
239   userspace_config.raw = 0;
240   userspace_config.rgb_layer_change = true;
241   eeconfig_update_user(userspace_config.raw);
242   #if (defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE))
243     set_unicode_input_mode(DRASHNA_UNICODE_MODE);
244     get_unicode_input_mode();
245   #else
246     eeprom_update_byte(EECONFIG_UNICODEMODE, DRASHNA_UNICODE_MODE);
247   #endif
248 }