2 Copyright 2017 Christopher Courtney <drashna@live.com> @drashna
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.
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.
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/>.
20 userspace_config_t userspace_config;
21 #if (defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE))
22 #define DRASHNA_UNICODE_MODE UC_WIN
24 // set to 2 for UC_WIN, set to 4 for UC_WINC
25 #define DRASHNA_UNICODE_MODE 2
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) {
34 if (userspace_config.is_overwatch) {
42 send_string_with_delay(str, MACRO_TIMER);
46 if (override) wait_ms(3000);
50 bool mod_key_press_timer (uint16_t code, uint16_t mod_code, bool pressed) {
51 static uint16_t this_timer;
53 this_timer= timer_read();
55 if (timer_elapsed(this_timer) < TAPPING_TERM){
57 unregister_code(code);
59 register_code(mod_code);
61 unregister_code(code);
62 unregister_code(mod_code);
68 bool mod_key_press (uint16_t code, uint16_t mod_code, bool pressed, uint16_t this_timer) {
70 this_timer= timer_read();
72 if (timer_elapsed(this_timer) < TAPPING_TERM){
74 unregister_code(code);
76 register_code(mod_code);
78 unregister_code(code);
79 unregister_code(mod_code);
85 void bootmagic_lite(void) {
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);
95 if (matrix_get_row(BOOTMAGIC_LITE_ROW) & (1 << BOOTMAGIC_LITE_COLUMN)) {
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) {}
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();
112 #ifdef BOOTLOADER_CATERINA
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 #ifdef RGBLIGHT_ENABLE
127 #endif //RGBLIGHT_ENABLE
131 __attribute__ ((weak))
132 void shutdown_keymap(void) {}
134 void shutdown_user (void) {
135 #ifdef RGBLIGHT_ENABLE
136 rgblight_enable_noeeprom();
137 rgblight_mode_noeeprom(1);
138 rgblight_setrgb_red();
139 #endif // RGBLIGHT_ENABLE
140 #ifdef RGB_MATRIX_ENABLE
141 uint16_t timer_start = timer_read();
142 rgb_matrix_set_color_all( 0xFF, 0x00, 0x00 );
143 while(timer_elapsed(timer_start) < 250) { wait_ms(1); }
144 #endif //RGB_MATRIX_ENABLE
148 __attribute__ ((weak))
149 void suspend_power_down_keymap(void) {}
151 void suspend_power_down_user(void) {
152 suspend_power_down_keymap();
155 __attribute__ ((weak))
156 void suspend_wakeup_init_keymap(void) {}
158 void suspend_wakeup_init_user(void) {
159 suspend_wakeup_init_keymap();
163 __attribute__ ((weak))
164 void matrix_scan_keymap(void) {}
166 // No global matrix scan code, so just run keymap's matrix
168 void matrix_scan_user(void) {
169 static bool has_ran_yet;
175 #ifdef TAP_DANCE_ENABLE // Run Diablo 3 macro checking code.
176 run_diablo_macro_check();
177 #endif // TAP_DANCE_ENABLE
179 #ifdef RGBLIGHT_ENABLE
181 #endif // RGBLIGHT_ENABLE
183 matrix_scan_keymap();
187 __attribute__ ((weak))
188 uint32_t layer_state_set_keymap (uint32_t state) {
192 // on layer change, no matter where the change was initiated
193 // Then runs keymap's layer change check
194 uint32_t layer_state_set_user(uint32_t state) {
195 state = update_tri_layer_state(state, _RAISE, _LOWER, _ADJUST);
196 #ifdef RGBLIGHT_ENABLE
197 state = layer_state_set_rgb(state);
198 #endif // RGBLIGHT_ENABLE
199 return layer_state_set_keymap (state);
203 __attribute__ ((weak))
204 uint32_t default_layer_state_set_keymap (uint32_t state) {
208 // Runs state check and changes underglow color and animation
209 uint32_t default_layer_state_set_user(uint32_t state) {
210 state = default_layer_state_set_keymap(state);
211 #ifdef RGBLIGHT_ENABLE
212 state = default_layer_state_set_rgb(state);
213 #endif // RGBLIGHT_ENABLE
217 __attribute__ ((weak))
218 void led_set_keymap(uint8_t usb_led) {}
220 // Any custom LED code goes here.
221 // So far, I only have keyboard specific code,
222 // So nothing goes here.
223 void led_set_user(uint8_t usb_led) {
224 led_set_keymap(usb_led);
227 __attribute__ ((weak))
228 void eeconfig_init_keymap(void) {}
230 void eeconfig_init_user(void) {
231 userspace_config.raw = 0;
232 userspace_config.rgb_layer_change = true;
233 eeconfig_update_user(userspace_config.raw);
234 #if (defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE))
235 set_unicode_input_mode(DRASHNA_UNICODE_MODE);
236 get_unicode_input_mode();
238 eeprom_update_byte(EECONFIG_UNICODEMODE, DRASHNA_UNICODE_MODE);