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();
127 __attribute__((weak))
128 void keyboard_post_init_keymap(void){ }
130 void keyboard_post_init_user(void){
131 #ifdef RGBLIGHT_ENABLE
132 keyboard_post_init_rgb();
134 keyboard_post_init_keymap();
137 __attribute__ ((weak))
138 void shutdown_keymap(void) {}
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
154 __attribute__ ((weak))
155 void suspend_power_down_keymap(void) {}
157 void suspend_power_down_user(void) {
158 suspend_power_down_keymap();
161 __attribute__ ((weak))
162 void suspend_wakeup_init_keymap(void) {}
164 void suspend_wakeup_init_user(void) {
165 suspend_wakeup_init_keymap();
169 __attribute__ ((weak))
170 void matrix_scan_keymap(void) {}
172 // No global matrix scan code, so just run keymap's matrix
174 void matrix_scan_user(void) {
175 static bool has_ran_yet;
181 #ifdef TAP_DANCE_ENABLE // Run Diablo 3 macro checking code.
182 run_diablo_macro_check();
183 #endif // TAP_DANCE_ENABLE
185 #ifdef RGBLIGHT_ENABLE
187 #endif // RGBLIGHT_ENABLE
189 matrix_scan_keymap();
193 __attribute__ ((weak))
194 uint32_t layer_state_set_keymap (uint32_t state) {
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);
209 __attribute__ ((weak))
210 uint32_t default_layer_state_set_keymap (uint32_t state) {
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);
218 #ifdef RGBLIGHT_ENABLE
219 state = default_layer_state_set_rgb(state);
220 #endif // RGBLIGHT_ENABLE
225 __attribute__ ((weak))
226 void led_set_keymap(uint8_t usb_led) {}
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);
235 __attribute__ ((weak))
236 void eeconfig_init_keymap(void) {}
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();
246 eeprom_update_byte(EECONFIG_UNICODEMODE, DRASHNA_UNICODE_MODE);