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) {
41 wait_ms(TAP_CODE_DELAY);
42 send_string_with_delay(str, TAP_CODE_DELAY);
43 wait_ms(TAP_CODE_DELAY);
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){
58 register_code(mod_code);
60 unregister_code(mod_code);
66 bool mod_key_press (uint16_t code, uint16_t mod_code, bool pressed, uint16_t this_timer) {
68 this_timer= timer_read();
70 if (timer_elapsed(this_timer) < TAPPING_TERM){
73 register_code(mod_code);
75 unregister_code(mod_code);
81 void bootmagic_lite(void) {
83 #if defined(DEBOUNCING_DELAY) && DEBOUNCING_DELAY > 0
84 wait_ms(DEBOUNCING_DELAY * 2);
85 #elif defined(DEBOUNCE) && DEBOUNCE > 0
86 wait_ms(DEBOUNCE * 2);
91 if (matrix_get_row(BOOTMAGIC_LITE_ROW) & (1 << BOOTMAGIC_LITE_COLUMN)) {
96 // Add reconfigurable functions here, for keymap customization
97 // This allows for a global, userspace functions, and continued
98 // customization of the keymap. Use _keymap instead of _user
99 // functions in the keymaps
100 __attribute__ ((weak))
101 void matrix_init_keymap(void) {}
103 // Call user matrix init, set default RGB colors and then
104 // call the keymap's init function
105 void matrix_init_user(void) {
106 userspace_config.raw = eeconfig_read_user();
108 #ifdef BOOTLOADER_CATERINA
116 #if (defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE))
117 set_unicode_input_mode(DRASHNA_UNICODE_MODE);
118 get_unicode_input_mode();
119 #endif //UNICODE_ENABLE
120 matrix_init_keymap();
123 __attribute__((weak))
124 void keyboard_post_init_keymap(void){ }
126 void keyboard_post_init_user(void){
127 #ifdef RGBLIGHT_ENABLE
128 keyboard_post_init_rgb();
130 keyboard_post_init_keymap();
133 __attribute__ ((weak))
134 void shutdown_keymap(void) {}
136 void shutdown_user (void) {
137 #ifdef RGBLIGHT_ENABLE
138 rgblight_enable_noeeprom();
139 rgblight_mode_noeeprom(1);
140 rgblight_setrgb_red();
141 #endif // RGBLIGHT_ENABLE
142 #ifdef RGB_MATRIX_ENABLE
143 // uint16_t timer_start = timer_read();
144 // rgb_matrix_set_color_all( 0xFF, 0x00, 0x00 );
145 // while(timer_elapsed(timer_start) < 250) { wait_ms(1); }
146 #endif //RGB_MATRIX_ENABLE
150 __attribute__ ((weak))
151 void suspend_power_down_keymap(void) {}
153 void suspend_power_down_user(void) {
154 suspend_power_down_keymap();
157 __attribute__ ((weak))
158 void suspend_wakeup_init_keymap(void) {}
160 void suspend_wakeup_init_user(void) {
161 suspend_wakeup_init_keymap();
165 __attribute__ ((weak))
166 void matrix_scan_keymap(void) {}
168 // No global matrix scan code, so just run keymap's matrix
170 void matrix_scan_user(void) {
171 static bool has_ran_yet;
177 #ifdef TAP_DANCE_ENABLE // Run Diablo 3 macro checking code.
178 run_diablo_macro_check();
179 #endif // TAP_DANCE_ENABLE
181 #ifdef RGBLIGHT_ENABLE
183 #endif // RGBLIGHT_ENABLE
185 matrix_scan_keymap();
189 __attribute__ ((weak))
190 layer_state_t layer_state_set_keymap (layer_state_t state) {
194 // on layer change, no matter where the change was initiated
195 // Then runs keymap's layer change check
196 layer_state_t layer_state_set_user(layer_state_t state) {
197 state = update_tri_layer_state(state, _RAISE, _LOWER, _ADJUST);
198 #ifdef RGBLIGHT_ENABLE
199 state = layer_state_set_rgb(state);
200 #endif // RGBLIGHT_ENABLE
201 return layer_state_set_keymap (state);
205 __attribute__ ((weak))
206 layer_state_t default_layer_state_set_keymap (layer_state_t state) {
210 // Runs state check and changes underglow color and animation
211 layer_state_t default_layer_state_set_user(layer_state_t state) {
212 state = default_layer_state_set_keymap(state);
214 #ifdef RGBLIGHT_ENABLE
215 state = default_layer_state_set_rgb(state);
216 #endif // RGBLIGHT_ENABLE
221 __attribute__ ((weak))
222 void led_set_keymap(uint8_t usb_led) {}
224 // Any custom LED code goes here.
225 // So far, I only have keyboard specific code,
226 // So nothing goes here.
227 void led_set_user(uint8_t usb_led) {
228 led_set_keymap(usb_led);
231 __attribute__ ((weak))
232 void eeconfig_init_keymap(void) {}
234 void eeconfig_init_user(void) {
235 userspace_config.raw = 0;
236 userspace_config.rgb_layer_change = true;
237 eeconfig_update_user(userspace_config.raw);
238 #if (defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE))
239 set_unicode_input_mode(DRASHNA_UNICODE_MODE);
240 get_unicode_input_mode();
242 eeprom_update_byte(EECONFIG_UNICODEMODE, DRASHNA_UNICODE_MODE);