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
30 bool mod_key_press_timer(uint16_t code, uint16_t mod_code, bool pressed) {
31 static uint16_t this_timer;
33 this_timer = timer_read();
35 if (timer_elapsed(this_timer) < TAPPING_TERM) {
38 register_code(mod_code);
40 unregister_code(mod_code);
46 bool mod_key_press(uint16_t code, uint16_t mod_code, bool pressed, uint16_t this_timer) {
48 this_timer = timer_read();
50 if (timer_elapsed(this_timer) < TAPPING_TERM) {
53 register_code(mod_code);
55 unregister_code(mod_code);
61 void bootmagic_lite(void) {
63 #if defined(DEBOUNCING_DELAY) && DEBOUNCING_DELAY > 0
64 wait_ms(DEBOUNCING_DELAY * 2);
65 #elif defined(DEBOUNCE) && DEBOUNCE > 0
66 wait_ms(DEBOUNCE * 2);
71 if (matrix_get_row(BOOTMAGIC_LITE_ROW) & (1 << BOOTMAGIC_LITE_COLUMN)) {
76 // Add reconfigurable functions here, for keymap customization
77 // This allows for a global, userspace functions, and continued
78 // customization of the keymap. Use _keymap instead of _user
79 // functions in the keymaps
81 void matrix_init_keymap(void) {}
83 // Call user matrix init, set default RGB colors and then
84 // call the keymap's init function
85 void matrix_init_user(void) {
86 userspace_config.raw = eeconfig_read_user();
88 #ifdef BOOTLOADER_CATERINA
96 #if (defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE))
97 set_unicode_input_mode(DRASHNA_UNICODE_MODE);
98 get_unicode_input_mode();
99 #endif // UNICODE_ENABLE
100 matrix_init_keymap();
103 __attribute__((weak))
104 void keyboard_post_init_keymap(void) {}
106 void keyboard_post_init_user(void) {
107 #if defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE)
108 keyboard_post_init_rgb();
110 keyboard_post_init_keymap();
113 __attribute__((weak))
114 void shutdown_keymap(void) {}
116 void rgb_matrix_update_pwm_buffers(void);
118 void shutdown_user(void) {
119 #ifdef RGBLIGHT_ENABLE
120 rgblight_enable_noeeprom();
121 rgblight_mode_noeeprom(1);
122 rgblight_setrgb_red();
123 #endif // RGBLIGHT_ENABLE
124 #ifdef RGB_MATRIX_ENABLE
125 rgb_matrix_set_color_all( 0xFF, 0x00, 0x00 );
126 rgb_matrix_update_pwm_buffers();
128 #endif // RGB_MATRIX_ENABLE
132 __attribute__((weak))
133 void suspend_power_down_keymap(void) {}
135 void suspend_power_down_user(void) {
136 suspend_power_down_keymap();
139 __attribute__((weak))
140 void suspend_wakeup_init_keymap(void) {}
142 void suspend_wakeup_init_user(void) {
143 suspend_wakeup_init_keymap();
146 __attribute__((weak))
147 void matrix_scan_keymap(void) {}
149 // No global matrix scan code, so just run keymap's matrix
151 void matrix_scan_user(void) {
152 static bool has_ran_yet;
158 #ifdef TAP_DANCE_ENABLE // Run Diablo 3 macro checking code.
159 run_diablo_macro_check();
160 #endif // TAP_DANCE_ENABLE
162 #if defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE)
164 #endif // RGBLIGHT_ENABLE
166 matrix_scan_keymap();
169 __attribute__((weak))
170 layer_state_t layer_state_set_keymap(layer_state_t state) { return state; }
172 // on layer change, no matter where the change was initiated
173 // Then runs keymap's layer change check
174 layer_state_t layer_state_set_user(layer_state_t state) {
175 state = update_tri_layer_state(state, _RAISE, _LOWER, _ADJUST);
176 #if defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE)
177 state = layer_state_set_rgb(state);
178 #endif // RGBLIGHT_ENABLE
179 return layer_state_set_keymap(state);
182 __attribute__((weak))
183 layer_state_t default_layer_state_set_keymap(layer_state_t state) { return state; }
185 // Runs state check and changes underglow color and animation
186 layer_state_t default_layer_state_set_user(layer_state_t state) {
187 state = default_layer_state_set_keymap(state);
189 #if defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE)
190 state = default_layer_state_set_rgb(state);
191 # endif // RGBLIGHT_ENABLE
196 __attribute__((weak))
197 void led_set_keymap(uint8_t usb_led) {}
199 // Any custom LED code goes here.
200 // So far, I only have keyboard specific code,
201 // So nothing goes here.
202 void led_set_user(uint8_t usb_led) {
203 led_set_keymap(usb_led);
206 __attribute__((weak))
207 void eeconfig_init_keymap(void) {}
209 void eeconfig_init_user(void) {
210 userspace_config.raw = 0;
211 userspace_config.rgb_layer_change = true;
212 eeconfig_update_user(userspace_config.raw);
213 #if (defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE))
214 set_unicode_input_mode(DRASHNA_UNICODE_MODE);
215 get_unicode_input_mode();
217 eeprom_update_byte(EECONFIG_UNICODEMODE, DRASHNA_UNICODE_MODE);
219 eeconfig_init_keymap();